93 lines
2 KiB
Python
93 lines
2 KiB
Python
"""Tests for the helper functions in conversions.py"""
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
import pytest
|
|
|
|
from dnidatetime.conversions import (
|
|
hvy2ord,
|
|
ord2hvy,
|
|
earth_to_dni,
|
|
dni_to_earth
|
|
)
|
|
|
|
|
|
def test_hvy2ord_8765_4_29():
|
|
assert hvy2ord(8765, 4, 29) == 322306
|
|
|
|
|
|
def test_hvy2ord_8765_5_1():
|
|
assert hvy2ord(8765, 5, 1) == hvy2ord(8765, 4, 29) + 1
|
|
|
|
|
|
def test_hvy2ord_8765_10_29():
|
|
assert hvy2ord(8765, 10, 29) == 322480
|
|
|
|
|
|
def test_hvy2ord_8766_1_1():
|
|
assert hvy2ord(8766, 1, 1) == hvy2ord(8765, 10, 29) + 1
|
|
|
|
|
|
def test_ord2hvy_too_low():
|
|
with pytest.raises(ValueError, match="Ordinal"):
|
|
ord2hvy(-1)
|
|
|
|
|
|
def test_ord2hvy_too_high():
|
|
with pytest.raises(ValueError, match="Ordinal"):
|
|
ord2hvy(2900500)
|
|
|
|
|
|
def test_ord2hvy_322306():
|
|
assert ord2hvy(322306) == (8765, 4, 29)
|
|
|
|
|
|
def test_ord2hvy_322307():
|
|
assert ord2hvy(322307) == (8765, 5, 1)
|
|
|
|
|
|
def test_ord2hvy_322480():
|
|
assert ord2hvy(322480) == (8765, 10, 29)
|
|
|
|
|
|
def test_ord2hvy_322481():
|
|
assert ord2hvy(322481) == (8766, 1, 1)
|
|
|
|
|
|
def test_earth_to_dni_no_timezone():
|
|
with pytest.raises(ValueError, match="timezone"):
|
|
earth_to_dni(datetime.now())
|
|
|
|
|
|
def test_earth_to_dni_dniepoch():
|
|
assert earth_to_dni(
|
|
datetime(1991, 4, 21, 16, 54, 0, tzinfo=timezone.utc)
|
|
) == (9647, 1, 1, 0, 0, 0, 0)
|
|
|
|
|
|
def test_earth_to_dni_2020():
|
|
assert earth_to_dni(
|
|
datetime(2020, 8, 27, 10, 51, 0, tzinfo=timezone.utc)
|
|
) == (9676, 4, 16, 1, 0, 20, 5)
|
|
|
|
|
|
def test_dni_to_earth_not_tuple():
|
|
with pytest.raises(ValueError, match="timetuple"):
|
|
dni_to_earth([9647, 1, 1, 0, 0, 0, 0])
|
|
|
|
|
|
def test_dni_to_earth_bad_tuple():
|
|
with pytest.raises(ValueError, match="malformed"):
|
|
dni_to_earth((9647, 1, 1))
|
|
|
|
|
|
def test_dni_to_earth_dniepoch():
|
|
assert dni_to_earth(
|
|
(9647, 1, 1, 0, 0, 0, 0)
|
|
) == datetime(1991, 4, 21, 16, 54, tzinfo=timezone.utc)
|
|
|
|
|
|
def test_dni_to_earth_2020():
|
|
assert dni_to_earth(
|
|
(9676, 4, 16, 1, 0, 20, 5)
|
|
) == datetime(2020, 8, 27, 10, 50, 59, 668172, tzinfo=timezone.utc)
|