forked from davidraleigh/pytest-pep8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_pep8.py
executable file
·143 lines (124 loc) · 3.79 KB
/
test_pep8.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# coding=utf8
import pytest
import py
pytest_plugins = "pytester",
def test_version():
import pytest_pep8
assert pytest_pep8.__version__
class TestIgnores:
def pytest_funcarg__example(self, request):
testdir = request.getfuncargvalue("testdir")
p = testdir.makepyfile("")
p.write("class AClass:\n pass\n \n\n# too many spaces")
return p
def test_ignores(self, tmpdir):
from pytest_pep8 import Ignorer
ignores = ["E203", "b/?.py E204 W205", "z.py ALL", "*.py E300"]
ign = Ignorer(ignores)
assert ign(tmpdir.join("a/b/x.py")) == "E203 E204 W205 E300".split()
assert ign(tmpdir.join("a/y.py")) == "E203 E300".split()
assert ign(tmpdir.join("a/z.py")) is None
def test_ignores_all(self, testdir):
from pytest_pep8 import Ignorer
testdir.makeini("""
[pytest]
pep8ignore = E203
*.py E300
tests/*.py ALL E203 # something
""")
testdir.tmpdir.ensure("xy.py")
testdir.tmpdir.ensure("tests/hello.py")
result = testdir.runpytest("--pep8", "-s")
assert result.ret == 0
result.stdout.fnmatch_lines([
"*collected 1*",
"*xy.py .*",
"*1 passed*",
])
def test_w293w292(self, testdir, example):
result = testdir.runpytest("--pep8", )
result.stdout.fnmatch_lines([
# "*plugins*pep8*",
"*W293*",
"*W292*",
])
assert result.ret != 0
def test_mtime_caching(self, testdir, example):
testdir.tmpdir.ensure("hello.py")
result = testdir.runpytest("--pep8", )
result.stdout.fnmatch_lines([
# "*plugins*pep8*",
"*W293*",
"*W292*",
"*1 failed*1 passed*",
])
assert result.ret != 0
result = testdir.runpytest("--pep8", )
result.stdout.fnmatch_lines([
"*W293*",
"*W292*",
"*1 failed*1 skipped*",
])
testdir.makeini("""
[pytest]
pep8ignore = *.py W293 W292
""")
result = testdir.runpytest("--pep8", )
result.stdout.fnmatch_lines([
"*2 passed*",
])
def test_ok_verbose(testdir):
p = testdir.makepyfile("""
class AClass:
pass
""")
p = p.write(p.read() + "\n")
result = testdir.runpytest("--pep8", "--verbose")
result.stdout.fnmatch_lines([
"*test_ok_verbose*PEP8-check*",
])
assert result.ret == 0
def test_keyword_match(testdir):
testdir.makepyfile("""
def test_hello():
a=[ 1,123]
#
""")
result = testdir.runpytest("--pep8", "-mpep8")
result.stdout.fnmatch_lines([
"*E201*",
"*1 failed*",
])
assert 'passed' not in result.stdout.str()
def test_maxlinelength(testdir):
testdir.makeini("""
[pytest]
pep8maxlinelength = 50
""")
testdir.makepyfile("""
# this line is longer than the configured max. line length
""")
result = testdir.runpytest("--pep8", "-mpep8")
result.stdout.fnmatch_lines([
"*E501*",
"*1 failed*",
])
assert 'passed' not in result.stdout.str()
@pytest.mark.xfail("sys.platform == 'win32'")
def test_unicode_error(testdir):
x = testdir.tmpdir.join("x.py")
import codecs
f = codecs.open(str(x), "w", encoding="utf8")
f.write(py.builtin._totext("""
# coding=utf8
accent_map = {
u'\\xc0': 'a', # À -> a non-ascii comment crashes it
}
""", "utf8"))
f.close()
result = testdir.runpytest("--pep8", x, "-s")
result.stdout.fnmatch_lines("*non-ascii comment*")
def test_strict(testdir):
testdir.makepyfile("")
result = testdir.runpytest("--strict", "--pep8")
assert result.ret == 0