1
|
|
|
#!/usr/bin/env python |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
|
4
|
|
|
"""Tests for KISS Util Module.""" |
5
|
|
|
|
6
|
|
|
# These imports are for python3 compatibility inside python2 |
7
|
|
|
from __future__ import absolute_import |
8
|
|
|
from __future__ import division |
9
|
|
|
from __future__ import print_function |
10
|
|
|
|
11
|
|
|
import unittest |
12
|
|
|
|
13
|
|
|
import apex.kiss |
14
|
|
|
import apex.kiss.constants |
15
|
|
|
|
16
|
|
|
from .kiss_mock import KissMock |
17
|
|
|
|
18
|
|
|
__author__ = 'Jeffrey Phillips Freeman (WI2ARD)' |
19
|
|
|
__maintainer__ = 'Jeffrey Phillips Freeman (WI2ARD)' |
20
|
|
|
__email__ = '[email protected]' |
21
|
|
|
__license__ = 'Apache License, Version 2.0' |
22
|
|
|
__copyright__ = 'Copyright 2016, Syncleus, Inc. and contributors' |
23
|
|
|
__credits__ = [] |
24
|
|
|
|
25
|
|
|
# KG6WTF>S7TSUV,MTOSO-2,WIDE2*,qAR,KF6FIR-10:`17El#X-/[email protected] |
26
|
|
|
ENCODED_FRAME = [192, 0, 75, 71, 54, 87, 84, 70, 62, 83, 55, 84, 83, 85, 86, 44, 77, 84, 79, 83, 79, 45, 50, 44, 87, 73, |
27
|
|
|
68, 69, 50, 42, 44, 113, 65, 82, 44, 75, 70, 54, 70, 73, 82, 45, 49, 48, 58, 96, 49, 55, 69, 108, 35, |
28
|
|
|
88, 45, 47, 107, 103, 54, 119, 116, 102, 64, 103, 111, 115, 115, 101, 108, 105, 110, 102, 97, 109, 105, |
29
|
|
|
108, 121, 46, 99, 111, 109, 192] |
30
|
|
|
DECODED_FRAME = [75, 71, 54, 87, 84, 70, 62, 83, 55, 84, 83, 85, 86, 44, 77, 84, 79, 83, 79, 45, 50, 44, 87, 73, 68, |
31
|
|
|
69, 50, 42, 44, 113, 65, 82, 44, 75, 70, 54, 70, 73, 82, 45, 49, 48, 58, 96, 49, 55, 69, 108, 35, |
32
|
|
|
88, 45, 47, 107, 103, 54, 119, 116, 102, 64, 103, 111, 115, 115, 101, 108, 105, 110, 102, 97, 109, |
33
|
|
|
105, 108, 121, 46, 99, 111, 109] |
34
|
|
|
|
35
|
|
|
# pylint: disable=R0904,C0103 |
36
|
|
|
class KissUtilTestCase(unittest.TestCase): |
37
|
|
|
|
38
|
|
|
"""Test class for KISS Python Module.""" |
39
|
|
|
|
40
|
|
|
def setUp(self): |
41
|
|
|
"""Setup.""" |
42
|
|
|
self.kiss_mock = KissMock() |
43
|
|
|
|
44
|
|
|
def tearDown(self): |
45
|
|
|
"""Teardown.""" |
46
|
|
|
self.kiss_mock.clear_interface() |
47
|
|
|
|
48
|
|
|
def test_escape_special_codes_fend(self): |
49
|
|
|
""" |
50
|
|
|
Tests `kiss.util.escape_special_codes` util function. |
51
|
|
|
""" |
52
|
|
|
# fend = apex.kiss.util.escape_special_codes(apex.kiss.constants.FEND) |
53
|
|
|
fend = apex.kiss.Kiss._Kiss__escape_special_codes([apex.kiss.constants.FEND]) # pylint: disable=E1101 |
54
|
|
|
self.assertEqual(fend, apex.kiss.constants.FESC_TFEND) |
55
|
|
|
|
56
|
|
|
def test_escape_special_codes_fesc(self): |
57
|
|
|
""" |
58
|
|
|
Tests `kiss.util.escape_special_codes` util function. |
59
|
|
|
""" |
60
|
|
|
fesc = apex.kiss.Kiss._Kiss__escape_special_codes([apex.kiss.constants.FESC]) # pylint: disable=E1101 |
61
|
|
|
self.assertEqual(fesc, apex.kiss.constants.FESC_TFESC) |
62
|
|
|
|
63
|
|
|
def test_read(self): |
64
|
|
|
self.kiss_mock.clear_interface() |
65
|
|
|
self.kiss_mock.add_read_from_interface(ENCODED_FRAME) |
66
|
|
|
translated_frame = self.kiss_mock.read() |
67
|
|
|
self.assertEqual(DECODED_FRAME, translated_frame) |
68
|
|
|
|
69
|
|
|
def test_write(self): |
70
|
|
|
self.kiss_mock.clear_interface() |
71
|
|
|
self.kiss_mock.write(DECODED_FRAME) |
72
|
|
|
all_raw_frames = self.kiss_mock.get_sent_to_interface() |
73
|
|
|
self.assertEqual(ENCODED_FRAME, all_raw_frames[0]) |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
if __name__ == '__main__': |
77
|
|
|
unittest.main() |
78
|
|
|
|