Conditions | 6 |
Total Lines | 85 |
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 os |
||
127 | self.assertEqual(len(results[2]), 0) |
||
128 | |||
129 | def test_process_queues(self): |
||
130 | ctrlq = queue.Queue() |
||
131 | |||
132 | # Append custom controlling sequences. |
||
133 | |||
134 | # Simulated process 1 |
||
135 | ctrlq.put((CONTROL_ELEMENT.LOCAL, 1)) |
||
136 | ctrlq.put((CONTROL_ELEMENT.LOCAL_FINISHED, None)) |
||
137 | ctrlq.put((CONTROL_ELEMENT.GLOBAL, 1)) |
||
138 | |||
139 | # Simulated process 2 |
||
140 | ctrlq.put((CONTROL_ELEMENT.LOCAL, 2)) |
||
141 | |||
142 | # Simulated process 1 |
||
143 | ctrlq.put((CONTROL_ELEMENT.GLOBAL_FINISHED, None)) |
||
144 | |||
145 | # Simulated process 2 |
||
146 | ctrlq.put((CONTROL_ELEMENT.LOCAL_FINISHED, None)) |
||
147 | ctrlq.put((CONTROL_ELEMENT.GLOBAL, 1)) |
||
148 | ctrlq.put((CONTROL_ELEMENT.GLOBAL_FINISHED, None)) |
||
149 | |||
150 | first_local = Result.from_values("o", "The first result.", file="f") |
||
151 | second_local = Result.from_values("ABear", |
||
152 | "The second result.", |
||
153 | file="f", |
||
154 | line=1) |
||
155 | third_local = Result.from_values("ABear", |
||
156 | "The second result.", |
||
157 | file="f", |
||
158 | line=4) |
||
159 | fourth_local = Result.from_values("ABear", |
||
160 | "Another result.", |
||
161 | file="f", |
||
162 | line=7) |
||
163 | first_global = Result("o", "The one and only global result.") |
||
164 | section = Section("") |
||
165 | section.append(Setting('min_severity', "normal")) |
||
166 | process_queues( |
||
167 | [DummyProcess(control_queue=ctrlq) for i in range(3)], |
||
168 | ctrlq, |
||
169 | {1: [first_local, |
||
170 | second_local, |
||
171 | third_local, |
||
172 | # The following are to be ignored |
||
173 | Result('o', 'm', severity=RESULT_SEVERITY.INFO), |
||
174 | Result.from_values("ABear", "u", file="f", line=2), |
||
175 | Result.from_values("ABear", "u", file="f", line=3)], |
||
176 | 2: [fourth_local, |
||
177 | # The following are to be ignored |
||
178 | HiddenResult("t", "c"), |
||
179 | Result.from_values("ABear", "u", file="f", line=5), |
||
180 | Result.from_values("ABear", "u", file="f", line=6)]}, |
||
181 | {1: [first_global]}, |
||
182 | {"f": ["first line # stop ignoring, invalid ignore range\n", |
||
183 | "second line # ignore all\n", |
||
184 | "third line\n", |
||
185 | "fourth line\n", |
||
186 | "# Start ignoring ABear, BBear and CBear\n", |
||
187 | "# Stop ignoring\n", |
||
188 | "seventh"]}, |
||
189 | lambda *args: self.queue.put(args[2]), |
||
190 | section, |
||
191 | self.log_printer) |
||
192 | |||
193 | self.assertEqual(self.queue.get(timeout=0), ([first_local, |
||
194 | second_local, |
||
195 | third_local])) |
||
196 | self.assertEqual(self.queue.get(timeout=0), ([fourth_local])) |
||
197 | self.assertEqual(self.queue.get(timeout=0), ([first_global])) |
||
198 | self.assertEqual(self.queue.get(timeout=0), ([first_global])) |
||
199 | |||
200 | # No valid FINISH element in the queue |
||
201 | ctrlq.put((CONTROL_ELEMENT.GLOBAL_FINISHED, None)) |
||
202 | |||
203 | process_queues( |
||
204 | [DummyProcess(control_queue=ctrlq) for i in range(3)], |
||
205 | ctrlq, |
||
206 | {1: "The first result.", 2: "The second result."}, |
||
207 | {1: "The one and only global result."}, |
||
208 | {}, |
||
209 | lambda *args: self.queue.put(args[2]), |
||
210 | Section(""), |
||
211 | self.log_printer) |
||
212 | with self.assertRaises(queue.Empty): |
||
269 |