Completed
Pull Request — master (#42)
by TJ
06:11
created

TestStarStructNone.test_single_element_2()   B

Complexity

Conditions 6

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
c 1
b 0
f 0
dl 0
loc 36
rs 7.5384

1 Method

Rating   Name   Duplication   Size   Complexity  
A TestStarStructNone.pseudo_salted_md5() 0 3 1
1
#!/usr/bin/env python3
2
3
"""Tests for the starstruct class"""
4
5
import unittest
6
from hashlib import md5
7
8
from starstruct.message import Message
9
10
class TestStarStructNone(unittest.TestCase):
11
    """StarStruct module tests"""
12
13
    VarTest = Message('VarTest', [
14
        ('x', 'B'),
15
        ('y', 'B'),
16
    ])
17
18
    def test_single_element_2(self):
19
        def pseudo_salted_md5(salt, original):
20
            temp_md5 = md5(original)
21
            return md5(salt + temp_md5.digest()).digest()
22
23
        TestStruct = Message('TestStruct', [
24
            ('length_in_objects', 'H', 'vardata'),
25
            ('vardata', self.VarTest, 'length_in_objects'),
26
        ])
27
28
        CRCedMessage = Message('CRCedMessage', [
29
            ('data', TestStruct),
30
            ('salted', None),
31
            ('function_data', '16B', pseudo_salted_md5, ['salted', b'data']),
32
        ])
33
34
        test_data = {
35
            'data': {
36
                'length_in_objects': 2,
37
                'vardata': [
38
                    {'x': 1, 'y': 2},
39
                    {'x': 3, 'y': 4},
40
                ],
41
            },
42
            'salted': b'random_salter',
43
        }
44
45
        made = CRCedMessage.make(test_data)
46
        # assert len(made) == 5
47
        assert len(made.data.vardata) == 2
48
        assert made.data.vardata[0].x == 1
49
        assert made.data.vardata[0].y == 2
50
51
        no_data = made.pack()
52
        regular = CRCedMessage.pack(**test_data)
0 ignored issues
show
Coding Style introduced by
Usage of * or ** arguments should usually be done with care.

Generally, there is nothing wrong with usage of * or ** arguments. For readability of the code base, we suggest to not over-use these language constructs though.

For more information, we can recommend this blog post from Ned Batchelder including its comments which also touches this aspect.

Loading history...
53
        assert regular == no_data
54