diff --git a/tests/test_nmea/test_protocols.py b/tests/test_nmea/test_protocols.py new file mode 100644 index 0000000..e2abac6 --- /dev/null +++ b/tests/test_nmea/test_protocols.py @@ -0,0 +1,44 @@ +"""Unit tests for NMEA structural protocols.""" + +from typing import Any + +from nmea.protocols import NMEASentenceHandler + + +class ConformingNMEADecoder: + """A dummy class that implements the NMEASentenceHandler protocol.""" + + def decode(self, sentence: str) -> dict[str, Any]: + return {"talker": "GP", "sentence_id": "RMC"} + + def checksum(self, sentence: str) -> str: + return "00" + + +class NonConformingNMEADecoderMissingChecksum: + """A dummy class missing the checksum method.""" + + def decode(self, sentence: str) -> dict[str, Any]: + return {"talker": "GP"} + + +class NonConformingNMEADecoderMissingDecode: + """A dummy class missing the decode method.""" + + def checksum(self, sentence: str) -> str: + return "00" + + +def test_nmea_sentence_handler_conforming() -> None: + """Test that a compliant class is recognized by the protocol.""" + decoder = ConformingNMEADecoder() + assert isinstance(decoder, NMEASentenceHandler) + + +def test_nmea_sentence_handler_non_conforming() -> None: + """Test that non-compliant classes are rejected by the protocol.""" + missing_checksum = NonConformingNMEADecoderMissingChecksum() + assert not isinstance(missing_checksum, NMEASentenceHandler) + + missing_decode = NonConformingNMEADecoderMissingDecode() + assert not isinstance(missing_decode, NMEASentenceHandler) diff --git a/tests/test_protocols.py b/tests/test_protocols.py index f352054..38034b6 100644 --- a/tests/test_protocols.py +++ b/tests/test_protocols.py @@ -2,7 +2,6 @@ from ais.protocols import AISMessageHandler from aisutils.protocols import DatabaseBridge, GISExporter -from nmea.protocols import NMEASentenceHandler class DummyAISDecoder: @@ -13,14 +12,6 @@ def encode(self, params, validate=True): return None -class DummyNMEADecoder: - def decode(self, sentence): - return {"talker": "GP"} - - def checksum(self, sentence): - return "00" - - class DummyDBBridge: def sql_create_table(self, outfile, db_type="sqlite", table_name=None): pass @@ -39,11 +30,6 @@ def test_ais_message_handler_protocol(): assert isinstance(decoder, AISMessageHandler) -def test_nmea_sentence_handler_protocol(): - decoder = DummyNMEADecoder() - assert isinstance(decoder, NMEASentenceHandler) - - def test_database_bridge_protocol(): bridge = DummyDBBridge() assert isinstance(bridge, DatabaseBridge)