earthobservations / wetterdienst

Open weather data for humans.
https://wetterdienst.readthedocs.io/
MIT License
360 stars 55 forks source link

Timestamp processing fails after daylight saving time switchover #389

Closed amotl closed 2 years ago

amotl commented 3 years ago

This test currently fails on my machine when using hours=2.

https://github.com/earthobservations/wetterdienst/blob/42acabfd9b981c91e8030bc9786f2c25b6188ba9/tests/provider/dwd/observation/test_api_data.py#L230-L241

Like that:

$ pytest -vvvv -k test_request_period
===================================================================== test session starts ======================================================================
platform darwin -- Python 3.8.5, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 -- /Users/amo/Library/Caches/pypoetry/virtualenvs/wetterdienst-EkOFQaO8-py3.8/bin/python
cachedir: .pytest_cache
rootdir: /Users/amo/dev/earthobservations/wetterdienst, configfile: pyproject.toml
plugins: dictsdiff-0.5.8, cov-2.11.1, notebook-0.6.1, xdist-2.1.0, forked-1.3.0
collected 201 items / 196 deselected / 5 selected

tests/provider/dwd/observation/test_api_data.py::test_request_period_historical PASSED                                                                   [ 20%]
tests/provider/dwd/observation/test_api_data.py::test_request_period_historical_recent PASSED                                                            [ 40%]
tests/provider/dwd/observation/test_api_data.py::test_request_period_historical_recent_now PASSED                                                        [ 60%]
tests/provider/dwd/observation/test_api_data.py::test_request_period_now FAILED                                                                          [ 80%]
tests/provider/dwd/observation/test_api_data.py::test_request_period_empty PASSED                                                                        [100%]

=========================================================================== FAILURES ===========================================================================
___________________________________________________________________ test_request_period_now ____________________________________________________________________

    def test_request_period_now():

        # !!!Recent and now period cant be tested dynamically
        # TODO: add test with mocked datetime here

        # Now period
        request = DwdObservationRequest(
            parameter=[DwdObservationDataset.CLIMATE_SUMMARY],
            resolution=DwdObservationResolution.DAILY,
            start_date=pd.Timestamp(datetime.utcnow()) - pd.Timedelta(hours=2),
        )
>       assert Period.NOW in request.period
E       AssertionError: assert <Period.NOW: 'now'> in []
E        +  where <Period.NOW: 'now'> = Period.NOW
E        +  and   [] = <wetterdienst.provider.dwd.observation.api.DwdObservationRequest object at 0x168a8e6d0>.period

tests/provider/dwd/observation/test_api_data.py:241: AssertionError
--------------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------------
interval-1: [2021-03-28 17:22:12.428042, 2021-03-28 17:22:12.428042]
interval-2: [2021-03-27 00:00:00.656455, 2021-03-28 19:22:11.656455]
overlaps: False
=================================================================== short test summary info ====================================================================
FAILED tests/provider/dwd/observation/test_api_data.py::test_request_period_now - AssertionError: assert <Period.NOW: 'now'> in []
========================================================= 1 failed, 4 passed, 196 deselected in 1.29s ==========================================================

_Originally posted by @amotl in https://github.com/earthobservations/wetterdienst/pull/388#discussion_r602919518_

amotl commented 3 years ago

JFYI. The same thing works on behalf of https://gist.github.com/amotl/4a58dbc621acab7403ed630900a53115.

gutzbenj commented 2 years ago

Closing for the moment. May open again when issue reoccurs.