generate_composite_base_case#
- generate_composite_base_case(*, when: str | dict[str, str] | None = None, flag: str | None = None, script: str | None = None) None#
Create an composite base test case that depends on all of the parameterized test cases generated by this file.
The composite base case will run after all other parameterized test cases and can be used to to ensure that the overall behavior of the parameterized test cases. For example, a parameter may represent a step size and the composite base case will verify convergence as the step size parameter is reduced.
The composite base case has access to all of parameterized cases’ parameters through the
dependenciesattribute.Usage#
.pyt:import canary canary.directives.generate_composite_base_case(*, flag=None, script=None, when=...)
.vvt:#VVT: analyze (options=..., platforms=..., testname=...) : (flag|script)Parameters#
when: Restrict processing of the directive to this conditionflag: Run the test script with the--FLAGoption on the command line.flagshould start with a hyphen (-). The script should parse this value and perform the appropriate analysis.script: Runscriptduring the analysis phase (instead of the test file).
The
whenexpression is limited to the following conditions:testname: Restrict processing of the directive to this test nameplatforms: Restrict processing of the directive to certain platform or platformsoptions: Restrict processing of the directive to command line-ooptionsparameters: Restrict processing of the directive to certain parameter names and values
References#
Examples#
import canary canary.directives.generate_composite_base_case(flag="--base", when="platforms='not darwin'") canary.directives.parameterize("a,b", [(1, 2), (3, 4)])
# VVT: analyze (platforms="not darwin") : --analyze # VVT: parameterize : a,b = 1,2 3,4
will run an analysis job after jobs
[a=1,b=3]and[a=2,b=4]have run to completion. Thecanary.testinstanceandvvtest_utilmodules will contain information regarding the previously run jobs so that a collective analysis can be performed.For either file type, the script must query the command line arguments to determine the type of test to run:
import argparse import sys import canary canary.directives.generate_composite_base_case(flag="--base", when="platforms='not darwin'") canary.directives.parameterize("a,b", [(1, 2), (3, 4)]) def test() -> int: ... def base() -> int: ... def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("--base", action="store_true") args = parser.parse_args() if args.analyze: return base() return test() if __name__ == "__main__": sys.exit(main())