|
1
|
|
|
""" |
|
2
|
|
|
Tests for the pyclean CLI |
|
3
|
|
|
""" |
|
4
|
|
|
import os |
|
5
|
|
|
|
|
6
|
|
|
try: |
|
7
|
|
|
from unittest.mock import patch |
|
8
|
|
|
except ImportError: # Python 2.7, PyPy2 |
|
9
|
|
|
from mock import patch |
|
10
|
|
|
|
|
11
|
|
|
from cli_test_helpers import ArgvContext |
|
12
|
|
|
|
|
13
|
|
|
import pyclean.cli |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
def test_entrypoint(): |
|
17
|
|
|
""" |
|
18
|
|
|
Is entrypoint script installed? (setup.py) |
|
19
|
|
|
""" |
|
20
|
|
|
exit_status = os.system('pyclean --help') |
|
21
|
|
|
assert exit_status == 0 |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
def test_entrypoint_py2_installed(): |
|
25
|
|
|
""" |
|
26
|
|
|
Is entrypoint script installed for Python 2? (setup.py) |
|
27
|
|
|
""" |
|
28
|
|
|
exit_status = os.system('py2clean --help') |
|
29
|
|
|
assert exit_status == 0 |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
@patch('pyclean.compat.import_module') |
|
33
|
|
|
def test_entrypoint_py2_working(mock_import_module): |
|
34
|
|
|
""" |
|
35
|
|
|
Is entrypoint overriding with Python 2 implementation? |
|
36
|
|
|
""" |
|
37
|
|
|
with ArgvContext('py2clean', 'foo'): |
|
38
|
|
|
pyclean.cli.py2clean() |
|
39
|
|
|
|
|
40
|
|
|
args, _ = mock_import_module.call_args |
|
41
|
|
|
assert args == ('pyclean.py2clean',) |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
def test_entrypoint_py3_installed(): |
|
45
|
|
|
""" |
|
46
|
|
|
Is entrypoint script installed for Python 3? (setup.py) |
|
47
|
|
|
""" |
|
48
|
|
|
exit_status = os.system('py3clean --help') |
|
49
|
|
|
assert exit_status == 0 |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
@patch('pyclean.compat.import_module') |
|
53
|
|
|
def test_entrypoint_py3_working(mock_import_module): |
|
54
|
|
|
""" |
|
55
|
|
|
Is entrypoint overriding with Python 3 implementation? |
|
56
|
|
|
""" |
|
57
|
|
|
with ArgvContext('py3clean', 'foo'): |
|
58
|
|
|
pyclean.cli.py3clean() |
|
59
|
|
|
|
|
60
|
|
|
args, _ = mock_import_module.call_args |
|
61
|
|
|
assert args == ('pyclean.py3clean',) |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
def test_entrypoint_pypy_installed(): |
|
65
|
|
|
""" |
|
66
|
|
|
Is entrypoint script installed for PyPy 2/3? (setup.py) |
|
67
|
|
|
""" |
|
68
|
|
|
exit_status = os.system('pypyclean --help') |
|
69
|
|
|
assert exit_status == 0 |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
@patch('pyclean.compat.import_module') |
|
73
|
|
|
def test_entrypoint_pypy_working(mock_import_module): |
|
74
|
|
|
""" |
|
75
|
|
|
Is entrypoint overriding with PyPy implementation? |
|
76
|
|
|
""" |
|
77
|
|
|
with ArgvContext('pypyclean', 'foo'): |
|
78
|
|
|
pyclean.cli.pypyclean() |
|
79
|
|
|
|
|
80
|
|
|
args, _ = mock_import_module.call_args |
|
81
|
|
|
assert args == ('pyclean.pypyclean',) |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
@patch('pyclean.compat.get_implementation') |
|
85
|
|
|
def test_legacy_calls_compat(mock_get_implementation): |
|
86
|
|
|
""" |
|
87
|
|
|
Does calling `pyclean --legacy` invoke the compat layer? |
|
88
|
|
|
""" |
|
89
|
|
|
with ArgvContext('pyclean', '--legacy', 'foo'): |
|
90
|
|
|
pyclean.cli.main() |
|
91
|
|
|
|
|
92
|
|
|
assert mock_get_implementation.called |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
@patch('pyclean.modern.pyclean') |
|
96
|
|
|
def test_default_modern(mock_modern_pyclean): |
|
97
|
|
|
""" |
|
98
|
|
|
Does simply calling `pyclean` invoke the modern implementation? |
|
99
|
|
|
""" |
|
100
|
|
|
with ArgvContext('pyclean', 'foo'): |
|
101
|
|
|
pyclean.cli.main() |
|
102
|
|
|
|
|
103
|
|
|
assert mock_modern_pyclean.called |
|
104
|
|
|
|