| Conditions | 3 |
| Total Lines | 51 |
| Lines | 0 |
| Ratio | 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 | from collections import OrderedDict |
||
| 46 | pass |
||
| 47 | |||
| 48 | self.sections = self.uut.parse(self.file) |
||
| 49 | |||
| 50 | def tearDown(self): |
||
| 51 | os.remove(self.file) |
||
| 52 | |||
| 53 | def test_parse_nonexisting_file(self): |
||
| 54 | self.assertRaises(FileNotFoundError, |
||
| 55 | self.uut.parse, |
||
| 56 | self.nonexistentfile) |
||
| 57 | self.assertNotEqual(self.uut.parse(self.file, True), self.sections) |
||
| 58 | |||
| 59 | def test_parse_nonexisting_section(self): |
||
| 60 | self.assertRaises(IndexError, |
||
| 61 | self.uut.get_section, |
||
| 62 | "inexistent section") |
||
| 63 | |||
| 64 | def test_parse_default_section(self): |
||
| 65 | default_should = OrderedDict([ |
||
| 66 | ('a_default', 'val'), |
||
| 67 | ('another', 'val'), |
||
| 68 | ('comment0', '# do you know that thats a comment'), |
||
| 69 | ('test', 'content'), |
||
| 70 | ('t', '')]) |
||
| 71 | |||
| 72 | key, val = self.sections.popitem(last=False) |
||
| 73 | self.assertTrue(isinstance(val, Section)) |
||
| 74 | self.assertEqual(key, 'default') |
||
| 75 | |||
| 76 | is_dict = OrderedDict() |
||
| 77 | for k in val: |
||
| 78 | is_dict[k] = str(val[k]) |
||
| 79 | self.assertEqual(is_dict, default_should) |
||
| 80 | |||
| 81 | def test_parse_makefiles_section(self): |
||
| 82 | makefiles_should = OrderedDict([ |
||
| 83 | ('j', 'a\nmultiline\nvalue'), |
||
| 84 | ('another', 'a\nmultiline\nvalue'), |
||
| 85 | ('comment1', '# just a omment'), |
||
| 86 | ('comment2', '# just a omment'), |
||
| 87 | ('lastone', 'val'), |
||
| 88 | ('comment3', ''), |
||
| 89 | ('a_default', 'val'), |
||
| 90 | ('comment0', '# do you know that thats a comment'), |
||
| 91 | ('test', 'content'), |
||
| 92 | ('t', '')]) |
||
| 93 | |||
| 94 | # Pop off the default section. |
||
| 95 | self.sections.popitem(last=False) |
||
| 96 | |||
| 97 | key, val = self.sections.popitem(last=False) |
||
| 159 |