-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
abspath_file_test.py
54 lines (48 loc) · 1.26 KB
/
abspath_file_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from __future__ import annotations
import pytest
from pyupgrade._data import Settings
from pyupgrade._main import _fix_plugins
@pytest.mark.parametrize(
('s', 'expected'),
(
pytest.param(
'from os.path import abspath\n'
'abspath(__file__)',
'from os.path import abspath\n'
'__file__',
id='abspath',
),
pytest.param(
'import os\n'
'os.path.abspath(__file__)',
'import os\n'
'__file__',
id='os.path.abspath',
),
),
)
def test_fix_abspath_file(s, expected):
ret = _fix_plugins(s, settings=Settings(min_version=(3, 9)))
assert ret == expected
@pytest.mark.parametrize(
's, min_version',
(
pytest.param(
'abspath(__file__)',
(3, 8),
id='Not Python3.9+',
),
pytest.param(
'os.path.abspath(file)',
(3, 9),
id='Abspath of not-__file__',
),
pytest.param(
'os.path.abspath(file, foo)',
(3, 9),
id='Garbage (don\'t rewrite)',
),
),
)
def test_fix_abspath_file_noop(s, min_version):
assert _fix_plugins(s, settings=Settings(min_version=min_version)) == s