| Total Complexity | 6 |
| Total Lines | 36 |
| Duplicated Lines | 100 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | #!/usr/bin/env python3 |
||
| 11 | View Code Duplication | class TestElementBase(unittest.TestCase): |
|
|
|
|||
| 12 | """ElementBase module tests""" |
||
| 13 | |||
| 14 | def test_valid(self): |
||
| 15 | """Test field formats that are valid ElementBase elements.""" |
||
| 16 | |||
| 17 | test_fields = [ |
||
| 18 | ('a', 'd'), # double |
||
| 19 | ('b', 'f'), # float |
||
| 20 | ('e', '?'), # bool: 0, 1 |
||
| 21 | ] |
||
| 22 | |||
| 23 | for field in test_fields: |
||
| 24 | with self.subTest(field): # pylint: disable=no-member |
||
| 25 | out = ElementBase.valid(field) |
||
| 26 | self.assertTrue(out) |
||
| 27 | |||
| 28 | def test_not_valid(self): |
||
| 29 | """Test field formats that are not valid ElementBase elements.""" |
||
| 30 | |||
| 31 | test_fields = [ |
||
| 32 | ('a', '4x'), # 4 pad bytes |
||
| 33 | ('b', 'z'), # invalid |
||
| 34 | ('c', '1'), # invalid |
||
| 35 | ('d', '9S'), # invalid (must be lowercase) |
||
| 36 | ('e', 'b'), # signed byte: -128, 127 |
||
| 37 | ('f', 'H'), # unsigned short: 0, 65535 |
||
| 38 | ('g', '10s'), # 10 byte string |
||
| 39 | ('h', 'L'), # unsigned long: 0, 2^32-1 |
||
| 40 | ('i', '/'), # invalid |
||
| 41 | ] |
||
| 42 | |||
| 43 | for field in test_fields: |
||
| 44 | with self.subTest(field): # pylint: disable=no-member |
||
| 45 | out = ElementBase.valid(field) |
||
| 46 | self.assertFalse(out) |
||
| 47 |