diff --git a/tests/test_kiss.py b/tests/test_kiss.py new file mode 100644 index 0000000000000000000000000000000000000000..d4dfb979e75f8eb60c668e187bd2307389c260bb --- /dev/null +++ b/tests/test_kiss.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +"""Tests for KISS Util Module.""" + +__author__ = 'Jeffrey Phillips Freeman WI2ARD <freemo@gmail.com>' +__license__ = 'Apache License, Version 2.0' +__copyright__ = 'Copyright 2016, Syncleus, Inc. and contributors' + +import sys +import unittest + +from . import constants + +import apex +import apex.kiss.constants +import apex.kiss.util + + +# pylint: disable=R0904,C0103 +class KISSUtilTestCase(unittest.TestCase): + + """Test class for KISS Python Module.""" + + # All other tests only work on python2 + if sys.version_info < (3, 0): + def setUp(self): + """Setup.""" + self.test_frames = open(constants.TEST_FRAMES, 'r') + self.test_frame = self.test_frames.readlines()[0].strip() + + def tearDown(self): + """Teardown.""" + self.test_frames.close() + + def test_escape_special_codes_fend(self): + """ + Tests `kiss.util.escape_special_codes` util function. + """ + # fend = apex.kiss.util.escape_special_codes(apex.kiss.constants.FEND) + fend = apex.kiss.Kiss._Kiss__escape_special_codes([apex.kiss.constants.FEND]) + self.assertEqual(fend, apex.kiss.constants.FESC_TFEND) + + def test_escape_special_codes_fesc(self): + """ + Tests `kiss.util.escape_special_codes` util function. + """ + fesc = apex.kiss.Kiss._Kiss__escape_special_codes([apex.kiss.constants.FESC]) + self.assertEqual(fesc, apex.kiss.constants.FESC_TFESC) + + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_kiss_util.py b/tests/test_kiss_util.py index 6e32ba2313938a7972e78039cdc51ffe189b1848..1940226db0a1434e1b345fdca2aa9f54efa28114 100644 --- a/tests/test_kiss_util.py +++ b/tests/test_kiss_util.py @@ -7,7 +7,7 @@ __author__ = 'Jeffrey Phillips Freeman WI2ARD <freemo@gmail.com>' __license__ = 'Apache License, Version 2.0' __copyright__ = 'Copyright 2016, Syncleus, Inc. and contributors' - +import sys import unittest from . import constants @@ -31,20 +31,8 @@ class KISSUtilTestCase(unittest.TestCase): """Teardown.""" self.test_frames.close() - # def test_escape_special_codes_fend(self): - # """ - # Tests `kiss.util.escape_special_codes` util function. - # """ - # fend = apex.kiss.util.escape_special_codes(apex.kiss.constants.FEND) - # self.assertEqual(fend, apex.kiss.constants.FESC_TFEND) - # - # def test_escape_special_codes_fesc(self): - # """ - # Tests `kiss.util.escape_special_codes` util function. - # """ - # fesc = apex.kiss.util.escape_special_codes(apex.kiss.constants.FESC) - # self.assertEqual(fesc, apex.kiss.constants.FESC_TFESC) - # + # # All other tests only work on python2 + # # if sys.version_info < (3, 0): # def test_extract_ui(self): # """ # Tests `kiss.util.extract_ui` util function. diff --git a/tests/test_util.py b/tests/test_util.py index fd8790b16dfa36a4d4c85c5992816f71a10a5d8c..c712a24213494435a05104efb4042e7617648913 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -8,6 +8,7 @@ __license__ = 'Apache License, Version 2.0' __copyright__ = 'Copyright 2016, Syncleus, Inc. and contributors' +import sys import unittest import logging import logging.handlers @@ -40,15 +41,6 @@ class APRSUtilTestCase(unittest.TestCase): # pylint: disable=R0904 logger.addHandler(console_handler) logger.propagate = False - # def setUp(self): # pylint: disable=C0103 - # """Setup.""" - # self.test_frames = open(constants.TEST_FRAMES, 'r') - # self.test_frame = self.test_frames.readlines()[0].strip() - - # def tearDown(self): # pylint: disable=C0103 - # """Teardown.""" - # self.test_frames.close() - def test_latitude_north(self): """Test Decimal to APRS Latitude conversion. @@ -193,64 +185,6 @@ class APRSUtilTestCase(unittest.TestCase): # pylint: disable=R0904 self.assertFalse( apex.aprs.util.valid_callsign(i), "%s is an invalid call" % i) - # def test_extract_callsign_source(self): - # """ - # Tests extracting the source callsign from a KISS-encoded APRS frame - # using `aprs.util.extract_callsign()`. - # """ - # callsign = {'callsign': 'W2GMD', 'ssid': 6} - # extracted_callsign = apex.aprs.util.extract_callsign(self.test_frame[7:]) - # self.assertEqual(callsign, extracted_callsign) - # - # def test_extract_callsign_dest(self): - # """ - # Tests extracting the destination callsign from a KISS-encoded APRS - # frame using `aprs.util.extract_callsign()`. - # """ - # extracted_callsign = apex.aprs.util.extract_callsign(self.test_frame) - # self.assertEqual(extracted_callsign['callsign'], 'APRX24') - - # def test_full_callsign_with_ssid(self): - # """ - # Tests creating a full callsign string from a callsign+ssid dict using - # `aprs.util.full_callsign()`. - # """ - # callsign = { - # 'callsign': 'W2GMD', - # 'ssid': 1 - # } - # full_callsign = apex.aprs.util.full_callsign(callsign) - # self.assertEqual(full_callsign, 'W2GMD-1') - # - # def test_full_callsign_sans_ssid(self): - # """ - # Tests creating a full callsign string from a callsign dict using - # `aprs.util.full_callsign()`. - # """ - # callsign = { - # 'callsign': 'W2GMD', - # 'ssid': 0 - # } - # full_callsign = apex.aprs.util.full_callsign(callsign) - # self.assertEqual(full_callsign, 'W2GMD') - - # def test_format_aprs_frame(self): - # """ - # Tests formatting an APRS frame-as-string from an APRS frame-as-dict - # using `aprs.util.format_aprs_frame()`. - # """ - # frame = { - # 'source': 'W2GMD-1', - # 'destination': 'OMG', - # 'path': 'WIDE1-1', - # 'text': 'test_format_aprs_frame' - # } - # formatted_frame = apex.aprs.util.format_aprs_frame(frame) - # self.assertEqual( - # formatted_frame, - # 'W2GMD-1>OMG,WIDE1-1:test_format_aprs_frame' - # ) - def test_decode_aprs_ascii_frame(self): """ Tests creating an APRS frame-as-dict from an APRS frame-as-string @@ -271,102 +205,171 @@ class APRSUtilTestCase(unittest.TestCase): # pylint: disable=R0904 frame ) - # def test_extract_path(self): - # """ - # Tests extracting the APRS path from a KISS-encoded frame - # using `aprs.util.extract_path()`. - # """ - # extracted_path = apex.aprs.util.extract_path(3, self.test_frame) - # self.assertEqual('WIDE1-1', extracted_path[0]) - - # def test_format_path(self): - # """ - # Tests formatting an APRS path from a KISS-encoded frame - # using `aprs.util.format_path()`. - # """ - # extracted_path = apex.aprs.util.format_path(3, self.test_frame) - # self.assertEqual('WIDE1-1', extracted_path) - - # def test_encode_frame(self): - # """ - # Tests KISS-encoding an APRS frame using - # `aprs.util.encode_frame()`. - # """ - # frame = { - # 'source': 'W2GMD-1', - # 'destination': 'OMG', - # 'path': 'WIDE1-1', - # 'text': 'test_encode_frame' - # } - # encoded_frame = apex.aprs.util.encode_frame(frame) - # legit = ('\x9e\x9a\x8e@@@`\xaed\x8e\x9a\x88@b' - # '\xae\x92\x88\x8ab@c\x03\xf0test_encode_frame') - # self.assertEqual(legit, encoded_frame) - # - # def test_decode_frame_recorded(self): - # """ - # Tests decoding a KISS-encoded APRS frame using - # `aprs.util.decode_frame()`. - # """ - # frame = { - # 'path': 'WIDE1-1', - # 'destination': 'APRX24', - # 'source': 'W2GMD-6', - # 'text': ('!3745.75NI12228.05W#W2GMD-6 Inner Sunset, ' - # 'SF iGate/Digipeater http://w2gmd.org') - # } - # self.assertEqual(frame, apex.aprs.util.decode_frame(self.test_frame)) - # - # def test_decode_frame(self): - # """ - # Tests decoding a KISS-encoded APRS frame using - # `aprs.util.decode_frame()`. - # """ - # frame = { - # 'source': 'W2GMD-1', - # 'destination': 'OMG', - # 'path': 'WIDE1-1,WIDE2-2', - # 'text': 'test_encode_frame' - # } - # encoded_frame = apex.aprs.util.encode_frame(frame) - # decoded_frame = apex.aprs.util.decode_frame(encoded_frame) - # self.assertEqual(frame, decoded_frame) - # - # def test_create_callsign(self): - # """ - # Tests creating a callsign string from a callsign dict using - # `aprs.util.create_callsign()`. - # """ - # full_callsign = 'W2GMD-1' - # callsign = apex.aprs.util.create_callsign(full_callsign) - # self.assertEqual({'callsign': 'W2GMD', 'ssid': 1}, callsign) - # - # def test_full_callsign(self): - # """ - # Tests converting a callsign dict to a callsing string - # (callsign-ssid) using `aprs.util.full_callsign()`. - # """ - # callsign = {'callsign': 'W2GMD', 'ssid': 1} - # full_callsign = apex.aprs.util.full_callsign(callsign) - # self.assertEqual('W2GMD-1', full_callsign) + # All other tests only work on python2 + # if sys.version_info < (3, 0): + # def setUp(self): # pylint: disable=C0103 + # """Setup.""" + # self.test_frames = open(constants.TEST_FRAMES, 'r') + # self.test_frame = self.test_frames.readlines()[0].strip() # - # def test_encode_callsign_digipeated(self): - # """ - # Tests encoding a digipeated callsign with - # `aprs.util.encode_callsign()`. - # """ - # callsign = {'callsign': 'W2GMD*', 'ssid': 1} - # encoded_callsign = apex.aprs.util.encode_callsign(callsign) - # self.assertEqual('\xaed\x8e\x9a\x88@\xe2', encoded_callsign) + # def tearDown(self): # pylint: disable=C0103 + # """Teardown.""" + # self.test_frames.close() # - # def test_encode_callsign(self): - # """ - # Tests encoding a non-digipeated callsign with - # `aprs.util.encode_callsign()`. - # """ - # callsign = {'callsign': 'W2GMD', 'ssid': 1} - # encoded_callsign = apex.aprs.util.encode_callsign(callsign) - # self.assertEqual('\xaed\x8e\x9a\x88@b', encoded_callsign) + # def test_format_aprs_frame(self): + # """ + # Tests formatting an APRS frame-as-string from an APRS frame-as-dict + # using `aprs.util.format_aprs_frame()`. + # """ + # frame = { + # 'source': 'W2GMD-1', + # 'destination': 'OMG', + # 'path': 'WIDE1-1', + # 'text': 'test_format_aprs_frame' + # } + # formatted_frame = apex.aprs.util.format_aprs_frame(frame) + # self.assertEqual( + # formatted_frame, + # 'W2GMD-1>OMG,WIDE1-1:test_format_aprs_frame' + # ) + + # def test_extract_callsign_source(self): + # """ + # Tests extracting the source callsign from a KISS-encoded APRS frame + # using `aprs.util.extract_callsign()`. + # """ + # callsign = {'callsign': 'W2GMD', 'ssid': 6} + # extracted_callsign = apex.aprs.util.extract_callsign(self.test_frame[7:]) + # self.assertEqual(callsign, extracted_callsign) + # + # def test_extract_callsign_dest(self): + # """ + # Tests extracting the destination callsign from a KISS-encoded APRS + # frame using `aprs.util.extract_callsign()`. + # """ + # extracted_callsign = apex.aprs.util.extract_callsign(self.test_frame) + # self.assertEqual(extracted_callsign['callsign'], 'APRX24') + # + # def test_full_callsign_with_ssid(self): + # """ + # Tests creating a full callsign string from a callsign+ssid dict using + # `aprs.util.full_callsign()`. + # """ + # callsign = { + # 'callsign': 'W2GMD', + # 'ssid': 1 + # } + # full_callsign = apex.aprs.util.full_callsign(callsign) + # self.assertEqual(full_callsign, 'W2GMD-1') + # + # def test_full_callsign_sans_ssid(self): + # """ + # Tests creating a full callsign string from a callsign dict using + # `aprs.util.full_callsign()`. + # """ + # callsign = { + # 'callsign': 'W2GMD', + # 'ssid': 0 + # } + # full_callsign = apex.aprs.util.full_callsign(callsign) + # self.assertEqual(full_callsign, 'W2GMD') + # + # def test_extract_path(self): + # """ + # Tests extracting the APRS path from a KISS-encoded frame + # using `aprs.util.extract_path()`. + # """ + # extracted_path = apex.aprs.util.extract_path(3, self.test_frame) + # self.assertEqual('WIDE1-1', extracted_path[0]) + # + # def test_format_path(self): + # """ + # Tests formatting an APRS path from a KISS-encoded frame + # using `aprs.util.format_path()`. + # """ + # extracted_path = apex.aprs.util.format_path(3, self.test_frame) + # self.assertEqual('WIDE1-1', extracted_path) + # + # def test_encode_frame(self): + # """ + # Tests KISS-encoding an APRS frame using + # `aprs.util.encode_frame()`. + # """ + # frame = { + # 'source': 'W2GMD-1', + # 'destination': 'OMG', + # 'path': 'WIDE1-1', + # 'text': 'test_encode_frame' + # } + # encoded_frame = apex.aprs.util.encode_frame(frame) + # legit = ('\x9e\x9a\x8e@@@`\xaed\x8e\x9a\x88@b' + # '\xae\x92\x88\x8ab@c\x03\xf0test_encode_frame') + # self.assertEqual(legit, encoded_frame) + # + # def test_decode_frame_recorded(self): + # """ + # Tests decoding a KISS-encoded APRS frame using + # `aprs.util.decode_frame()`. + # """ + # frame = { + # 'path': 'WIDE1-1', + # 'destination': 'APRX24', + # 'source': 'W2GMD-6', + # 'text': ('!3745.75NI12228.05W#W2GMD-6 Inner Sunset, ' + # 'SF iGate/Digipeater http://w2gmd.org') + # } + # self.assertEqual(frame, apex.aprs.util.decode_frame(self.test_frame)) + # + # def test_decode_frame(self): + # """ + # Tests decoding a KISS-encoded APRS frame using + # `aprs.util.decode_frame()`. + # """ + # frame = { + # 'source': 'W2GMD-1', + # 'destination': 'OMG', + # 'path': 'WIDE1-1,WIDE2-2', + # 'text': 'test_encode_frame' + # } + # encoded_frame = apex.aprs.util.encode_frame(frame) + # decoded_frame = apex.aprs.util.decode_frame(encoded_frame) + # self.assertEqual(frame, decoded_frame) + # + # def test_create_callsign(self): + # """ + # Tests creating a callsign string from a callsign dict using + # `aprs.util.create_callsign()`. + # """ + # full_callsign = 'W2GMD-1' + # callsign = apex.aprs.util.create_callsign(full_callsign) + # self.assertEqual({'callsign': 'W2GMD', 'ssid': 1}, callsign) + # + # def test_full_callsign(self): + # """ + # Tests converting a callsign dict to a callsing string + # (callsign-ssid) using `aprs.util.full_callsign()`. + # """ + # callsign = {'callsign': 'W2GMD', 'ssid': 1} + # full_callsign = apex.aprs.util.full_callsign(callsign) + # self.assertEqual('W2GMD-1', full_callsign) + # + # def test_encode_callsign_digipeated(self): + # """ + # Tests encoding a digipeated callsign with + # `aprs.util.encode_callsign()`. + # """ + # callsign = {'callsign': 'W2GMD*', 'ssid': 1} + # encoded_callsign = apex.aprs.util.encode_callsign(callsign) + # self.assertEqual('\xaed\x8e\x9a\x88@\xe2', encoded_callsign) + # + # def test_encode_callsign(self): + # """ + # Tests encoding a non-digipeated callsign with + # `aprs.util.encode_callsign()`. + # """ + # callsign = {'callsign': 'W2GMD', 'ssid': 1} + # encoded_callsign = apex.aprs.util.encode_callsign(callsign) + # self.assertEqual('\xaed\x8e\x9a\x88@b', encoded_callsign) if __name__ == '__main__':