Tools#
The policyengine_core.tools module contains miscellaneous utility functions, including for running YAML tests.
run_tests#
- policyengine_core.tools.test_runner.run_tests(tax_benefit_system, paths, options=None)#
Runs all the YAML tests contained in a file or a directory.
If path is a directory, subdirectories will be recursively explored.
- Parameters:
tax_benefit_system (TaxBenefitSystem) – the tax-benefit system to use to run the tests
paths ((str/list)) – A path, or a list of paths, towards the files or directories containing the tests to run. If a path is a directory, subdirectories will be recursively explored.
options (dict) – See more details below.
- Raises:
AssertionError – if a test does not pass
- Returns:
the number of sucessful tests excecuted
Testing options:
dump_simulation#
- policyengine_core.tools.simulation_dumper.dump_simulation(simulation, directory)#
Write simulation data to directory, so that it can be restored later.
Writes the simulation’s branch values, including inherited values, and lists the periods it calculated (see
restore_simulation).
restore_simulation#
- policyengine_core.tools.simulation_dumper.restore_simulation(directory, tax_benefit_system, **kwargs)#
Restore simulation from directory
Each value is restored as the dumped simulation stored it: one it calculated (listed in the variable’s
derived_periods.txt) as a calculated value, and every other value as an input, recorded in_user_input_keysasset_inputrecords one, soapply_reformkeeps the inputs and drops the calculated values, as it would have in the dumped simulation.A dump lists which values were calculated, not where an input came from: a value the dumped simulation stored with
put_in_cachewithoutderived=True(an input to auto-carry-over and uprating thatset_inputdid not record, so thatapply_reformdropped it there) is restored as a recorded input too.A dump written before policyengine-core 3.32.16 lists no calculated value, so every value in it is restored as an input. A dump without a format marker that lists none may be one of those, so restoring it warns:
apply_reformthen keeps any calculated value in it as dumped instead of recalculating it.