|
6 | 6 |
|
7 | 7 | """Tests for Utilities""" |
8 | 8 |
|
9 | | -from datetime import datetime |
| 9 | +from datetime import datetime, timezone |
10 | 10 |
|
11 | 11 | import pytest |
12 | 12 |
|
13 | 13 | from sigmf import utils |
14 | 14 |
|
15 | 15 |
|
16 | | -@pytest.mark.parametrize("ts, expected", [ |
17 | | - ("1955-07-04T05:15:00Z", datetime(year=1955, month=7, day=4, hour=5, minute=15, second=00, microsecond=0)), |
18 | | - ("2956-08-05T06:15:12Z", datetime(year=2956, month=8, day=5, hour=6, minute=15, second=12, microsecond=0)), |
19 | | - ("3957-09-06T07:15:12.345Z", datetime(year=3957, month=9, day=6, hour=7, minute=15, second=12, microsecond=345000)), |
20 | | - ("4958-10-07T08:15:12.0345Z", datetime(year=4958, month=10, day=7, hour=8, minute=15, second=12, microsecond=34500)), |
21 | | - ("5959-11-08T09:15:12.000000Z", datetime(year=5959, month=11, day=8, hour=9, minute=15, second=12, microsecond=0)), |
22 | | - ("6960-12-09T10:15:12.123456789123Z", datetime(year=6960, month=12, day=9, hour=10, minute=15, second=12, microsecond=123456)), |
| 16 | +@pytest.mark.parametrize("time_str, expected", [ |
| 17 | + ("1955-07-04T05:15:00Z", datetime(year=1955, month=7, day=4, hour=5, minute=15, second=00, microsecond=0, tzinfo=timezone.utc)), |
| 18 | + ("2956-08-05T06:15:12Z", datetime(year=2956, month=8, day=5, hour=6, minute=15, second=12, microsecond=0, tzinfo=timezone.utc)), |
| 19 | + ("3957-09-06T07:15:12.345Z", datetime(year=3957, month=9, day=6, hour=7, minute=15, second=12, microsecond=345000, tzinfo=timezone.utc)), |
| 20 | + ("4958-10-07T08:15:12.0345Z", datetime(year=4958, month=10, day=7, hour=8, minute=15, second=12, microsecond=34500, tzinfo=timezone.utc)), |
| 21 | + ("5959-11-08T09:15:12.000000Z", datetime(year=5959, month=11, day=8, hour=9, minute=15, second=12, microsecond=0, tzinfo=timezone.utc)), |
| 22 | + ("6960-12-09T10:15:12.123456789123Z", datetime(year=6960, month=12, day=9, hour=10, minute=15, second=12, microsecond=123456, tzinfo=timezone.utc)), |
23 | 23 |
|
24 | 24 | ]) |
25 | | -def test_parse_simple_iso8601(ts, expected): |
26 | | - dt = utils.parse_iso8601_datetime(ts) |
27 | | - assert dt == expected |
| 25 | +def test_parse_simple_iso8601(time_str: str, expected: datetime) -> None: |
| 26 | + """Ensure various times are represented as expected""" |
| 27 | + date_struct = utils.parse_iso8601_datetime(time_str) |
| 28 | + assert date_struct == expected |
| 29 | + |
| 30 | + |
| 31 | +def test_roundtrip_datetime() -> None: |
| 32 | + """New string -> struct -> string is ok""" |
| 33 | + now_str = utils.get_sigmf_iso8601_datetime_now() |
| 34 | + now_struct = utils.parse_iso8601_datetime(now_str) |
| 35 | + assert now_str == now_struct.strftime(utils.SIGMF_DATETIME_ISO8601_FMT) |
0 commit comments