Total Complexity | 13 |
Total Lines | 65 |
Duplicated Lines | 58.46 % |
Changes | 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 | 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): |
|
|
|||
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): |
|
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 |