Vivarium Testing Utilities

Utility functions and classes to make testing vivarium components easier.

class vivarium.engine.testing_utilities.NonCRNTestPopulation[source]
CONFIGURATION_DEFAULTS: dict[str, Any] = {'population': {'initialization_age_max': 100, 'initialization_age_min': 0, 'untracking_age': None}}

A dictionary containing the defaults for any configurations managed by this component. An empty dictionary indicates no managed configurations. Components will look for a data_sources block in this dictionary to build lookup tables automatically.

setup(builder)[source]

Defines custom actions this component needs to run during the setup lifecycle phase.

This method is intended to be overridden by subclasses to perform any necessary setup operations specific to the component. By default, it does nothing.

Return type:

None

Parameters:

builder (Builder) – The builder object used to set up the component.

initialize_population(pop_data)[source]
Return type:

None

Parameters:

pop_data (SimulantData)

on_time_step(event)[source]

Method that vivarium will run during the time_step event.

This method is intended to be overridden by subclasses if there are operations they need to perform specifically during the time_step event.

Return type:

None

Parameters:

event (Event) – The event object associated with the time_step event.

class vivarium.engine.testing_utilities.TestPopulation[source]
setup(builder)[source]

Defines custom actions this component needs to run during the setup lifecycle phase.

This method is intended to be overridden by subclasses to perform any necessary setup operations specific to the component. By default, it does nothing.

Return type:

None

Parameters:

builder (Builder) – The builder object used to set up the component.

initialize_population(pop_data)[source]
Return type:

None

Parameters:

pop_data (SimulantData)

vivarium.engine.testing_utilities.build_table(value, parameter_columns={'age': (0, 125), 'year': (1990, 2020)}, key_columns={'sex': ('Female', 'Male')}, value_columns=['value'])[source]
Return type:

DataFrame

Parameters:
  • value (Any) – Value(s) to put in the value columns of a lookup table.

  • parameter_columns (dict[str, Sequence[int]]) – A dictionary where the keys are parameter (continuous) columns of a lookup table and the values are tuple of the range (inclusive) for that column.

  • key_columns (dict[str, Sequence[Any]]) – A dictionary where the keys are key (categorical) columns of a lookup table and the values are a tuple of the categories for that column

  • value_columns (list[str]) – A list of value columns that will appear in the returned lookup table

Returns:

A pandas dataframe that has the cartesian product of the range of all parameter columns and the values of the key columns.

vivarium.engine.testing_utilities.get_randomness(key='test', clock=<function <lambda>>, seed=12345, initializes_crn_attributes=False, component=None)[source]
Return type:

RandomnessStream

Parameters:
vivarium.engine.testing_utilities.metadata(file_path, layer='override')[source]
Return type:

dict[str, str]

Parameters: