From 2e22a3c9851b6b1c38bac25a4ea2b87229ed5bc2 Mon Sep 17 00:00:00 2001 From: Bill Mitchell Date: Tue, 1 May 2018 12:03:18 -0500 Subject: [PATCH] Updated testing to include third-party packets --- tests/test_parse.py | 2 +- tests/test_thirdparty.py | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/test_thirdparty.py diff --git a/tests/test_parse.py b/tests/test_parse.py index 4974f8d..62ce882 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -66,7 +66,7 @@ class ParseTestCase(unittest.TestCase): def test_unsupported_formats_raising(self): with self.assertRaises(UnknownFormat): - for packet_type in '#$%)*,B:%saaa" % packet_type try: diff --git a/tests/test_thirdparty.py b/tests/test_thirdparty.py new file mode 100644 index 0000000..80a9342 --- /dev/null +++ b/tests/test_thirdparty.py @@ -0,0 +1,58 @@ + +import unittest2 as unittest + +from aprslib import parse +from aprslib.exceptions import ParseError, UnknownFormat + + +class thirdpartyTC(unittest.TestCase): + def test_empty_subpacket(self): + self.assertRaises(ParseError, parse, "A>B:}") + + def test_no_body(self): + self.assertRaises(ParseError, parse, "A>B:}C>D") + + def test_empty_body(self): + self.assertRaises(ParseError, parse, "A>B:}C>D:") + + def testparse_header_exception(self): + self.assertRaises(ParseError, parse, "A>B:}C:asd") + + def test_empty_body_of_format_that_is_not_status(self): + self.assertRaises(ParseError, parse, "A>B:}C>D:!") + + try: + parse("A>B:}C>D:>") + except: + self.fail("empty status packet shouldn't raise exception") + + def test_unsupported_formats_raising(self): + with self.assertRaises(UnknownFormat): + for packet_type in '#$%)*,B:}C>D:%saaa" % packet_type + + try: + parse(packet) + except UnknownFormat as exp: + self.assertEqual(exp.packet, packet) + raise + + def test_valid_thirdparty_msg(self): + packet = "A-1>APRS,B-2,WIDE1*:}C>APU25N,TCPIP,A-1*::DEF :ack56" + result = parse(packet) + self.assertEqual(result['via'],'') + self.assertEqual(result['to'],'APRS') + self.assertEqual(result['from'],'A-1') + self.assertEqual(result['format'],'thirdparty') + self.assertEqual(result['raw'],packet) + self.assertEqual(result['path'],['B-2', 'WIDE1*']) + self.assertEqual(result['subpacket']['raw'],packet[21:]) + self.assertEqual(result['subpacket']['via'],'') + self.assertEqual(result['subpacket']['msgNo'],'56') + self.assertEqual(result['subpacket']['from'],'C') + self.assertEqual(result['subpacket']['path'],['TCPIP', 'A-1*']) + self.assertEqual(result['subpacket']['response'],'ack') + self.assertEqual(result['subpacket']['format'],'message') + self.assertEqual(result['subpacket']['to'],'APU25N') + self.assertEqual(result['subpacket']['addresse'],'DEF') +