HopkinsIDD / flepiMoP

The Flexible Epidemic Modeling Pipeline
https://flepimop.org
GNU General Public License v3.0
9 stars 4 forks source link

`TestRunId.test_get_run_id_default_timestamp` Time Dependent Test Failure #287

Closed TimothyWillard closed 3 months ago

TimothyWillard commented 3 months ago

Describe the bug

The TestRunId.test_get_run_id_default_timestamp test fixture can fail if the after date time has 59 seconds for reasons that are irrelevant to the code.

To Reproduce

It's dependent on the timestamp so it's hard to reproduce naturally unless you get lucky (or unlucky).

  1. Changed this line of code:
    after = datetime.now()

    to

    after = datetime.now().replace(second=59)

    in flepimop/gempyor_pkg/tests/file_paths/test_run_id.py.

  2. Run the unit test with pytest flepimop/gempyor_pkg/tests/file_paths/test_run_id.py -v.
  3. Then the test fixture should fail with an error that looks like:
    FAILED flepimop/gempyor_pkg/tests/file_paths/test_run_id.py::TestRunId::test_get_run_id_default_timestamp - ValueError: second must be in 0..59

Expected behavior

This test fixture should be able to handle a datetime object with a seconds of 59, I think it just needs to be done more carefully using timedeltas instead of haphazardly messing with the components. Instead of

after = after.replace(microsecond=0, second=after.second + 1)

something like

after = (after + timedelta(seconds=1)).replace(microsecond=0)

or similar.

Environment, if relevant: