Total Complexity | 6 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | #!/usr/bin/env python3 |
||
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) |
||
|
|||
54 | assert regular == no_data |
||
55 |
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.