Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeF1 Date Format 1 #32

Closed
linville opened this issue Jan 9, 2023 · 0 comments · Fixed by #33
Closed

TimeF1 Date Format 1 #32

linville opened this issue Jan 9, 2023 · 0 comments · Fixed by #33

Comments

@linville
Copy link
Contributor

linville commented Jan 9, 2023

TimeF1 packets set to date_format 1 (w/ Month and Year available) are missing the month and day fields.

PR #31 introduced a new unit test test_time_bytes_with_ms that has a bug; it does not specify the date_format so the packet can only contain IRIG day, not the year. The year data is truncated, but this wasn't evident as the current year was re-added to the Python date time which at that time matched the test data so the bug wasn't revealed until the new year. Running the test now errors out with:

>       assert time.TimeF1(io.BytesIO(raw)).time == t0.time
E       AssertionError: assert datetime.datetime(2023, 12, 5, 1, 2, 3, 450000) == datetime.datetime(2022, 12, 5, 1, 2, 3, 450000)
E        +  where datetime.datetime(2023, 12, 5, 1, 2, 3, 450000) = <TimeF1 36 bytes>.time
E        +    where <TimeF1 36 bytes> = <class 'chapter10.time.TimeF1'>(<_io.BytesIO object at 0x1091041d0>)
E        +      where <class 'chapter10.time.TimeF1'> = time.TimeF1
E        +      and   <_io.BytesIO object at 0x1091041d0> = <class '_io.BytesIO'>(b'%\xeb\x00\x00$\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00S\xeb\x00\x00\x00\x00E\x03\x02\x019\x03\x00\x00')
E        +        where <class '_io.BytesIO'> = io.BytesIO
E        +  and   datetime.datetime(2022, 12, 5, 1, 2, 3, 450000) = <TimeF1 36 bytes>.time
tests/unit/test_time.py:33: AssertionError

The test could be fixed by only comparing the fields that would be contained in date_format=0 packet (IRIG Day and below). A better fix would be TimeF1 with date_format=1 that includes the year data. Fixing that error than causes the test to error out with a new error:

>           self.time = datetime(year, month, day)
E           ValueError: month must be in 1..12

chapter10/time.py:136: ValueError
...
FAILED tests/unit/test_time.py::test_time_bytes_with_ms - ValueError: month must be in 1..12

In debugging this, a little restructuring of the unit test would reveal an unpack error due to not enough data.

PR incoming shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant