This repository was archived by the owner on Apr 23, 2025. It is now read-only.
forked from SkypLabs/python4yahdlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
70 lines (58 loc) · 2.05 KB
/
test.py
File metadata and controls
70 lines (58 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import unittest
from yahdlc import *
class TestYahdlc(unittest.TestCase):
def test_frame_data_invalid_inputs(self):
with self.assertRaises(TypeError):
frame_data(2)
with self.assertRaises(TypeError):
frame_data('test', 'test')
with self.assertRaises(TypeError):
frame_data('test', FRAME_DATA, 'test')
with self.assertRaises(ValueError):
frame_data('test', 12)
with self.assertRaises(ValueError):
frame_data('test', FRAME_DATA, 8)
def test_get_data_invalid_inputs(self):
with self.assertRaises(TypeError):
get_data(12)
with self.assertRaises(MessageError):
get_data('')
with self.assertRaises(MessageError):
get_data('test')
def test_get_data_corrupted_frame(self):
data = bytearray(frame_data('test', FRAME_DATA, 0))
data[7] ^= 0x01
data = bytes(data)
with self.assertRaises(FCSError):
try:
get_data(data)
except FCSError as e:
self.assertEqual(e.args[0], 0)
raise
data = bytearray(frame_data('test', FRAME_DATA, 2))
data[7] ^= 0x01
data = bytes(data)
with self.assertRaises(FCSError):
try:
get_data(data)
except FCSError as e:
self.assertEqual(e.args[0], 2)
raise
def test_encode_and_decode_frame(self):
frame = frame_data('test')
data, ftype, seq_no = get_data(frame)
self.assertEqual(b'test', data)
self.assertEqual(FRAME_DATA, ftype)
self.assertEqual(0, seq_no)
def test_decode_frame_with_1B_buffer(self):
frame = frame_data('test')
for c in frame:
try:
data, ftype, seq_no = get_data(frame)
except MessageError:
pass
self.assertEqual(b'test', data)
self.assertEqual(FRAME_DATA, ftype)
self.assertEqual(0, seq_no)
if __name__ == '__main__':
unittest.main()