From 0c6194229d4ac0b6b4276eeaa3d77358983b62bc Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 17 Sep 2026 23:24:35 +0000 Subject: [PATCH] test(nmea): add dedicated test file for NMEASentenceHandler protocol Moved NMEA protocol tests from generic `tests/test_protocols.py` to a dedicated `tests/test_nmea/test_protocols.py` file. Added dummy classes to specifically test the structural subtyping (runtime_checkable) of the `NMEASentenceHandler` protocol, ensuring both conforming and non-conforming implementations are correctly identified. --- tests/test_nmea/test_protocols.py | 44 +++++++++++++++++++++++++++++++ tests/test_protocols.py | 14 ---------- 2 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 tests/test_nmea/test_protocols.py 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)