def test_chrono_system_clock_roundtrip(): date1 = datetime.datetime.today() # Roundtrip the time date2 = m.test_chrono2(date1) # The returned value should be a datetime assert isinstance(date2, datetime.datetime) # They should be identical (no information lost on roundtrip) diff = abs(date1 - date2) assert diff.days == 0 assert diff.seconds == 0 assert diff.microseconds == 0
def test_chrono_system_clock_roundtrip(): date1 = datetime.datetime.today() # Roundtrip the time date2 = m.test_chrono2(date1) # The returned value should be a datetime assert isinstance(date2, datetime.datetime) # They should be identical (no information lost on roundtrip) diff = abs(date1 - date2) assert diff.days == 0 assert diff.seconds == 0 assert diff.microseconds == 0
def test_chrono_system_clock_roundtrip_time(time1, tz, monkeypatch): if tz is not None: monkeypatch.setenv("TZ", "/usr/share/zoneinfo/{}".format(tz)) # Roundtrip the time datetime2 = m.test_chrono2(time1) date2 = datetime2.date() time2 = datetime2.time() # The returned value should be a datetime assert isinstance(datetime2, datetime.datetime) assert isinstance(date2, datetime.date) assert isinstance(time2, datetime.time) # Hour, Minute, Second & Microsecond should be the same after the round trip assert time1 == time2 # There should be no date information (i.e. date = python base date) assert date2.year == 1970 assert date2.month == 1 assert date2.day == 1
def test_chrono_system_clock_roundtrip_time(): time1 = datetime.datetime.today().time() # Roundtrip the time datetime2 = m.test_chrono2(time1) date2 = datetime2.date() time2 = datetime2.time() # The returned value should be a datetime assert isinstance(datetime2, datetime.datetime) assert isinstance(date2, datetime.date) assert isinstance(time2, datetime.time) # Hour, Minute, Second & Microsecond should be the same after the round trip assert time1.hour == time2.hour assert time1.minute == time2.minute assert time1.second == time2.second assert time1.microsecond == time2.microsecond # There should be no date information (i.e. date = python base date) assert date2.year == 1970 assert date2.month == 1 assert date2.day == 1
def test_numpy_chrono_system_clock_roundtrip_date(): date1 = datetime.datetime.today().date() date1_np = np.datetime64(date1) # Roundtrip the time datetime2 = m.test_chrono2(date1_np) date2 = datetime2.date() time2 = datetime2.time() # The returned value should be a datetime assert isinstance(datetime2, datetime.datetime) assert isinstance(date2, datetime.date) assert isinstance(time2, datetime.time) # There should be no time information assert time2.hour == 0 assert time2.minute == 0 assert time2.second == 0 assert time2.microsecond == 0 # Year, Month & Day should be the same after the round trip assert date2.year == date1.year assert date2.month == date1.month assert date2.day == date1.day