19from decimal
import Decimal
20from unittest
import mock
24from freezegun
import freeze_time
26from lal
import (LIGOTimeGPS, gpstime)
29@mock.patch("lal.gpstime._gps_time_now", return_value=LIGOTimeGPS(100))
31 assert gpstime.gps_time_now() == 100.
34@pytest.mark.parametrize(
'date, gps', [
35 (datetime.datetime(2000, 1, 1, 0, 0, 0), 630720013),
36 (datetime.date(2000, 1, 2), 630806413),
39 out = gpstime.utc_to_gps(date)
40 assert isinstance(out, LIGOTimeGPS)
41 assert out == LIGOTimeGPS(gps)
44@pytest.mark.parametrize(
'gps, date', [
45 (630720013, datetime.datetime(2000, 1, 1, 0, 0, 0)),
46 (LIGOTimeGPS(630720013, 12345), datetime.datetime(2000, 1, 1, 0, 0, 0, 12)),
47 (LIGOTimeGPS(630720013, 12999), datetime.datetime(2000, 1, 1, 0, 0, 0, 13)),
48 (Decimal(
"1234567890.123456789"), datetime.datetime(2019, 2, 18, 23, 31, 12, 123457)),
51 assert gpstime.gps_to_utc(gps) == date
54@mock.patch("lal.gpstime._gps_time_now", return_value=LIGOTimeGPS(100))
56 assert gpstime.utc_time_now() == datetime.datetime(
61@freeze_time("2015-09-14 09:50:45.391")
62@mock.patch("lal.gpstime._gps_time_now", return_value=LIGOTimeGPS(1126259462))
63@pytest.mark.parametrize(
'text, gps', [
66 (
"today", 1126224017),
67 (
"tomorrow", 1126310417),
68 (
"yesterday", 1126137617),
69 (
"Sep 14 2015 09:50:45.391", LIGOTimeGPS(1126259462, 391000000)),
72 out = gpstime.str_to_gps(text)
74 assert isinstance(out, LIGOTimeGPS)
75 assert out == LIGOTimeGPS(gps)
78@pytest.mark.parametrize(
'gps, text', [
79 (LIGOTimeGPS(1126259462, 391000000),
80 "September 14 2015, 09:50:45.391000 UTC"),
81 (1126259462,
"September 14 2015, 09:50:45 UTC"),
84 assert gpstime.gps_to_str(gps) == text
88 assert gpstime.gps_to_str(12345, form=
"%Y%m%d") ==
"19800106"
91@mock.patch("lal.gpstime._gps_time_now", return_value=LIGOTimeGPS(1126259462))
92@pytest.mark.parametrize(
'in_, result', [
93 (
"now", LIGOTimeGPS(1126259462)),
94 (LIGOTimeGPS(1126259462, 391000000),
95 "September 14 2015, 09:50:45.391000 UTC"),
98 out = gpstime.tconvert(in_)
99 assert type(out) == type(result)
103if __name__ ==
'__main__':
104 args = sys.argv[1:]
or [
"-v",
"-rs",
"--junit-xml=junit-gpstime.xml"]
105 sys.exit(pytest.main(args=[__file__] + args))
def test_str_to_gps(_, text, gps)
def test_gps_to_str(gps, text)
def test_gps_to_str_form()
def test_utc_to_gps(date, gps)
def test_gps_to_utc(gps, date)
def test_tconvert(_, in_, result)