Skip to content

Commit d71dfd8

Browse files
committed
Updated GeoComTester
1 parent d7f6df7 commit d71dfd8

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

tests/helpers_geocom.py

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Callable, Any
1+
from typing import Callable, Any, Iterable
22
import re
33

44
from geocompy.protocols import GeoComProtocol
@@ -43,51 +43,60 @@ class GeoComTester:
4343
def test_parse_response(instrument: GeoComProtocol):
4444
cmd = "%R1Q,5008:"
4545
answer = "%R1P,0,0:0,1996,'07','19','10','13','2f'"
46-
parsers: dict[str, Callable[[str], Any]] = {
47-
"year": int,
48-
"month": Byte.parse,
49-
"day": Byte.parse,
50-
"hour": Byte.parse,
51-
"minute": Byte.parse,
52-
"second": Byte.parse
53-
}
46+
parsers: Iterable[Callable[[str], Any]] = (
47+
int,
48+
Byte.parse,
49+
Byte.parse,
50+
Byte.parse,
51+
Byte.parse,
52+
Byte.parse
53+
)
5454
response = instrument.parse_response(
5555
cmd,
5656
answer,
5757
parsers
5858
)
59-
assert response.params["year"] == 1996
59+
assert response.params is not None
60+
assert response.params[0] == 1996
6061

6162
response = instrument.parse_response(
6263
cmd,
6364
"%R1P,1,0:",
6465
parsers
6566
)
66-
assert len(response.params) == 0
67+
assert response.params is None
68+
# assert len(response.params) == 0
6769

68-
parsers_faulty = parsers.copy()
69-
parsers_faulty["year"] = faulty_parser
70+
parsers_faulty = (
71+
faulty_parser,
72+
Byte.parse,
73+
Byte.parse,
74+
Byte.parse,
75+
Byte.parse,
76+
Byte.parse
77+
)
7078
response = instrument.parse_response(
7179
cmd,
7280
answer,
7381
parsers_faulty
7482
)
75-
assert len(response.params) == 0
83+
assert response.params is None
7684

7785
@staticmethod
7886
def test_request(instrument: GeoComProtocol):
7987
response = instrument.request(
8088
5008,
81-
parsers={
82-
"year": int,
83-
"month": Byte.parse,
84-
"day": Byte.parse,
85-
"hour": Byte.parse,
86-
"minute": Byte.parse,
87-
"second": Byte.parse
88-
}
89+
parsers=(
90+
int,
91+
Byte.parse,
92+
Byte.parse,
93+
Byte.parse,
94+
Byte.parse,
95+
Byte.parse
96+
)
8997
)
90-
assert response.params["year"] == 1996
98+
assert response.params is not None
99+
assert response.params[0] == 1996
91100

92101
response = instrument.request(
93102
1,

0 commit comments

Comments
 (0)