Skip to content

Commit b5b18c1

Browse files
committed
GeoCom tests start
1 parent 6914f97 commit b5b18c1

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
pytest.register_assert_rewrite(
44
"helpers",
5+
"helpers_geocom",
56
"helpers_gsionline"
67
)

tests/helpers_geocom.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import re
2+
3+
from geocompy import GeoComProtocol
4+
from geocompy.communication import Connection
5+
from geocompy.data import (
6+
Byte
7+
)
8+
9+
10+
class DummyGeoComConnection(Connection):
11+
_RESP = re.compile(
12+
r"^%R1P,"
13+
r"(?P<comrc>\d+),"
14+
r"(?P<tr>\d+):"
15+
r"(?P<rc>\d+)"
16+
r"(?:,(?P<params>.*))?$"
17+
)
18+
19+
_CMD = re.compile(
20+
r"^%R1Q,"
21+
r"(?P<rpc>\d+):"
22+
r"(?:,(?P<params>.*))?$"
23+
)
24+
25+
def send(self, message: str):
26+
return
27+
28+
def exchange1(self, cmd: str) -> str:
29+
print(cmd)
30+
31+
if not self._CMD.match(cmd):
32+
return "%R1P,0,2:"
33+
34+
if cmd == "%R1Q,0:":
35+
return "%R1P,0,0:0"
36+
37+
return ""
38+
39+
40+
class GeoComTester:
41+
@staticmethod
42+
def test_parse_response(instrument: GeoComProtocol):
43+
response = instrument.parse_response(
44+
"%R1Q,5008:",
45+
"%R1P,0,0:0,1996,'07','19','10','13','2f'",
46+
{
47+
"year": int,
48+
"month": Byte.parse,
49+
"day": Byte.parse,
50+
"hour": Byte.parse,
51+
"minute": Byte.parse,
52+
"second": Byte.parse
53+
}
54+
)
55+
assert response.params["year"] == 1996

tests/test_tps1200p.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
3+
from geocompy.tps1200p import TPS1200P
4+
5+
from helpers_geocom import (
6+
DummyGeoComConnection,
7+
GeoComTester
8+
)
9+
10+
11+
@pytest.fixture
12+
def tps() -> TPS1200P:
13+
return TPS1200P(DummyGeoComConnection())
14+
15+
16+
class TestTPS1200P:
17+
def test_parse_response(self, tps: TPS1200P):
18+
GeoComTester.test_parse_response(tps)

0 commit comments

Comments
 (0)