Completed
Pull Request — master (#42)
by TJ
05:36 queued 04:35
created

TestStarStructNone.pseudo_salted_md5()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
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
11
class TestStarStructNone(unittest.TestCase):
12
    """StarStruct module tests"""
13
14
    VarTest = Message('VarTest', [
15
        ('x', 'B'),
16
        ('y', 'B'),
17
    ])
18
19
    def test_single_element_2(self):
20
        def pseudo_salted_md5(salt, original):
21
            temp_md5 = md5(original)
22
            return md5(salt + temp_md5.digest()).digest()
23
24
        TestStruct = Message('TestStruct', [
25
            ('length_in_objects', 'H', 'vardata'),
26
            ('vardata', self.VarTest, 'length_in_objects'),
27
        ])
28
29
        CRCedMessage = Message('CRCedMessage', [
30
            ('data', TestStruct),
31
            ('salted', None),
32
            ('function_data', '16B', pseudo_salted_md5, ['salted', b'data']),
33
        ])
34
35
        test_data = {
36
            'data': {
37
                'length_in_objects': 2,
38
                'vardata': [
39
                    {'x': 1, 'y': 2},
40
                    {'x': 3, 'y': 4},
41
                ],
42
            },
43
            'salted': b'random_salter',
44
        }
45
46
        made = CRCedMessage.make(test_data)
47
        # assert len(made) == 5
48
        assert len(made.data.vardata) == 2
49
        assert made.data.vardata[0].x == 1
50
        assert made.data.vardata[0].y == 2
51
52
        no_data = made.pack()
53
        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...
54
        assert regular == no_data
55