Vivarium Testing Utilities

Utility functions and classes to make testing vivarium components easier.

class vivarium.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.

property columns_created: List[str]

Provides names of columns created by the component.

Returns:

  • Names of the columns created by this component, or an empty list if

  • none.

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.

on_initialize_simulants(pop_data)[source]

Method that vivarium will run during simulant initialization.

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

Return type:

None

Parameters:

pop_data (SimulantData) – The data associated with the simulants being initialized.

Return type:

None

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.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.

on_initialize_simulants(pop_data)[source]

Method that vivarium will run during simulant initialization.

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

Return type:

None

Parameters:

pop_data (SimulantData) – The data associated with the simulants being initialized.

Return type:

None

vivarium.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) – 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) – 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) – 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.testing_utilities.make_dummy_column(name, initial_value)[source]
vivarium.testing_utilities.get_randomness(key='test', clock=<function <lambda>>, seed=12345, initializes_crn_attributes=False)[source]
vivarium.testing_utilities.reset_mocks(mocks)[source]
vivarium.testing_utilities.metadata(file_path, layer='override')[source]