Download tests/unit/shared/test_datetime_utils.py from paisaly/backend: direct link, hf CLI and curl.
- Browser
- Download file 3.23 kB
-
https://huggingface.co/spaces/paisaly/backend/resolve/main/tests/unit/shared/test_datetime_utils.py
- Command line
-
hf download hf://spaces/paisaly/backend/tests/unit/shared/test_datetime_utils.py
-
curl -L -o test_datetime_utils.py https://huggingface.co/spaces/paisaly/backend/resolve/main/tests/unit/shared/test_datetime_utils.py
3.23 kB
| from __future__ import annotations | |
| from datetime import datetime, timezone | |
| import pytest | |
| from app.shared.datetime_utils import ( | |
| convert_to_gmt, | |
| parse_datetime, | |
| to_unix_timestamp, | |
| to_unix_timestamp_ceil, | |
| ) | |
| # --------------------------------------------------------------------------- | |
| # shared.datetime_utils — parse_datetime | |
| # --------------------------------------------------------------------------- | |
| def test_parse_datetime(value, expected): | |
| assert parse_datetime(value) == expected | |
| def test_parse_datetime_naive_assumed_utc(): | |
| dt = parse_datetime("2024-06-01T00:00:00") | |
| assert dt is not None and dt.tzinfo == timezone.utc | |
| # --------------------------------------------------------------------------- | |
| # shared.datetime_utils — convert_to_gmt | |
| # --------------------------------------------------------------------------- | |
| def test_convert_to_gmt(value, expected): | |
| assert convert_to_gmt(value) == expected | |
| # --------------------------------------------------------------------------- | |
| # shared.datetime_utils — to_unix_timestamp_ceil | |
| # --------------------------------------------------------------------------- | |
| _WHOLE = datetime(2030, 6, 1, 12, 0, 0, tzinfo=timezone.utc) | |
| _WHOLE_TS = int(_WHOLE.timestamp()) | |
| def test_to_unix_timestamp_ceil(value, expected): | |
| assert to_unix_timestamp_ceil(value) == expected | |
| def test_ceil_agrees_with_floor_on_whole_seconds(): | |
| whole = datetime(2030, 6, 1, 12, 0, 0, tzinfo=timezone.utc) | |
| assert to_unix_timestamp_ceil(whole) == to_unix_timestamp(whole) | |