MultipleExecutionsTestCase   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 57.14 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
dl 16
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_simple_success() 0 8 2
A test_failure_in_middle() 16 16 3

How to fix   Duplicated Code   

Duplicated Code

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
2
3
# Copyright 2013-2018 Vincent Jacques <[email protected]>
4
5
from __future__ import division, absolute_import, print_function
6
7
from ActionTree import *
8
from . import *
9
10
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, SUCCESSFUL)
20
21
        self.assertEventsEqual("a " * self.REPEAT)
22
23 View Code Duplication
    def test_failure_in_middle(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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, CANCELED)
35
            self.assertEqual(report.get_action_status(b).status, FAILED)
36
            self.assertEqual(report.get_action_status(c).status, SUCCESSFUL)
37
38
        self.assertEventsEqual("c b " * self.REPEAT)
39