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