|
1 |
| -# pylint: disable=missing-function-docstring,missing-module-docstring |
| 1 | +# pylint: disable=missing-function-docstring,missing-module-docstring,invalid-name |
2 | 2 |
|
3 | 3 | # SPDX-FileCopyrightText: 2021 Jonas Kittner
|
4 | 4 | #
|
|
10 | 10 | from adafruit_gps import _parse_float
|
11 | 11 | from adafruit_gps import _read_degrees
|
12 | 12 | from adafruit_gps import _parse_talker
|
| 13 | +from adafruit_gps import _parse_data |
13 | 14 |
|
14 | 15 |
|
15 | 16 | @pytest.mark.parametrize(
|
@@ -65,9 +66,101 @@ def test_read_degrees(data, neg, exp):
|
65 | 66 | assert _read_degrees(data, 0, neg) == exp
|
66 | 67 |
|
67 | 68 |
|
| 69 | +@pytest.mark.xfail(reason="bug is not fixed yet") |
68 | 70 | def test_parse_talker_prop_code():
|
69 | 71 | assert _parse_talker(b"PMTK001") == (b"P", b"MTK001")
|
70 | 72 |
|
71 | 73 |
|
72 | 74 | def test_parse_talker_regular():
|
73 | 75 | 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