/
test_pytest_pylint.py
112 lines (87 loc) · 2.96 KB
/
test_pytest_pylint.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# -*- coding: utf-8 -*-
"""
Unit testing module for pytest-pylti plugin
"""
pytest_plugins = ('pytester',) # pylint: disable=invalid-name
def test_basic(testdir):
"""Verify basic pylint checks"""
testdir.makepyfile("""import sys""")
result = testdir.runpytest('--pylint')
assert 'Missing module docstring' in result.stdout.str()
assert 'Unused import sys' in result.stdout.str()
assert 'Final newline missing' in result.stdout.str()
assert 'passed' not in result.stdout.str()
def test_error_control(testdir):
"""Verify that error types are configurable"""
testdir.makepyfile("""import sys""")
result = testdir.runpytest('--pylint', '--pylint-error-types=EF')
assert '1 passed' in result.stdout.str()
def test_pylintrc_file(testdir):
"""Verify that a specified pylint rc file will work."""
rcfile = testdir.makefile('rc', """
[FORMAT]
max-line-length=3
""")
testdir.makepyfile("""import sys""")
result = testdir.runpytest(
'--pylint', '--pylint-rcfile={0}'.format(rcfile.strpath)
)
assert 'Line too long (10/3)' in result.stdout.str()
def test_pylintrc_file_beside_ini(testdir):
"""
Verify that a specified pylint rc file will work what placed into pytest
ini dir.
"""
non_cwd_dir = testdir.mkdir('non_cwd_dir')
rcfile = non_cwd_dir.join('foo.rc')
rcfile.write("""
[FORMAT]
max-line-length=3
""")
inifile = non_cwd_dir.join('foo.ini')
inifile.write("""
[pytest]
addopts = --pylint --pylint-rcfile={0}
""".format(rcfile.basename))
pyfile = testdir.makepyfile("""import sys""")
result = testdir.runpytest(
pyfile.strpath
)
assert 'Line too long (10/3)' not in result.stdout.str()
result = testdir.runpytest(
'-c', inifile.strpath, pyfile.strpath
)
assert 'Line too long (10/3)' in result.stdout.str()
def test_pylintrc_ignore(testdir):
"""Verify that a pylintrc file with ignores will work."""
rcfile = testdir.makefile('rc', """
[MASTER]
ignore = test_pylintrc_ignore.py
""")
testdir.makepyfile("""import sys""")
result = testdir.runpytest(
'--pylint', '--pylint-rcfile={0}'.format(rcfile.strpath)
)
assert 'collected 0 items' in result.stdout.str()
def test_pylintrc_msg_template(testdir):
"""Verify that msg-template from pylintrc file is handled."""
rcfile = testdir.makefile('rc', """
[REPORTS]
msg-template=start {msg_id} end
""")
testdir.makepyfile("""import sys""")
result = testdir.runpytest(
'--pylint', '--pylint-rcfile={0}'.format(rcfile.strpath)
)
assert 'start W0611 end' in result.stdout.str()
def test_get_rel_path():
"""
Verify our relative path function.
"""
from pytest_pylint import get_rel_path
correct_rel_path = 'How/Are/You/blah.py'
path = '/Hi/How/Are/You/blah.py'
parent_path = '/Hi/'
assert get_rel_path(path, parent_path) == correct_rel_path
parent_path = '/Hi'
assert get_rel_path(path, parent_path) == correct_rel_path