"""Tests for the helper functions in util.py""" from datetime import datetime import pytest from dnidatetime.utils import ( cmp, divide_and_round, check_dni_date_fields, check_dni_time_fields, add_leap_seconds, get_ms_from_epoch, get_adj_ms_from_epoch, is_timezone_aware ) def test_cmp_lessthan(): assert cmp(1, 10) == -1 def test_cmp_equal(): assert cmp(5, 5) == 0 def test_cmp_greaterthan(): assert cmp(10, 1) == 1 def test_dar_down(): assert divide_and_round(5, 2) == 2 def test_dar_up(): assert divide_and_round(7, 2) == 4 def test_dar_no_rem(): assert divide_and_round(6, 2) == 3 def test_check_dnidate_hahr_low(): with pytest.raises(ValueError, match="Hahr"): check_dni_date_fields(7000, 1, 1) def test_check_dnidate_hahr_high(): with pytest.raises(ValueError, match="Hahr"): check_dni_date_fields(20000, 1, 1) def test_check_dnidate_vailee_low(): with pytest.raises(ValueError, match="Vailee"): check_dni_date_fields(7654, -1, 1) def test_check_dnidate_vailee_high(): with pytest.raises(ValueError, match="Vailee"): check_dni_date_fields(7654, 12, 1) def test_check_dnidate_yahr_low(): with pytest.raises(ValueError, match="Yahr"): check_dni_date_fields(7654, 1, -1) def test_check_dnidate_yahr_high(): with pytest.raises(ValueError, match="Yahr"): check_dni_date_fields(7654, 1, 31) def test_check_dnitime_gahrtahvo_low(): with pytest.raises(ValueError, match="Gahrtahvo"): check_dni_time_fields(-1, 0, 0, 0) def test_check_dnitime_gahrtahvo_high(): with pytest.raises(ValueError, match="Gahrtahvo"): check_dni_time_fields(10, 0, 0, 0) def test_check_dnitime_tahvo_low(): with pytest.raises(ValueError, match="Tahvo"): check_dni_time_fields(0, -1, 0, 0) def test_check_dnitime_tahvo_high(): with pytest.raises(ValueError, match="Tahvo"): check_dni_time_fields(0, 30, 0, 0) def test_check_dnitime_gorahn_low(): with pytest.raises(ValueError, match="Gorahn"): check_dni_time_fields(0, 0, -1, 0) def test_check_dnitime_gorahn_high(): with pytest.raises(ValueError, match="Gorahn"): check_dni_time_fields(0, 0, 30, 0) def test_check_dnitime_prorahn_low(): with pytest.raises(ValueError, match="Prorahn"): check_dni_time_fields(0, 0, 0, -1) def test_check_dnitime_prorahn_high(): with pytest.raises(ValueError, match="Prorahn"): check_dni_time_fields(0, 0, 0, 30) def test_add_leap_seconds_epoch(): assert add_leap_seconds(0) == 0 def test_add_leap_seconds_1984(): assert add_leap_seconds(455328000000) == 455328022000 def test_add_leap_seconds_2020(): assert add_leap_seconds(1598486400000) == 1598486437000 def test_get_ms_from_epoch_base(): assert get_ms_from_epoch(datetime(1970, 1, 1)) == 0 def test_get_ms_from_epoch_1984(): assert get_ms_from_epoch(datetime(1984, 6, 6)) == 455328000000 def test_get_ms_from_epoch_2020(): assert get_ms_from_epoch(datetime(2020, 8, 27)) == 1598486400000 def test_get_adj_ms_from_epoch_1959(): assert get_adj_ms_from_epoch(datetime(1959, 1, 17)) == -345772800000 def test_get_adj_ms_from_epoch_1981(): assert get_adj_ms_from_epoch(datetime(1981, 9, 14)) == 369273620000 def test_get_adj_ms_from_epoch_2023(): assert get_adj_ms_from_epoch(datetime(2023, 12, 8)) == 1701993637000 def test_is_timezone_aware_true(): assert is_timezone_aware(datetime.now().astimezone()) is True def test_is_timezone_aware_false(): assert is_timezone_aware(datetime.now()) is False