Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions tests/test_nmea/test_protocols.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 0 additions & 14 deletions tests/test_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from ais.protocols import AISMessageHandler
from aisutils.protocols import DatabaseBridge, GISExporter
from nmea.protocols import NMEASentenceHandler


class DummyAISDecoder:
Expand All @@ -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
Expand All @@ -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)
Expand Down
Loading