Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fails on some days #22

Closed
dotlambda opened this issue Feb 28, 2023 · 2 comments · Fixed by #23
Closed

Test fails on some days #22

dotlambda opened this issue Feb 28, 2023 · 2 comments · Fixed by #23

Comments

@dotlambda
Copy link

My local time is

Tue Feb 28 11:54:04 AM PST 2023

and the tests fail with

============================= test session starts ==============================
platform linux -- Python 3.10.10, pytest-7.2.0, pluggy-1.0.0
rootdir: /build/tempora-5.1.0, configfile: pytest.ini
plugins: freezegun-0.4.2
collected 42 items

tempora/__init__.py ..........F.                                         [ 28%]
tempora/schedule.py ...                                                  [ 35%]
tempora/timing.py .....                                                  [ 47%]
tempora/utc.py .                                                         [ 50%]
tempora/tests/test_schedule.py ...................                       [ 95%]
tempora/tests/test_timing.py ..                                          [100%]

=================================== FAILURES ===================================
______________________ [doctest] tempora.parse_timedelta _______________________
382
383     >>> parse_timedelta('1 year, 1 month')
384     datetime.timedelta(days=395, seconds=58685)
385
386     Note that months and years strict intervals, not aligned
387     to a calendar:
388
389     >>> now = datetime.datetime.now()
390     >>> later = now + parse_timedelta('1 year')
391     >>> diff = later.replace(year=now.year) - now
UNEXPECTED EXCEPTION: ValueError('day is out of range for month')
Traceback (most recent call last):
  File "/nix/store/iw1vmh509hcbby8dbpsaanbri4zsq7dj-python3-3.10.10/lib/python3.10/doctest.py", line 1350, in __run
    exec(compile(example.source, filename, "single",
  File "<doctest tempora.parse_timedelta[7]>", line 1, in <module>
ValueError: day is out of range for month
/build/tempora-5.1.0/tempora/__init__.py:391: UnexpectedException
=========================== short test summary info ============================
FAILED tempora/__init__.py::tempora.parse_timedelta
========================= 1 failed, 41 passed in 1.53s =========================
@DimStar77
Copy link

Looking at the code, the issue is that 'next year is a leap year': the test does:

now=datetime.datetime.now()
print(now)
later = now + datetime.timedelta(days=365)
print(later)
diff = later.replace(year=now.year) - now
>>> now=datetime.datetime.now()
>>> print(now)
2023-03-01 10:17:55.056591
>>> later = now + datetime.timedelta(days=365)
>>> print(later)
2024-02-29 10:17:55.056591

There we can already see that 'diff' can't be valid if we replace the year from 'later (2024) with this year (2023).

@jaraco
Copy link
Owner

jaraco commented Apr 10, 2023

Ha. Okay. So that test would fail for about 20k seconds when run one year before the leap day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants