PandemiaProject / pandemia

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

Inconsistant `initial_conditions` method signature for MovementModels #88

Open andrewphilipsmith opened 1 year ago

andrewphilipsmith commented 1 year ago

Currently, two test fail due to differences in the initial_conditions method for MovementModels:

FAILED tests/test_components.py::test_initial_conditions[DefaultMovementModel] - TypeError: DefaultMovementModel.initial_conditions() missing 1 required positional argument: 'offset'
FAILED tests/test_components.py::test_initial_conditions[VoidMovementModel] - TypeError: VoidMovementModel.initial_conditions() missing 1 required positional argument: 'offset'

NOTES: Low Priority: Not a bug, more of a code-style thing. With a method like initial_conditions, which is passed down a class hierarchy, my preference is if the method signature can remain constant throughout the hierarchy. This is not an absolute rule by any means, but the consistency makes the code easier to read. In this case, is it feasible to pass the offset value to the component constructor? If it is too difficult to change the method signature in these two cases, then it would be appropriate to add an expectation to the test code - eg:

if type(concrete_model) not in [DefaultMovementModel, VoidMovementModel]:
    ...

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_initial_conditions[DefaultMovementModel] FAILED [100%]

==================================== FAILURES =====================================
__________________ test_initial_conditions[DefaultMovementModel] __________________

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

    def test_initial_conditions(concrete_model, sample_vector_region):
        """
        For all Component subclasses - test calling the `initial_conditions` method.

        The `vectorize_component` method is called first, has it is typically the first method called, after construction.
        Any errors from `vectorize_component` are ignored in this test.

        **At present the NO positive assertion that this has worked as expected. Only the absence of an error in
        `initial_conditions` is sufficient for this test to pass.
        """

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

        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
        v_region = sample_vector_region()

        # Ignore errors in `vectorize_component`
        try:
            concrete_model.vectorize_component(v_region)
        except Exception:
            pass

>       concrete_model.initial_conditions(v_region)
E       TypeError: DefaultMovementModel.initial_conditions() missing 1 required positional argument: 'offset'

tests/test_components.py:206: TypeError
================================ 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_initial_conditions[DefaultMovementModel]
=================== 1 failed, 63 deselected, 1 warning in 1.26s ===================