test_datetime.py 562 B

12345678910111213141516171819
  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(('ts_sec', 'expected_dt'), [
  9. (1528795204,
  10. datetime.datetime(2018, 6, 12, 9, 20, 4, tzinfo=datetime.timezone.utc)),
  11. ])
  12. def test_unix_epoch_time_to_datetime_utc(ts_sec, expected_dt):
  13. assert expected_dt == unix_epoch_time_to_datetime_utc(ts_sec)