From e1247467e56902790db6e80fd070b9bd5b0a517c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Gru=CC=88ndger?= Date: Sat, 30 Sep 2017 19:22:15 +0200 Subject: [PATCH] Added test for receiver OGNSDR --- ogn/parser/parse.py | 4 +-- ogn/parser/parse_receiver.py | 7 +++-- tests/parser/test_parse_aprs.py | 2 +- tests/parser/test_parse_receiver.py | 41 +++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 tests/parser/test_parse_receiver.py diff --git a/ogn/parser/parse.py b/ogn/parser/parse.py index 9d03db9..ca80249 100644 --- a/ogn/parser/parse.py +++ b/ogn/parser/parse.py @@ -45,7 +45,7 @@ def parse_aprs(message, reference_date=None, reference_time=None): 'track': int(match_position.group('course')) if match_position.group('course_extension') else None, 'ground_speed': int(match_position.group('ground_speed')) * kts2kmh if match_position.group('ground_speed') else None, 'altitude': int(match_position.group('altitude')) * feet2m, - 'comment': match_position.group('comment'), + 'comment': match_position.group('comment') if match_position.group('comment') else "", 'aprs_type': 'position'} match_status = re.search(PATTERN_APRS_STATUS, message) @@ -54,7 +54,7 @@ def parse_aprs(message, reference_date=None, reference_time=None): 'dstcall': match_status.group('dstcall'), 'receiver_name': match_status.group('receiver'), 'timestamp': createTimestamp(match_status.group('time'), reference_date, reference_time), - 'comment': match_status.group('comment'), + 'comment': match_status.group('comment') if match_status.group('comment') else "", 'aprs_type': 'status'} raise AprsParseError(message) diff --git a/ogn/parser/parse_receiver.py b/ogn/parser/parse_receiver.py index ab919ee..97ce78b 100644 --- a/ogn/parser/parse_receiver.py +++ b/ogn/parser/parse_receiver.py @@ -4,8 +4,11 @@ from ogn.parser.pattern import PATTERN_RECEIVER_POSITION, PATTERN_RECEIVER_STATU def parse_position(aprs_comment): - match = re.search(PATTERN_RECEIVER_POSITION, aprs_comment) - return {'user_comment': match.group('user_comment') if match.group('user_comment') else None} + if aprs_comment is None: + return {} + else: + match = re.search(PATTERN_RECEIVER_POSITION, aprs_comment) + return {'user_comment': match.group('user_comment') if match.group('user_comment') else None} def parse_status(aprs_comment): diff --git a/tests/parser/test_parse_aprs.py b/tests/parser/test_parse_aprs.py index 61e52b4..89f962c 100644 --- a/tests/parser/test_parse_aprs.py +++ b/tests/parser/test_parse_aprs.py @@ -55,7 +55,7 @@ class TestStringMethods(unittest.TestCase): raw_message = "Ulrichamn>APRS,TCPIP*,qAC,GLIDERN1:/085616h5747.30NI01324.77E&/A=001322" message = parse_aprs(raw_message, reference_date=datetime(2015, 1, 1, 8, 56, 0)) - self.assertEqual(message['comment'], None) + self.assertEqual(message['comment'], '') def test_v026_relay(self): # beacons can be relayed diff --git a/tests/parser/test_parse_receiver.py b/tests/parser/test_parse_receiver.py new file mode 100644 index 0000000..5e33ca9 --- /dev/null +++ b/tests/parser/test_parse_receiver.py @@ -0,0 +1,41 @@ +import unittest + +from ogn.parser.parse_receiver import parse_position, parse_status + + +class TestStringMethods(unittest.TestCase): + def test_position(self): + message = parse_position("Antenna: chinese, on a pylon, 20 meter above ground") + + self.assertEqual(message['user_comment'], "Antenna: chinese, on a pylon, 20 meter above ground") + + def test_position_empty(self): + message = parse_position("") + + self.assertIsNotNone(message) + + def test_status(self): + message = parse_status("v0.2.7.RPI-GPU CPU:0.7 RAM:770.2/968.2MB NTP:1.8ms/-3.3ppm +55.7C 7/8Acfts[1h] RF:+54-1.1ppm/-0.16dB/+7.1dB@10km[19481]/+16.8dB@10km[7/13]") + + self.assertEqual(message['version'], "0.2.7") + self.assertEqual(message['platform'], 'RPI-GPU') + self.assertEqual(message['cpu_load'], 0.7) + self.assertEqual(message['free_ram'], 770.2) + self.assertEqual(message['total_ram'], 968.2) + self.assertEqual(message['ntp_error'], 1.8) + self.assertEqual(message['rt_crystal_correction'], -3.3) + self.assertEqual(message['cpu_temp'], 55.7) + self.assertEqual(message['senders_visible'], 7) + self.assertEqual(message['senders_total'], 8) + self.assertEqual(message['rec_crystal_correction'], 54) + self.assertEqual(message['rec_crystal_correction_fine'], -1.1) + self.assertEqual(message['rec_input_noise'], -0.16) + self.assertEqual(message['senders_signal'], 7.1) + self.assertEqual(message['senders_messages'], 19481) + self.assertEqual(message['good_senders_signal'], 16.8) + self.assertEqual(message['good_senders'], 7) + self.assertEqual(message['good_and_bad_senders'], 13) + + +if __name__ == '__main__': + unittest.main()