Testing API¶
Demod provides some helper test case classes for the simulators. You can create test classes by inheriting from theses base classes. See the tutorial. ADD LINK
-
class
tests.test_base_simulators.BaseSimulatorChildrenTests(methodName='runTest')¶ Helper Class for testing children of the base simulator.
This class can be used as parent to test the behaviour of any
Simulator.-
sim¶ The simuulator class that should be tested.
-
n_households¶ The number of households that are supposed to be simulated in the test.
- Type
int
-
args¶ The args used for the
__init__()method.- Type
List[Any]
-
kwargs¶ The kwargs used for the
__init__()method.- Type
Dict[str, Any]
-
args_step¶ Example args used for the
step()method- Type
List[Any]
-
kwargs_step¶ Example kwargs used for the
step()method- Type
Dict[str, Any]
-
unimplemented_getters¶ A list of any getter names, that should not have their behaviour tested by TestCase.
- Type
List[str]
-
getter_args¶ A dictionary that specifies some arguments that should be passed to specific getter funcitons. Of the form: {“get_name_of_getter”: [*args], …}
- Type
Dict[str, List[Any]]
-
sim¶ alias of
demod.simulators.base_simulators.ExampleSimulator
-
test_instantiation()¶ Test that the simulator can be instantiated with args and kwargs.
-
test_n_households()¶ Test that the number of households is well assigned.
-
test_step()¶ Test that the simulator can perform a step.
-
test_step_timestep()¶ Test that the simulator updates the
current_time_stepwhen doing a step.
-
test_accept_logger()¶ Test that the simulator can accept a
SimLogger.
-
test_getter_function_work()¶ Test all getter functions available in the simulator.
Reads the attributes of the simulator to find the getters. If a getter should be ignored in the test, it can be specifies in the TestCase
unimplemented_gettersattribute.
-
run_base_tests()¶ Run all basic tests.
Useful if you want to run all test with different parameters.
-
-
class
tests.test_base_simulators.TimeAwareSimulatorChildrenTests(methodName='runTest')¶ Base tests for all children of TimeAwareSimulators.
This method also has all the attributes from
BaseSimulatorChildrenTests.-
default_start_datetime¶ The date_time at which the simulators starts by default.
- Type
datetime.datetime
-
default_initialization_time¶ The initialization time that is used by the simulator.
- Type
datetime.time
-
default_step_size¶ The default step_size assigned to the simulator.
- Type
datetime.timedelta
-
random_time¶ A random date_time value that is used for some tests.
- Type
datetime.datetime
-
random_step_size¶ A random step_size value that is used for some test.
- Type
datetime.timedelta
-
sim¶ The TimeAwareSimulator that should be tested.
-
sim¶ alias of
demod.simulators.base_simulators.TimeAwareExampleSimulator
-
test_same_time_init_start_in_test()¶ Test for the TestCase default values.
Test that the
default_start_datetimeand thedefault_initialization_timehave the same time value in the TestCase values.
-
test_instantiation_with_default_datetime()¶ Test that sim is initialized at default start_datetime.
-
test_instantiation_with_other_datetime()¶ Test instantiation at another datetime.
-
test_instantiation_with_tzinfo()¶ Test instantiation with a non-naive datetime object.
A non-naive datetime object holds a tzinfo, which gives information on the time-zone and daylight saving times.
-
test_step_updates_time()¶ Test that
sim.step()updatessim.current_time.
-
test_initialization_time()¶ Test that the simulator is running the requested number of steps when initialized.
Default intialization should not require doing any initialization step.
-
test_initialization_time_over_day()¶ Test that the simulator can be initialized over a day.
Test proper instantiation. Test the number of steps performed.
-
test_non_default_step_size()¶ Test the simulator behaviour with non default step_size.
This test can be overriden in case, only a single step_size is allowed.
-
run_base_tests()¶ Run all basic tests.
Useful if you want to run all test with different parameters.
-