Skip to content

Commit 1e7e7b9

Browse files
committed
WIP add more tests
1 parent 0fef25a commit 1e7e7b9

File tree

2 files changed

+95
-2
lines changed

2 files changed

+95
-2
lines changed

.coveragerc

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
plugins = covdefaults
66

77
[report]
8-
fail_under = 1
8+
fail_under = 31

tests/adafruit_gps_test.py

+94-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# pylint: disable=missing-function-docstring,missing-module-docstring
1+
# pylint: disable=missing-function-docstring,missing-module-docstring,invalid-name
22

33
# SPDX-FileCopyrightText: 2021 Jonas Kittner
44
#
@@ -10,6 +10,7 @@
1010
from adafruit_gps import _parse_float
1111
from adafruit_gps import _read_degrees
1212
from adafruit_gps import _parse_talker
13+
from adafruit_gps import _parse_data
1314

1415

1516
@pytest.mark.parametrize(
@@ -65,9 +66,101 @@ def test_read_degrees(data, neg, exp):
6566
assert _read_degrees(data, 0, neg) == exp
6667

6768

69+
@pytest.mark.xfail(reason="bug is not fixed yet")
6870
def test_parse_talker_prop_code():
6971
assert _parse_talker(b"PMTK001") == (b"P", b"MTK001")
7072

7173

7274
def test_parse_talker_regular():
7375
assert _parse_talker(b"GPRMC") == (b"GP", b"RMC")
76+
77+
78+
@pytest.mark.parametrize(
79+
"st",
80+
(-1, 10),
81+
)
82+
def test_parse_data_unknown_sentence_type(st):
83+
assert _parse_data(st, data=[]) is None
84+
85+
86+
def test_param_types_does_not_match_data_items():
87+
assert _parse_data(sentence_type=1, data=["too", "few"]) is None
88+
89+
90+
@pytest.mark.parametrize(
91+
("st", "data", "exp_data"),
92+
(
93+
# (0, 1, 2, 3, 4, 5, 6, 7, 8, 9),
94+
pytest.param(
95+
1,
96+
[
97+
"203855.000",
98+
"A",
99+
"2747.4161",
100+
"S",
101+
"15303.4057",
102+
"E",
103+
"0.10",
104+
"242.84",
105+
"280921",
106+
"",
107+
"",
108+
"A",
109+
],
110+
[
111+
203855.0,
112+
"A",
113+
27.79027,
114+
"S",
115+
153.0568,
116+
"E",
117+
0.10,
118+
242.84,
119+
280921,
120+
None,
121+
None,
122+
"A",
123+
],
124+
id="RMC",
125+
),
126+
pytest.param(
127+
2,
128+
[
129+
"203855.000",
130+
"2747.4161",
131+
"S",
132+
"15303.4057",
133+
"E",
134+
"1",
135+
"07",
136+
"1.91",
137+
"-46.2",
138+
"M",
139+
"47.4",
140+
"M",
141+
"",
142+
"",
143+
],
144+
[
145+
203855.0,
146+
27.79027,
147+
"S",
148+
153.0568,
149+
"E",
150+
1,
151+
7,
152+
1.91,
153+
-46.2,
154+
"M",
155+
47.4,
156+
"M",
157+
None,
158+
None,
159+
],
160+
id="GGA",
161+
),
162+
# TODO: test for all other sentence types
163+
),
164+
)
165+
def test_parse_data(st, data, exp_data):
166+
assert pytest.approx(_parse_data(sentence_type=st, data=data)) == exp_data

0 commit comments

Comments
 (0)