Skip to content

Commit

Permalink
Test read_sentence/update
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Feb 9, 2022
1 parent 7a19c35 commit dedd8d2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/pa1010d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def read_sentence(self, timeout=5):
# Should be a full \r\n since the GPS emits spurious newlines
if buf[-2:] == [ord("\r"), ord("\n")]:
# Remove line ending and spurious newlines from the sentence
return bytearray(buf).decode("ascii").strip().replace("\n","")
return bytearray(buf).decode("ascii").strip().replace("\n", "")

raise TimeoutError("Timeout waiting for readline")

Expand Down
19 changes: 19 additions & 0 deletions library/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,28 @@
import sys


class SMBus:
def __init__(self, bus):
self.data = "$PMTK011,MTKGPS*08\r\n".encode("ascii")
self.ptr = 0

def read_byte_data(self, address, register):
if register == 0x00:
result = self.data[self.ptr]
self.ptr += 1
self.ptr %= len(self.data)
return result
else:
return 0

def write_byte(self, address, data):
pass


@pytest.fixture(scope='function', autouse=False)
def smbus():
smbus = mock.MagicMock()
smbus.SMBus = SMBus
sys.modules["smbus"] = smbus
yield smbus
del sys.modules["smbus"]
9 changes: 9 additions & 0 deletions library/tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ def test_send_command(smbus):

gps = pa1010d.PA1010D()
gps.send_command("$TEST")
gps.send_command("$TEST*")
gps.send_command("$TEST*".encode("ascii"))


def test_recv_command(smbus):
import pa1010d

gps = pa1010d.PA1010D()
assert gps.update() is True

0 comments on commit dedd8d2

Please sign in to comment.