Conditions | 10 |
Total Lines | 73 |
Code Lines | 58 |
Lines | 0 |
Ratio | 0 % |
Changes | 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:
Complex classes like build.tests.integration.test_results_edges.TestResultsEdges.test_path9() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | """Module to test the KytosGraph in graph.py.""" |
||
174 | def test_path9(self): |
||
175 | """Tests paths between all users using constrained path algorithm, |
||
176 | with the delay constraint set to 50, the bandwidth constraint |
||
177 | set to 100, the reliability constraint set to 3, and the ownership |
||
178 | constraint set to 'B' |
||
179 | |||
180 | Tests conducted with all but ownership flexible |
||
181 | """ |
||
182 | combos = combinations(["User1", "User2", "User3", "User4"], 2) |
||
183 | self.initializer() |
||
184 | |||
185 | for point_a, point_b in combos: |
||
186 | results = self.get_path_constrained(point_a, point_b, |
||
187 | base={"ownership": "B"}, |
||
188 | flexible={"delay": 50, |
||
189 | "bandwidth": 100, |
||
190 | "reliability": 3}) |
||
191 | for result in results: |
||
192 | # delay = 50 checks |
||
193 | if "delay" in result["metrics"]: |
||
194 | for path in result["paths"]: |
||
195 | self.assertNotIn("S1:1", path) |
||
196 | self.assertNotIn("S2:1", path) |
||
197 | self.assertNotIn("S3:1", path) |
||
198 | self.assertNotIn("S5:1", path) |
||
199 | self.assertNotIn("S4:2", path) |
||
200 | self.assertNotIn("User1:2", path) |
||
201 | self.assertNotIn("S5:5", path) |
||
202 | self.assertNotIn("S8:2", path) |
||
203 | self.assertNotIn("S5:6", path) |
||
204 | self.assertNotIn("User1:3", path) |
||
205 | self.assertNotIn("S6:3", path) |
||
206 | self.assertNotIn("S9:1", path) |
||
207 | self.assertNotIn("S6:4", path) |
||
208 | self.assertNotIn("S9:2", path) |
||
209 | self.assertNotIn("S6:5", path) |
||
210 | self.assertNotIn("S10:1", path) |
||
211 | self.assertNotIn("S8:5", path) |
||
212 | self.assertNotIn("S9:4", path) |
||
213 | self.assertNotIn("User1:4", path) |
||
214 | self.assertNotIn("User4:3", path) |
||
215 | |||
216 | # bandwidth = 100 checks |
||
217 | if "bandwidth" in result["metrics"]: |
||
218 | for path in result["paths"]: |
||
219 | self.assertNotIn("S3:1", path) |
||
220 | self.assertNotIn("S5:1", path) |
||
221 | self.assertNotIn("User1:4", path) |
||
222 | self.assertNotIn("User4:3", path) |
||
223 | |||
224 | # reliability = 3 checks |
||
225 | if "reliability" in result["metrics"]: |
||
226 | for path in result["paths"]: |
||
227 | self.assertNotIn("S4:1", path) |
||
228 | self.assertNotIn("S5:2", path) |
||
229 | self.assertNotIn("S5:3", path) |
||
230 | self.assertNotIn("S6:1", path) |
||
231 | |||
232 | # ownership = "B" checks |
||
233 | self.assertIn("ownership", result["metrics"]) |
||
234 | for path in result["paths"]: |
||
235 | self.assertNotIn("S4:1", path) |
||
236 | self.assertNotIn("S5:2", path) |
||
237 | self.assertNotIn("S4:2", path) |
||
238 | self.assertNotIn("User1:2", path) |
||
239 | self.assertNotIn("S5:4", path) |
||
240 | self.assertNotIn("S6:2", path) |
||
241 | self.assertNotIn("S6:5", path) |
||
242 | self.assertNotIn("S10:1", path) |
||
243 | self.assertNotIn("S8:6", path) |
||
244 | self.assertNotIn("S10:2", path) |
||
245 | self.assertNotIn("S10:3", path) |
||
246 | self.assertNotIn("User2:1", path) |
||
247 | |||
258 |