Testing¶
quivers.testing runs the in-language tests of QVR modules:
their test, property and example declarations and the examples written in their doc
comments. run_paths discovers modules and packages and runs
every test on the reference machine; mutate_module
runs a module's tests against every mutant of its code. The meaning of a test, an exact run, and a
mutation run is stated in Tests and exact evaluation.
runner
¶
Discover and run a module's tests, properties, and examples.
run_module checks one .qvr module and runs every test it declares
(Module.tests): its test, property and example declarations
and the examples written in its doc comments. run_paths does so for
files and directories (a directory is a package: every module under it),
and returns a TestReport whose TestReport.to_data is the
machine-readable report qvr test --json prints.
A test's body runs once. A property's body runs once per assignment of its
variables: every assignment when each variable ranges over a finite set,
checked exhaustively up to the declaration's limit; otherwise cases
assignments drawn from the declaration's seed, with sizes growing up to
size, and a failing assignment shrunk to a minimal one. All of these
are pinned in the declaration's options; nothing on the command line
changes them.
A test evaluates exactly, over the rationals, unless an expectation states
a tolerance with within, which makes it floating (float64), or its
options say numbers=float64 or numbers=float32. An equality of
reals states which it means: exactly in an exact test, within in a
floating one.
SourceLoader
¶
SourceLoader = Callable[[Path], tuple[bytes, tuple[TestDecl, ...]]]
Read one module file: its QVR source, and any tests its format carries beyond the source (the checked examples of a literate module).
TestSettings
didactic-model
¶
TestSettings(*, numbers: Numbers, cases: int = 100, seed: int = 0, size: int = 20, limit: int = 10000, fuel: int = 1000000, shrinks: int = 1000)
Bases: Model
A test declaration's pinned options.
| PARAMETER | DESCRIPTION |
|---|---|
numbers
|
The number domain:
TYPE:
|
cases
|
How many assignments a property draws when a variable ranges over an infinite type.
TYPE:
|
seed
|
The seed of those draws and of every program run.
TYPE:
|
size
|
The largest size a drawn value has.
TYPE:
|
limit
|
The most assignments an exhaustive check enumerates.
TYPE:
|
fuel
|
The step budget of each run.
TYPE:
|
shrinks
|
The most candidates shrinking tries.
TYPE:
|
TestDeclarationError
¶
Bases: ValueError
A test declaration whose options or expectations are ill-formed.
ExpectationResult
didactic-model
¶
Bases: Model
One evaluated expectation.
| PARAMETER | DESCRIPTION |
|---|---|
line
|
Its source line.
TYPE:
|
passed
|
Whether it held.
TYPE:
|
relation
|
The comparison it checked, or
TYPE:
|
left
|
The rendered left side, or the truth value.
TYPE:
|
right
|
The rendered right side, or
TYPE:
|
describe
¶
The expectation as one line.
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/testing/runner.py
TestResult
didactic-model
¶
TestResult(*, kind: str, name: str, line: int, status: Status, subject: str = '', numbers: str = 'exact', message: str = '', expectations: tuple[ExpectationResult, ...] = (), cases: int = 0, exhaustive: bool = False, counterexample: dict[str, str] = field(default_factory=dict), shrinks: int = 0, cached: bool = False, digest: str = '', seconds: float = 0.0)
Bases: Model
The outcome of one test, property, or example.
| PARAMETER | DESCRIPTION |
|---|---|
kind
|
TYPE:
|
name
|
Its title.
TYPE:
|
line
|
Its source line.
TYPE:
|
status
|
TYPE:
|
subject
|
For a doc-comment example, the declaration it documents.
TYPE:
|
numbers
|
The number domain it ran in.
TYPE:
|
message
|
Why it failed or erred; empty when it passed.
TYPE:
|
expectations
|
The expectations evaluated, up to the first that failed.
TYPE:
|
cases
|
How many assignments a property checked (1 for a test).
TYPE:
|
exhaustive
|
Whether a property enumerated every assignment.
TYPE:
|
counterexample
|
A failing property's minimal assignment, rendered by variable.
TYPE:
|
shrinks
|
How many shrinking steps reduced the counterexample.
TYPE:
|
cached
|
Whether the pass was read from the cache.
TYPE:
|
digest
|
The test's own content hash.
TYPE:
|
seconds
|
The wall time it took.
TYPE:
|
to_data
¶
The result as JSON data.
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Every field, expectations as lists of their fields. |
Source code in src/quivers/testing/runner.py
ModuleReport
didactic-model
¶
ModuleReport(*, path: str, digest: str = '', results: tuple[TestResult, ...] = (), error: str = '')
Bases: Model
The tests of one module and how they ended.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The module's file.
TYPE:
|
digest
|
The content hash of the module's code, tests excluded.
TYPE:
|
results
|
One result per test, in source order.
TYPE:
|
error
|
Why the module could not be tested (a parse or compile error); empty otherwise.
TYPE:
|
ok
property
¶
Whether the module loaded and every test passed.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
The verdict. |
to_data
¶
The module's report as JSON data.
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Its path, digest, verdict, error, and results. |
Source code in src/quivers/testing/runner.py
TestReport
didactic-model
¶
TestReport(*, modules: tuple[ModuleReport, ...] = (), packages: tuple[str, ...] = ())
Bases: Model
The report of one qvr test run.
| PARAMETER | DESCRIPTION |
|---|---|
modules
|
One report per module, in discovery order.
TYPE:
|
packages
|
The directories given, each a package of the modules under it.
TYPE:
|
ok
property
¶
Whether every module loaded and every test passed.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
The verdict. |
counts
¶
counts(modules: Iterable[ModuleReport] | None = None) -> dict[str, int]
Tests by status.
| PARAMETER | DESCRIPTION |
|---|---|
modules
|
The modules counted; every module when
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, int]
|
|
Source code in src/quivers/testing/runner.py
to_data
¶
The machine-readable report.
| RETURNS | DESCRIPTION |
|---|---|
dict
|
|
Source code in src/quivers/testing/runner.py
CheckedModule
didactic-model
¶
CheckedModule(*, path: str, parsed: Module, checked: QiecModule = field(opaque=True, extras=OPAQUE_BY_VALUE), digest: str)
Bases: ValueModel
A parsed module and its checked QIEC module, ready for its tests.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The file.
TYPE:
|
parsed
|
The parsed module after its meta phase, tests included: the generated declarations spliced in and generated properties among the tests.
TYPE:
|
checked
|
The checked module, with one computation per property whose parameters are its variables.
TYPE:
|
digest
|
The content hash of the module's code, tests excluded.
TYPE:
|
binder_types
¶
The checked types of a property's variables.
| PARAMETER | DESCRIPTION |
|---|---|
test
|
A property of this module.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[TypeExpr, ...]
|
One type per variable. |
Source code in src/quivers/testing/runner.py
settings_of
¶
settings_of(test: TestDecl) -> TestSettings
Read and check a declaration's options.
| PARAMETER | DESCRIPTION |
|---|---|
test
|
The declaration.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TestSettings
|
The settings, with the documented defaults for options not given. |
| RAISES | DESCRIPTION |
|---|---|
TestDeclarationError
|
If an option is unknown, repeated, or of the wrong kind; or an
expectation's |
Source code in src/quivers/testing/runner.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
check_module
¶
check_module(parsed: Module, path: str) -> CheckedModule
Check a parsed module for its tests.
| PARAMETER | DESCRIPTION |
|---|---|
parsed
|
The parsed module. Its meta phase runs first, so the properties a splice generates are among the tests and the declarations it generates are checked with the module.
TYPE:
|
path
|
Its file, for diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CheckedModule
|
The checked module. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the module has no checked QIEC part to run. |
Source code in src/quivers/testing/runner.py
run_test
¶
run_test(module: CheckedModule, test: TestDecl, cache: ResultCache | None = None) -> TestResult
Run one test, property, or example.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The checked module it belongs to.
TYPE:
|
test
|
The declaration.
TYPE:
|
cache
|
Where passes are remembered by content hash;
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TestResult
|
The outcome. |
Source code in src/quivers/testing/runner.py
register_source_loader
¶
register_source_loader(suffix: str, loader: SourceLoader) -> None
Teach run_paths to read modules of another file format.
A literate module format registers its suffix here; its loader tangles the file into QVR source and returns the examples its prose blocks declare, which run beside the source's own tests.
| PARAMETER | DESCRIPTION |
|---|---|
suffix
|
The file suffix, such as
TYPE:
|
loader
|
Reads a file of that format.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the suffix is |
Source code in src/quivers/testing/runner.py
discover
¶
The module files named by paths: files, and every module under a directory.
| PARAMETER | DESCRIPTION |
|---|---|
paths
|
Files and directories.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Path, ...]
|
The module files, each once, directories expanded in sorted order. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If a path does not exist. |
Source code in src/quivers/testing/runner.py
load_program
¶
load_program(path: Path) -> FlatProgram
Read a module file as it runs: its module graph as one flat program.
The file is the root of its module graph. A module of a package is read
in its package's build
(quivers.packages.workspace.load_package_file), as qvr check reads
it; any other file's imports are found below its own directory and in
the standard library. The
graph is interpreted into one flat program, as quivers.dsl.load
interprets it, so a test names the module's own declarations by their
names and an imported one through the import that reaches it. The tests
are the root module's, with any tests its file format carries beyond
the source.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The module file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FlatProgram
|
The flat program, with the root module's tests, and the source map from its lines to each module's file. |
| RAISES | DESCRIPTION |
|---|---|
OSError
|
If a file cannot be read. |
ParseError
|
If the module or one it imports does not parse. |
ModuleError
|
If an import names no module, the imports form a cycle, or a name does not resolve. |
ManifestError
|
If the manifest of the file's package is malformed. |
PackageError
|
If an import of a package module crosses a package boundary the rules forbid, or its lockfile does not match the packages. |
ValueError
|
If the file is not a module the loaders read. |
Source code in src/quivers/testing/runner.py
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 | |
load_module
¶
load_module(path: Path) -> Module
Read a module file as it runs, as load_program reads it.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The module file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Module
|
The flat program, with the root module's tests. |
| RAISES | DESCRIPTION |
|---|---|
OSError
|
If a file cannot be read. |
ParseError
|
If the module or one it imports does not parse. |
ModuleError
|
If an import names no module, the imports form a cycle, or a name does not resolve. |
ValueError
|
If the file is not a module the loaders read. |
Source code in src/quivers/testing/runner.py
run_module
¶
run_module(path: Path, cache: ResultCache | None = None, select: Callable[[TestDecl], bool] | None = None) -> ModuleReport
Run every test of one module file.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The module.
TYPE:
|
cache
|
Where passes are remembered;
TYPE:
|
select
|
Which tests to run; all when
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ModuleReport
|
The module's report. |
Source code in src/quivers/testing/runner.py
run_paths
¶
run_paths(paths: Sequence[Path], cache: ResultCache | None = None, select: Callable[[TestDecl], bool] | None = None) -> TestReport
Run the tests of every module named by paths.
| PARAMETER | DESCRIPTION |
|---|---|
paths
|
Module files and package directories.
TYPE:
|
cache
|
Where passes are remembered;
TYPE:
|
select
|
Which tests to run; all when
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
TestReport
|
The report. |