TestStarStruct   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 11
Bugs 0 Features 0
Metric Value
c 11
b 0
f 0
dl 0
loc 36
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
B test_escape_sequence_items() 0 27 4
1
"""Tests for the starstruct class"""
2
3
# import pytest
4
5
from starstruct.message import Message
6
# from starstruct.modes import Mode
7
8
9
# pylint: disable=line-too-long,invalid-name
10
class TestStarStruct:
11
    """StarStruct module tests"""
12
13
    Repeated = Message('Repeated', [
14
        ('x', 'B'),
15
        ('y', 'B'),
16
        ('z', 'H'),
17
    ])
18
19
    def test_escape_sequence_items(self):
20
        TestStruct = Message('TestStruct', [
21
            ('escaped_data', self.Repeated, {
22
                'escape': {
23
                    'start': b'\xff\x00\xff\x11',
24
                    'separator': b'\x12\x12',
25
                    'end': b'\x11\xff\x00\xff',
26
                },
27
            }),
28
        ])
29
30
        test_data = {
31
            'escaped_data': [
32
                {'x': 7, 'y': 9, 'z': 13},
33
                {'x': 2, 'y': 8, 'z': 27},
34
                {'x': 6, 'y': 7, 'z': 11},
35
            ],
36
        }
37
38
        made = TestStruct.make(test_data)
39
        assert made.escaped_data[0].x == 7
40
        assert made.escaped_data[0].y == 9
41
42
        packed = TestStruct.pack(test_data)
43
44
        unpacked = TestStruct.unpack(packed)
45
        assert unpacked == made
46