Skip to content

Commit

Permalink
better unit tests for type 5
Browse files Browse the repository at this point in the history
  • Loading branch information
pwoods25443 committed Apr 17, 2024
1 parent 7a11a78 commit 2e71c44
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
24 changes: 24 additions & 0 deletions tests/test_ais.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ def test_ais8_wrong_pad():
assert ('83am8S@j<d8dtfMEuj9loFOM6@0', 2) == AISMessageTranscoder.encode_nmea(msg)


@pytest.mark.parametrize("body,pad,expected", [
# incorrect padding
('56:=31`000008QaF220QD60`T4pN3N2222222216>pN5@50e0ES2@C`6EC`1hCQp8888880', 0,
{'name': 'HUA JIANG 7 '}),
# correct padding
('56:=31`000008QaF220QD60`T4pN3N2222222216>pN5@50e0ES2@C`6EC`1hCQp8888880', 2,
{'name': 'HUA JIANG 7 '})
])
def test_ais5(body, pad, expected):
msg = AISMessageTranscoder.decode_nmea(body, pad)
actual = {k: v for k, v in msg.items() if k in expected}
assert actual == expected


@pytest.mark.parametrize("body,pad,expected", [
# incorrect padding
('56:=31`000008QaF220QD60`T4pN3N2222222216>pN5@50e0ES2@C`6EC`1hCQp88888809999', 0,
'TYPE 5 LIBAIS ERR: Ais5: AIS_ERR_BAD_BIT_COUNT'),
])
def test_ais5_fail(body, pad, expected):
with pytest.raises(DecodeError, match=expected):
_ = AISMessageTranscoder.decode_nmea(body, pad)


@pytest.mark.parametrize("body,pad,expected", [
('9001?BP=h:qJ9vb;:f7EN1h240Rb', 0, {'mmsi': 20298, 'alt': 55, 'sog': 10}),
('90009C3dRIM1QSsjSPAa1;h200T4', 0, {'mmsi': 2380, 'alt': 946, 'alt_sensor': 0}),
Expand Down
10 changes: 0 additions & 10 deletions tests/test_aivdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,3 @@ def test_missing_part():
msg = decoder.safe_decode(nmea=nmea, best_effort=True)
assert msg['error'] == 'Expected 2 message parts to decode but found 1'
assert msg['tagblock_timestamp'] == 1668472438


@pytest.mark.parametrize("nmea", [
('\\c:1711942361,s:terrestrial,t:spire*4B\\!AIVDM,1,1,,A,56:=31`000008QaF220QD60`T4pN3N2222222216>pN5@50e0ES2@C`6EC`1hCQp8888880,0*60'),
('\\c:1711952914,s:terrestrial,t:spire*42\\!AIVDM,1,1,,A,56:Ib8P0000000000008DV09F1L4r1TTr374000j1p5320C=02U2ADj0CP000000000000:,0*03'),
])
def test_type_5_bad_padding(nmea):
decoder = AIVDM()
msg = decoder.safe_decode(nmea=nmea, best_effort=True)
assert 'error' not in msg

0 comments on commit 2e71c44

Please sign in to comment.