| Conditions | 1 |
| Total Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import unittest |
||
| 44 | @mock.patch('sys.stdout') |
||
| 45 | def test_create_data(self, mock_out): |
||
| 46 | # NO DATA |
||
| 47 | response = ['NODATA'] |
||
| 48 | data = self.pc.create_data(response) |
||
| 49 | self.assertEqual(len(data), 0) |
||
| 50 | |||
| 51 | # If error 7F... |
||
| 52 | response = ['7F0112'] |
||
| 53 | data = self.pc.create_data(response) |
||
| 54 | self.assertEqual(len(data), 0) |
||
| 55 | |||
| 56 | # If raw_data |
||
| 57 | # |
||
| 58 | # Single frame 11 bits |
||
| 59 | response = [ |
||
| 60 | '7E8064100FFFFFFFFFC' |
||
| 61 | ] |
||
| 62 | data = self.pc.create_data(response) |
||
| 63 | self.assertEqual(data, {'E8': 'FFFFFFFF'}) |
||
| 64 | |||
| 65 | # Single frame 29 bits |
||
| 66 | response = [ |
||
| 67 | '18DAF110064100FFFFFFFFFC' |
||
| 68 | ] |
||
| 69 | pc = p_can.ProtocolsCan(7) |
||
| 70 | data = pc.create_data(response) |
||
| 71 | self.assertEqual(data, {'10': 'FFFFFFFF'}) |
||
| 72 | |||
| 73 | # Multi line frame 11 bits |
||
| 74 | response = [ |
||
| 75 | '7E81013490401353630', |
||
| 76 | '7E82200000000000031', |
||
| 77 | '7E82132383934394143' |
||
| 78 | ] |
||
| 79 | data = self.pc.create_data(response) |
||
| 80 | self.assertEqual(data, {'E8': '134904013536303238393439414300000000000031'}) |
||
| 81 | |||
| 82 | # Multi line frame 29 bits |
||
| 83 | pc = p_can.ProtocolsCan(7) |
||
| 84 | response = [ |
||
| 85 | '18DAF1101013490401353630', |
||
| 86 | '18DAF1102200000000000031', |
||
| 87 | '18DAF1102132383934394143' |
||
| 88 | ] |
||
| 89 | data = pc.create_data(response) |
||
| 90 | self.assertEqual(data, {'10': '134904013536303238393439414300000000000031'}) |
||
| 91 | |||
| 92 | # Single frame 11 bits BUT 2 ECU's |
||
| 93 | response = [ |
||
| 94 | '7E8064100FFFFFFFFFC', |
||
| 95 | '7E9064100FFFFFF00FC' |
||
| 96 | ] |
||
| 97 | data = self.pc.create_data(response) |
||
| 98 | self.assertEqual(data, { |
||
| 99 | 'E8': 'FFFFFFFF', |
||
| 100 | 'E9': 'FFFFFF00' |
||
| 101 | }) |
||
| 106 |