test_datetime.py 611 B

123456789101112131415161718192021222324
  1. import datetime
  2. import pytest
  3. import pytz
  4. from symuid._datetime import datetime_utc_now, unix_epoch_time_to_datetime_utc
  5. def test_datetime_utc_now():
  6. pytz_dt = datetime.datetime.now(pytz.timezone("UTC"))
  7. assert abs((datetime_utc_now() - pytz_dt).total_seconds()) < 5
  8. @pytest.mark.parametrize(
  9. ("ts_sec", "expected_dt"),
  10. [
  11. (
  12. 1528795204,
  13. datetime.datetime(2018, 6, 12, 9, 20, 4, tzinfo=datetime.timezone.utc),
  14. ),
  15. ],
  16. )
  17. def test_unix_epoch_time_to_datetime_utc(ts_sec, expected_dt):
  18. assert expected_dt == unix_epoch_time_to_datetime_utc(ts_sec)