|
| 1 | +import unittest |
| 2 | + |
| 3 | +from aprslib.parsing import parse_position |
| 4 | + |
| 5 | +wind_multiplier = 0.44704 |
| 6 | +mm_multiplier = 0.254 |
| 7 | + |
| 8 | +class ParsePositionDataExtAndWeather(unittest.TestCase): |
| 9 | + def setUp(self): |
| 10 | + self.maxDiff = None |
| 11 | + |
| 12 | + def test_position_packet_only_weather_valid(self): |
| 13 | + packet_type = '@' |
| 14 | + packet = "092345z4903.50N/07201.75W_g000t066r000p000...dUII" |
| 15 | + expected = { |
| 16 | + 'messagecapable': True, |
| 17 | + 'raw_timestamp': '092345z', |
| 18 | + 'timestamp': 1657410300, |
| 19 | + 'format': 'uncompressed', |
| 20 | + 'posambiguity': 0, |
| 21 | + 'symbol': '_', |
| 22 | + 'symbol_table': '/', |
| 23 | + 'latitude': 49.05833333333333, |
| 24 | + 'longitude': -72.02916666666667, |
| 25 | + 'comment': '...dUII', |
| 26 | + 'weather': { |
| 27 | + 'wind_gust': 0.0, |
| 28 | + 'temperature': 18.88888888888889, |
| 29 | + 'rain_1h': 0.0, |
| 30 | + 'rain_24h': 0.0 |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + _, result = parse_position(packet_type, packet) |
| 35 | + self.assertEqual(expected, result) |
| 36 | + |
| 37 | + def test_position_packet_data_ext_and_weather_valid(self): |
| 38 | + packet_type = '@' |
| 39 | + packet = "092345z4903.50N/07201.75W_090/001g000t066r000p000...dUII" |
| 40 | + expected = { |
| 41 | + 'messagecapable': True, |
| 42 | + 'raw_timestamp': '092345z', |
| 43 | + 'timestamp': 1657410300, |
| 44 | + 'format': 'uncompressed', |
| 45 | + 'posambiguity': 0, |
| 46 | + 'symbol': '_', |
| 47 | + 'symbol_table': '/', |
| 48 | + 'latitude': 49.05833333333333, |
| 49 | + 'longitude': -72.02916666666667, |
| 50 | + 'course': 90, |
| 51 | + 'speed': 1*1.852, |
| 52 | + 'comment': '...dUII', |
| 53 | + 'weather': { |
| 54 | + 'wind_gust': 0.0, |
| 55 | + 'temperature': 18.88888888888889, |
| 56 | + 'rain_1h': 0.0, |
| 57 | + 'rain_24h': 0.0 |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + _, result = parse_position(packet_type, packet) |
| 62 | + self.assertEqual(expected, result) |
| 63 | + |
| 64 | + def test_position_packet_optional_speed(self): |
| 65 | + packet_type = '@' |
| 66 | + packet = "092345z4903.50N/07201.75W_090/...g000t066r000p000...dUII" |
| 67 | + expected = { |
| 68 | + 'messagecapable': True, |
| 69 | + 'raw_timestamp': '092345z', |
| 70 | + 'timestamp': 1657410300, |
| 71 | + 'format': 'uncompressed', |
| 72 | + 'posambiguity': 0, |
| 73 | + 'symbol': '_', |
| 74 | + 'symbol_table': '/', |
| 75 | + 'latitude': 49.05833333333333, |
| 76 | + 'longitude': -72.02916666666667, |
| 77 | + 'course': 90, |
| 78 | + 'comment': '...dUII', |
| 79 | + 'weather': { |
| 80 | + 'wind_gust': 0.0, |
| 81 | + 'temperature': 18.88888888888889, |
| 82 | + 'rain_1h': 0.0, |
| 83 | + 'rain_24h': 0.0 |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + _, result = parse_position(packet_type, packet) |
| 88 | + self.assertEqual(expected, result) |
| 89 | + |
| 90 | + def test_position_packet_optional_course(self): |
| 91 | + packet_type = '@' |
| 92 | + packet = "092345z4903.50N/07201.75W_ /001g000t066r000p000...dUII" |
| 93 | + expected = { |
| 94 | + 'messagecapable': True, |
| 95 | + 'raw_timestamp': '092345z', |
| 96 | + 'timestamp': 1657410300, |
| 97 | + 'format': 'uncompressed', |
| 98 | + 'posambiguity': 0, |
| 99 | + 'symbol': '_', |
| 100 | + 'symbol_table': '/', |
| 101 | + 'latitude': 49.05833333333333, |
| 102 | + 'longitude': -72.02916666666667, |
| 103 | + 'speed': 1*1.852, |
| 104 | + 'comment': '...dUII', |
| 105 | + 'weather': { |
| 106 | + 'wind_gust': 0.0, |
| 107 | + 'temperature': 18.88888888888889, |
| 108 | + 'rain_1h': 0.0, |
| 109 | + 'rain_24h': 0.0 |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + _, result = parse_position(packet_type, packet) |
| 114 | + self.assertEqual(expected, result) |
| 115 | + |
| 116 | + def test_position_packet_optional_speed_and_course(self): |
| 117 | + packet_type = '@' |
| 118 | + packet = "092345z4903.50N/07201.75W_.../...g000t066r000p000...dUII" |
| 119 | + expected = { |
| 120 | + 'messagecapable': True, |
| 121 | + 'raw_timestamp': '092345z', |
| 122 | + 'timestamp': 1657410300, |
| 123 | + 'format': 'uncompressed', |
| 124 | + 'posambiguity': 0, |
| 125 | + 'symbol': '_', |
| 126 | + 'symbol_table': '/', |
| 127 | + 'latitude': 49.05833333333333, |
| 128 | + 'longitude': -72.02916666666667, |
| 129 | + 'comment': '...dUII', |
| 130 | + 'weather': { |
| 131 | + 'wind_gust': 0.0, |
| 132 | + 'temperature': 18.88888888888889, |
| 133 | + 'rain_1h': 0.0, |
| 134 | + 'rain_24h': 0.0 |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + _, result = parse_position(packet_type, packet) |
| 139 | + self.assertEqual(expected, result) |
| 140 | + def test_position_packet_optional_course(self): |
| 141 | + packet_type = '@' |
| 142 | + packet = "092345z4903.50N/07201.75W_ /001g000t066r000p000...dUII" |
| 143 | + expected = { |
| 144 | + 'messagecapable': True, |
| 145 | + 'raw_timestamp': '092345z', |
| 146 | + 'timestamp': 1657410300, |
| 147 | + 'format': 'uncompressed', |
| 148 | + 'posambiguity': 0, |
| 149 | + 'symbol': '_', |
| 150 | + 'symbol_table': '/', |
| 151 | + 'latitude': 49.05833333333333, |
| 152 | + 'longitude': -72.02916666666667, |
| 153 | + 'speed': 1*1.852, |
| 154 | + 'comment': '...dUII', |
| 155 | + 'weather': { |
| 156 | + 'wind_gust': 0.0, |
| 157 | + 'temperature': 18.88888888888889, |
| 158 | + 'rain_1h': 0.0, |
| 159 | + 'rain_24h': 0.0 |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + _, result = parse_position(packet_type, packet) |
| 164 | + self.assertEqual(expected, result) |
| 165 | + |
| 166 | +if __name__ == '__main__': |
| 167 | + unittest.main() |
0 commit comments