Total Complexity | 4 |
Total Lines | 40 |
Duplicated Lines | 30 % |
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 | """ |
||
2 | Tests for the cleaning logic on Python packages |
||
3 | """ |
||
4 | import platform |
||
5 | import pytest |
||
6 | |||
7 | try: |
||
8 | from unittest.mock import patch |
||
9 | except ImportError: # Python 2.7, PyPy2 |
||
10 | from mock import patch |
||
11 | |||
12 | from cli_test_helpers import ArgvContext |
||
13 | |||
14 | import pyclean.cli |
||
15 | |||
16 | |||
17 | @pytest.mark.skipif(platform.python_implementation() != 'CPython' |
||
18 | or platform.system() != 'Linux', |
||
19 | reason="requires CPython on Debian Linux") |
||
20 | def test_clean_package(): |
||
21 | """ |
||
22 | Does collecting/traversing packages for cleaning work for Python 2+3? |
||
23 | """ |
||
24 | with ArgvContext('pyclean', '--legacy', '-p', 'python'): |
||
25 | pyclean.cli.main() |
||
26 | |||
27 | |||
28 | @pytest.mark.skipif(platform.python_implementation() != 'PyPy' |
||
29 | or platform.system() != 'Linux', |
||
30 | reason="requires PyPy on Debian Linux") |
||
31 | @patch('pyclean.pypyclean.installed_namespaces', return_value={}) |
||
32 | def test_clean_package_pypy(mock_namespaces): |
||
33 | """ |
||
34 | Does collecting/traversing packages for cleaning work for PyPy? |
||
35 | """ |
||
36 | with ArgvContext('pyclean', '--legacy', '-p', 'python'): |
||
37 | pyclean.cli.main() |
||
38 | |||
39 | assert mock_namespaces.called |
||
40 |