|
1 | | -from typing import Callable, Any |
| 1 | +from typing import Callable, Any, Iterable |
2 | 2 | import re |
3 | 3 |
|
4 | 4 | from geocompy.protocols import GeoComProtocol |
@@ -43,51 +43,60 @@ class GeoComTester: |
43 | 43 | def test_parse_response(instrument: GeoComProtocol): |
44 | 44 | cmd = "%R1Q,5008:" |
45 | 45 | 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 | + ) |
54 | 54 | response = instrument.parse_response( |
55 | 55 | cmd, |
56 | 56 | answer, |
57 | 57 | parsers |
58 | 58 | ) |
59 | | - assert response.params["year"] == 1996 |
| 59 | + assert response.params is not None |
| 60 | + assert response.params[0] == 1996 |
60 | 61 |
|
61 | 62 | response = instrument.parse_response( |
62 | 63 | cmd, |
63 | 64 | "%R1P,1,0:", |
64 | 65 | parsers |
65 | 66 | ) |
66 | | - assert len(response.params) == 0 |
| 67 | + assert response.params is None |
| 68 | + # assert len(response.params) == 0 |
67 | 69 |
|
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 | + ) |
70 | 78 | response = instrument.parse_response( |
71 | 79 | cmd, |
72 | 80 | answer, |
73 | 81 | parsers_faulty |
74 | 82 | ) |
75 | | - assert len(response.params) == 0 |
| 83 | + assert response.params is None |
76 | 84 |
|
77 | 85 | @staticmethod |
78 | 86 | def test_request(instrument: GeoComProtocol): |
79 | 87 | response = instrument.request( |
80 | 88 | 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 | + ) |
89 | 97 | ) |
90 | | - assert response.params["year"] == 1996 |
| 98 | + assert response.params is not None |
| 99 | + assert response.params[0] == 1996 |
91 | 100 |
|
92 | 101 | response = instrument.request( |
93 | 102 | 1, |
|
0 commit comments