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