tests.test_multiprocess   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 65
Duplicated Lines 58.46 %

Importance

Changes 0
Metric Value
eloc 43
dl 38
loc 65
rs 10
c 0
b 0
f 0
wmc 13

1 Function

Rating   Name   Duplication   Size   Complexity  
A test_func() 0 3 1

10 Methods

Rating   Name   Duplication   Size   Complexity  
A TestMultiprocessFunc.test_map() 3 3 1
A TestMultiprocessClass.setUp() 2 2 1
A TestMultiprocessClass.test_progress() 2 3 1
A TestMultiprocessClass.tearDown() 3 3 2
A TestMultiprocessFunc.test_progress() 2 3 1
A TestMultiprocessFunc.tearDown() 3 3 2
A TestMultiprocessFunc.setUp() 2 2 1
A TestMultiprocessClass.test_return() 3 3 1
A TestMultiprocessFunc.test_return() 3 3 1
A TestMultiprocessClass.test_map() 3 3 1

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
import unittest
2
from time import sleep
3
4
from looptools import Timer
5
6
from dirutility.multiprocess import pool_process, PoolProcess
7
8
9
def test_func(a):
10
    sleep(.1)
11
    return a * a
12
13
14
FUNC = test_func
15
ITER = list(range(100))
16
EXPECTED = set([a * a for a in range(100)])
17
18
19 View Code Duplication
class TestMultiprocessFunc(unittest.TestCase):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
20
21
    def setUp(self):
22
        self.result = None
23
24
    def tearDown(self):
25
        if isinstance(self.result, list):
26
            self.assertEqual(set(self.result), EXPECTED)
27
28
    @Timer.decorator
29
    def test_map(self):
30
        self.result = pool_process(FUNC, ITER)
31
32
    @Timer.decorator
33
    def test_return(self):
34
        self.result = pool_process(FUNC, ITER, return_vals=True)
35
36
    @Timer.decorator
37
    def test_progress(self):
38
        self.result = pool_process(FUNC, ITER, return_vals=True, progress_bar=True)
39
40
41 View Code Duplication
class TestMultiprocessClass(unittest.TestCase):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
42
43
    def setUp(self):
44
        self.result = None
45
46
    def tearDown(self):
47
        if isinstance(self.result, list):
48
            self.assertEqual(set(self.result), EXPECTED)
49
50
    @Timer.decorator
51
    def test_map(self):
52
        self.result = PoolProcess(FUNC, ITER).map()
53
54
    @Timer.decorator
55
    def test_return(self):
56
        self.result = PoolProcess(FUNC, ITER).map_return()
57
58
    @Timer.decorator
59
    def test_progress(self):
60
        self.result = PoolProcess(FUNC, ITER).map_tqdm()
61
62
63
if __name__ == '__main__':
64
    unittest.main()
65