| Conditions | 1 |
| Total Lines | 57 |
| 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 | import queue |
||
| 128 | def verify_local_bear(bear, |
||
| 129 | valid_files, |
||
| 130 | invalid_files, |
||
| 131 | filename=None, |
||
| 132 | settings={}, |
||
| 133 | force_linebreaks=True, |
||
| 134 | create_tempfile=True): |
||
| 135 | """ |
||
| 136 | Generates a test for a local bear by checking the given valid and invalid |
||
| 137 | file contents. Simply use it on your module level like: |
||
| 138 | |||
| 139 | YourTestName = verify_local_bear(YourBear, (['valid line'],), |
||
| 140 | (['invalid line'],)) |
||
| 141 | |||
| 142 | :param bear: The Bear class to test. |
||
| 143 | :param valid_files: An iterable of files as a string list that won't |
||
| 144 | yield results. |
||
| 145 | :param invalid_files: An iterable of files as a string list that must |
||
| 146 | yield results. |
||
| 147 | :param filename: The filename to use for valid and invalid files. |
||
| 148 | :param settings: A dictionary of keys and values (both string) from |
||
| 149 | which settings will be created that will be made |
||
| 150 | available for the tested bear. |
||
| 151 | :param force_linebreaks: Whether to append newlines at each line |
||
| 152 | if needed. (Bears expect a \\n for every line) |
||
| 153 | :param create_tempfile: Whether to save lines in tempfile if needed. |
||
| 154 | :return: A unittest.TestCase object. |
||
| 155 | """ |
||
| 156 | @generate_skip_decorator(bear) |
||
| 157 | class LocalBearTest(LocalBearTestHelper): |
||
| 158 | |||
| 159 | def setUp(self): |
||
| 160 | self.section = Section('name') |
||
| 161 | self.uut = bear(self.section, |
||
| 162 | queue.Queue()) |
||
| 163 | for name, value in settings.items(): |
||
| 164 | self.section.append(Setting(name, value)) |
||
| 165 | |||
| 166 | def test_valid_files(self): |
||
| 167 | for file in valid_files: |
||
| 168 | self.check_validity(self.uut, |
||
| 169 | file, |
||
| 170 | filename, |
||
| 171 | valid=True, |
||
| 172 | force_linebreaks=force_linebreaks, |
||
| 173 | create_tempfile=create_tempfile) |
||
| 174 | |||
| 175 | def test_invalid_files(self): |
||
| 176 | for file in invalid_files: |
||
| 177 | self.check_validity(self.uut, |
||
| 178 | file, |
||
| 179 | filename, |
||
| 180 | valid=False, |
||
| 181 | force_linebreaks=force_linebreaks, |
||
| 182 | create_tempfile=create_tempfile) |
||
| 183 | |||
| 184 | return LocalBearTest |
||
| 185 |