1
|
|
|
""" |
2
|
|
|
Tests for filtering by Python version |
3
|
|
|
""" |
4
|
|
|
import platform |
5
|
|
|
import sys |
6
|
|
|
import pytest |
7
|
|
|
|
8
|
|
|
try: |
9
|
|
|
from unittest.mock import patch |
10
|
|
|
except ImportError: # Python 2.7, PyPy2 |
11
|
|
|
from mock import patch |
12
|
|
|
|
13
|
|
|
from cli_test_helpers import ArgvContext |
14
|
|
|
|
15
|
|
|
import pyclean |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
@pytest.mark.skipif(platform.python_implementation() != 'CPython' |
19
|
|
|
or sys.version_info < (3,) |
20
|
|
|
or platform.system() != 'Linux', |
21
|
|
|
reason="requires CPython 3 on Debian Linux") |
22
|
|
|
@patch('pyclean.py3clean.Interpreter.magic_tag', return_value='{impl}-{ver}' |
23
|
|
|
.format( |
24
|
|
|
impl=platform.python_implementation().lower(), # e.g. "cpython" |
25
|
|
|
ver=''.join(platform.python_version().split('.')[:2]), # e.g. "36" |
26
|
|
|
)) |
27
|
|
|
def test_filterversion_py3(mock_magictag): |
28
|
|
|
""" |
29
|
|
|
Does filtering by Python version work when run with Python 3? |
30
|
|
|
""" |
31
|
|
|
with ArgvContext('pyclean', '--legacy', '-V', '3.5', '-p', 'python'), \ |
32
|
|
|
pytest.raises(SystemExit): |
33
|
|
|
pyclean.cli.main() |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
@pytest.mark.skipif(platform.python_implementation() != 'CPython' |
37
|
|
|
or sys.version_info >= (3,) |
38
|
|
|
or platform.system() != 'Linux', |
39
|
|
|
reason="requires CPython 2 on Debian Linux") |
40
|
|
|
def test_filterversion_py2(): |
41
|
|
|
""" |
42
|
|
|
Does filtering by Python version work when run with Python 2? |
43
|
|
|
""" |
44
|
|
|
with ArgvContext('pyclean', '--legacy', '-V', '2.7', '-p', 'python'): |
45
|
|
|
pyclean.cli.main() |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
@pytest.mark.skipif(platform.python_implementation() != 'PyPy' |
49
|
|
|
or platform.system() != 'Linux', |
50
|
|
|
reason="requires PyPy on Debian Linux") |
51
|
|
|
@patch('pyclean.pypyclean.installed_namespaces', return_value={}) |
52
|
|
|
def test_filterversion_pypy(mock_namespaces): |
53
|
|
|
""" |
54
|
|
|
Does filtering by Python version work when run with PyPy? |
55
|
|
|
""" |
56
|
|
|
with ArgvContext('pyclean', '--legacy', '-V', '2.7', '-p', 'python'): |
57
|
|
|
pyclean.cli.main() |
58
|
|
|
|
59
|
|
|
assert mock_namespaces.called |
60
|
|
|
|