ogn-python/tests/test_aprs_parser.py

39 wiersze
1.3 KiB
Python
Czysty Zwykły widok Historia

2015-10-24 21:13:21 +00:00
import unittest
from datetime import datetime
2015-10-24 21:13:21 +00:00
from ogn.aprs_parser import parse_aprs
2015-11-19 22:17:12 +00:00
from ogn.exceptions import AprsParseError, OgnParseError
2015-10-24 21:13:21 +00:00
class TestStringMethods(unittest.TestCase):
2015-12-08 21:44:39 +00:00
def test_valid_beacons(self):
with open('tests/valid_beacons.txt') as f:
for line in f:
parse_aprs(line, datetime(2015, 4, 10, 17, 0))
2015-10-24 21:13:21 +00:00
2015-10-24 21:57:31 +00:00
def test_fail_none(self):
2015-11-19 22:17:12 +00:00
with self.assertRaises(TypeError):
2015-10-24 21:57:31 +00:00
parse_aprs(None)
2015-10-24 21:44:07 +00:00
def test_fail_empty(self):
2015-11-19 22:17:12 +00:00
with self.assertRaises(AprsParseError):
2015-10-24 21:44:07 +00:00
parse_aprs("")
2015-11-19 22:17:12 +00:00
def test_fail_bad_string(self):
with self.assertRaises(AprsParseError):
parse_aprs("Lachens>APRS,TCPIwontbeavalidstring")
2015-12-08 21:44:39 +00:00
def test_incomplete_device_string(self):
2015-11-19 22:17:12 +00:00
with self.assertRaises(OgnParseError):
parse_aprs("ICA4B0E3A>APRS,qAS,Letzi:/072319h4711.75N\\00802.59E^327/149/A=006498 id154B0E3A -395",
datetime(2015, 4, 10, 7, 24))
2015-11-19 22:17:12 +00:00
2015-12-08 21:44:39 +00:00
def test_incomplete_receiver_string(self):
2015-11-19 22:17:12 +00:00
with self.assertRaises(OgnParseError):
parse_aprs("Lachens>APRS,TCPIP*,qAC,GLIDERN2:/165334h4344.70NI00639.19E&/A=005435 v0.2.1 CPU:0.3 RAM:1764.4/21",
datetime(2015, 4, 10, 16, 54))
2015-11-19 22:17:12 +00:00
2015-10-24 21:13:21 +00:00
if __name__ == '__main__':
unittest.main()