2015-10-24 21:13:21 +00:00
|
|
|
import unittest
|
2015-12-16 17:28:03 +00:00
|
|
|
import unittest.mock as mock
|
|
|
|
|
2015-12-10 16:28:29 +00:00
|
|
|
from datetime import datetime
|
2015-12-16 17:28:03 +00:00
|
|
|
from time import sleep
|
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:
|
2015-12-10 16:28:29 +00:00
|
|
|
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):
|
2015-12-10 16:28:29 +00:00
|
|
|
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):
|
2015-12-10 16:28:29 +00:00
|
|
|
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-12-16 17:28:03 +00:00
|
|
|
@mock.patch('ogn.aprs_parser.Beacon')
|
|
|
|
def test_default_reference_date(self, beacon_mock):
|
|
|
|
instance = beacon_mock.return_value
|
|
|
|
valid_aprs_string = "Lachens>APRS,TCPIP*,qAC,GLIDERN2:/165334h4344.70NI00639.19E&/A=005435 v0.2.1 CPU:0.3 RAM:1764.4/21"
|
|
|
|
|
|
|
|
parse_aprs(valid_aprs_string)
|
|
|
|
call_args = instance.parse.call_args
|
|
|
|
sleep(1)
|
|
|
|
parse_aprs(valid_aprs_string)
|
|
|
|
call_args_one_second_later = instance.parse.call_args
|
|
|
|
|
|
|
|
self.assertNotEqual(call_args, call_args_one_second_later)
|
|
|
|
|
2015-11-19 22:17:12 +00:00
|
|
|
|
2015-10-24 21:13:21 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|