PandemiaProject / pandemia

An individual-based pandemic simulator
Creative Commons Attribution 4.0 International
0 stars 1 forks source link

Failling test test_vectorize_component[DefaultMovementModel] #87

Open andrewphilipsmith opened 1 year ago

andrewphilipsmith commented 1 year ago

The test fails with the follow error message:

FAILED tests/test_components.py::test_vectorize_component[DefaultMovementModel] - AssertionError

Notes: This assertion appears to be a check for self-consistency in the user input, which is a good thing. If so, it would be helpful if it created a more user-friendly, actionable error message, which could be tested for separately.

Full pytest output:

=============================== test session starts ===============================
platform darwin -- Python 3.10.0, pytest-7.1.2, pluggy-1.0.0 -- /Users/a.smith/.pyenv/versions/3.10.0/bin/python
cachedir: .pytest_cache
rootdir: /Users/a.smith/code/pandemia/pandemia, configfile: pytest.ini
plugins: flakefinder-1.1.0, typeguard-2.13.3, cov-4.0.0
collected 64 items / 63 deselected / 1 selected                                   

tests/test_components.py::test_vectorize_component[DefaultMovementModel] FAILED [100%]

==================================== FAILURES =====================================
_________________ test_vectorize_component[DefaultMovementModel] __________________

concrete_model = <pandemia.components.movement_model.default_movement_model.DefaultMovementModel object at 0x117cfd450>
sample_vector_region = <function sample_vector_region.<locals>.v_region at 0x137500dc0>

    def test_vectorize_component(concrete_model, sample_vector_region):
        """
        For all Component subclasses - test calling the `vectorize_component` method.
        In a simulation this is typically the first method called, after construction.

        **At present the only positive assertion that this has worked as expected is the change in the number of attributes on the `vector_region`.**

        NOTE: The expected values have _only_ been obtained by running this test. The have not been checked by manually inspecting the code.
        """

        # Find expected failure cases
        xfail_if = {
            "DefaultMovementModel": "Expected fail. See issue https://github.com/PandemiaProject/pandemia/issues/87"
        }

        expected_fail_reason = xfail_if.get(type(concrete_model).__name__, None)

        if expected_fail_reason:
            pytest.xfail(reason=expected_fail_reason)

        # Now do the actual tests for the remaining cases
        all_excepted_values = {
            "DefaultHealthModel": 27,
            "VoidHealthModel": 9,
            "DefaultHospitalizationAndDeathModel": 6,
            "VoidHospitalizationAndDeathModel": 0,
            "DefaultMovementModel": 1,
            "VoidMovementModel": 9,
            "DefaultPolicyMakerModel": 0,
            "OptimizationPolicyMakerModel": 0,
            "RandomPolicyMakerModel": 0,
            "ValidationPolicyMakerModel": 1,
            "VoidPolicyMakerModel": 0,
            "DefaultSeasonalEffectsModel": 2,
            "VoidSeasonalEffectsModel": 1,
            "DefaultTestingAndContactTracingModel": 8,
            "VoidTestingAndContactTracingModel": 0,
            "DefaultTravelModel": 2,
            "VoidTravelModel": 1,
            "DefaultVaccinationModel": 5,
            "VoidVaccinationModel": 0,
        }

        expected_extra_attributes = all_excepted_values[type(concrete_model).__name__]

        v_region = sample_vector_region()
        before = len(dir(v_region))
>       concrete_model.vectorize_component(v_region)

tests/test_components.py:168: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pandemia.components.movement_model.default_movement_model.DefaultMovementModel object at 0x117cfd450>
vector_region = <pandemia.world.region.VectorRegion object at 0x1374fe1d0>

    def vectorize_component(self, vector_region):
        """Initializes numpy arrays associated to this component"""

        number_of_agents = vector_region.number_of_agents
        number_of_activities = vector_region.number_of_activities
        max_num_activity_locations = vector_region.max_num_activity_locations

        vector_region.current_location = np.zeros((number_of_agents), dtype=np.int64)
        vector_region.requested_location_update = np.zeros((number_of_agents), dtype=np.int64)
        vector_region.requesting_location_update = np.zeros((number_of_agents), dtype=np.int64)
        vector_region.location_closure = np.ones((number_of_agents, number_of_activities,
                                          max_num_activity_locations), dtype=np.int64)
        vector_region.lockdown_intervention = 0
        vector_region.current_facemask = np.zeros((number_of_agents), dtype=np.int64)
        vector_region.requested_facemask_update = np.zeros((number_of_agents), dtype=np.int64)
        vector_region.requesting_facemask_update = np.zeros((number_of_agents), dtype=np.int64)
        vector_region.wears_facemask = np.zeros((number_of_agents, number_of_activities),
                                                dtype=np.int64)
        vector_region.facemask_intervention = 0
        vector_region.current_quarantine = np.zeros((number_of_agents), dtype=np.int64)

        vector_region.home_location = np.zeros((number_of_agents), dtype=np.int64)
>       assert self.home_activity in vector_region.activity_strings
E       AssertionError

src/pandemia/components/movement_model/default_movement_model.py:66: AssertionError
================================ warnings summary =================================
../../../.pyenv/versions/3.10.0/lib/python3.10/site-packages/joblib/backports.py:22
  /Users/a.smith/.pyenv/versions/3.10.0/lib/python3.10/site-packages/joblib/backports.py:22: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
    import distutils  # noqa

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

---------- coverage: platform darwin, python 3.10.0-final-0 ----------
Coverage HTML written to dir htmlcov

============================= short test summary info =============================
FAILED tests/test_components.py::test_vectorize_component[DefaultMovementModel]
=================== 1 failed, 63 deselected, 1 warning in 1.13s ===================