19 from decimal
import Decimal
20 from unittest
import mock
24 from freezegun
import freeze_time
26 from 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', [
(datetime.datetime(2000, 1, 1, 0, 0, 0), 630720013),
35 (datetime.date(2000, 1, 2), 630806413),
38 out = gpstime.utc_to_gps(date)
39 assert isinstance(out, LIGOTimeGPS)
40 assert out == LIGOTimeGPS(gps)
43 @pytest.mark.parametrize('gps, date', [
(630720013, datetime.datetime(2000, 1, 1, 0, 0, 0)),
44 (LIGOTimeGPS(630720013, 12345), datetime.datetime(2000, 1, 1, 0, 0, 0, 12)),
45 (LIGOTimeGPS(630720013, 12999), datetime.datetime(2000, 1, 1, 0, 0, 0, 13)),
46 (Decimal(
"1234567890.123456789"), datetime.datetime(2019, 2, 18, 23, 31, 12, 123457)),
49 assert gpstime.gps_to_utc(gps) == date
52 @mock.patch("lal.gpstime._gps_time_now", return_value=LIGOTimeGPS(100))
54 assert gpstime.utc_time_now() == datetime.datetime(
59 @freeze_time("2015-09-14 09:50:45.391")
60 @mock.patch("lal.gpstime._gps_time_now", return_value=LIGOTimeGPS(1126259462))
61 @pytest.mark.parametrize('text, gps', [
(None, 1126259462),
63 (
"today", 1126224017),
64 (
"tomorrow", 1126310417),
65 (
"yesterday", 1126137617),
66 (
"Sep 14 2015 09:50:45.391", LIGOTimeGPS(1126259462, 391000000)),
69 out = gpstime.str_to_gps(text)
71 assert isinstance(out, LIGOTimeGPS)
72 assert out == LIGOTimeGPS(gps)
75 @pytest.mark.parametrize('gps, text', [
(LIGOTimeGPS(1126259462, 391000000),
76 "September 14 2015, 09:50:45.391000 UTC"),
77 (1126259462,
"September 14 2015, 09:50:45 UTC"),
80 assert gpstime.gps_to_str(gps) == text
84 assert gpstime.gps_to_str(12345, form=
"%Y%m%d") ==
"19800106"
87 @mock.patch("lal.gpstime._gps_time_now", return_value=LIGOTimeGPS(1126259462))
88 @pytest.mark.parametrize('in_, result', [
("now", LIGOTimeGPS(1126259462)),
89 (LIGOTimeGPS(1126259462, 391000000),
90 "September 14 2015, 09:50:45.391000 UTC"),
93 out = gpstime.tconvert(in_)
94 assert type(out) == type(result)
98 if __name__ ==
'__main__':
99 args = sys.argv[1:]
or [
"-v",
"-rs",
"--junit-xml=junit-gpstime.xml"]
100 sys.exit(pytest.main(args=[__file__] + args))
101
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)