| Conditions | 1 |
| Total Lines | 54 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 | # -*- coding: utf-8 -*- |
||
| 12 | def test_clean(self): |
||
| 13 | d = { |
||
| 14 | 'a': {}, |
||
| 15 | 'b': { 'x': 1 }, |
||
| 16 | 'c': [], |
||
| 17 | 'd': [0, 1], |
||
| 18 | 'e': 0.0, |
||
| 19 | 'f': '', |
||
| 20 | 'g': None, |
||
| 21 | 'h': '0' |
||
| 22 | } |
||
| 23 | |||
| 24 | b = UtilityDict(d) |
||
| 25 | b.clean() |
||
| 26 | r = { |
||
| 27 | 'b': { 'x': 1 }, |
||
| 28 | 'd': [0, 1], |
||
| 29 | 'e': 0.0, |
||
| 30 | 'h': '0', |
||
| 31 | } |
||
| 32 | self.assertEqual(b, r) |
||
| 33 | |||
| 34 | b = UtilityDict(d) |
||
| 35 | b.clean(dicts=False) |
||
| 36 | r = { |
||
| 37 | 'a': {}, |
||
| 38 | 'b': { 'x': 1 }, |
||
| 39 | 'd': [0, 1], |
||
| 40 | 'e': 0.0, |
||
| 41 | 'h': '0' |
||
| 42 | } |
||
| 43 | self.assertEqual(b, r) |
||
| 44 | |||
| 45 | b = UtilityDict(d) |
||
| 46 | b.clean(lists=False) |
||
| 47 | r = { |
||
| 48 | 'b': { 'x': 1 }, |
||
| 49 | 'c': [], |
||
| 50 | 'd': [0, 1], |
||
| 51 | 'e': 0.0, |
||
| 52 | 'h': '0' |
||
| 53 | } |
||
| 54 | self.assertEqual(b, r) |
||
| 55 | |||
| 56 | b = UtilityDict(d) |
||
| 57 | b.clean(strings=False) |
||
| 58 | r = { |
||
| 59 | 'b': { 'x': 1 }, |
||
| 60 | 'd': [0, 1], |
||
| 61 | 'e': 0.0, |
||
| 62 | 'f': '', |
||
| 63 | 'h': '0', |
||
| 64 | } |
||
| 65 | self.assertEqual(b, r) |
||
| 66 | |||
| 214 |