| Total Complexity | 5 |
| Total Lines | 28 |
| Duplicated Lines | 57.14 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | # coding: utf8 |
||
| 11 | class MultipleExecutionsTestCase(ActionTreeTestCase): |
||
| 12 | REPEAT = 5 |
||
| 13 | |||
| 14 | def test_simple_success(self): |
||
| 15 | a = self._action("a") |
||
| 16 | |||
| 17 | for i in range(self.REPEAT): |
||
| 18 | report = execute(a) |
||
| 19 | self.assertEqual(report.get_action_status(a).status, ExecutionReport.ActionStatus.Successful) |
||
| 20 | |||
| 21 | self.assertEventsEqual("a " * self.REPEAT) |
||
| 22 | |||
| 23 | View Code Duplication | def test_failure_in_middle(self): |
|
|
|
|||
| 24 | a = self._action("a") |
||
| 25 | b = self._action("b", exception=Exception()) |
||
| 26 | c = self._action("c") |
||
| 27 | a.add_dependency(b) |
||
| 28 | b.add_dependency(c) |
||
| 29 | |||
| 30 | for i in range(self.REPEAT): |
||
| 31 | with self.assertRaises(CompoundException) as catcher: |
||
| 32 | execute(a) |
||
| 33 | report = catcher.exception.execution_report |
||
| 34 | self.assertEqual(report.get_action_status(a).status, ExecutionReport.ActionStatus.Canceled) |
||
| 35 | self.assertEqual(report.get_action_status(b).status, ExecutionReport.ActionStatus.Failed) |
||
| 36 | self.assertEqual(report.get_action_status(c).status, ExecutionReport.ActionStatus.Successful) |
||
| 37 | |||
| 38 | self.assertEventsEqual("c b " * self.REPEAT) |
||
| 39 |