| Conditions | 6 |
| Total Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | #!/usr/bin/env python3 |
||
| 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) |
||
|
|
|||
| 53 | assert regular == no_data |
||
| 54 |
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.