-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_subprocess.py
More file actions
150 lines (119 loc) · 3.83 KB
/
test_subprocess.py
File metadata and controls
150 lines (119 loc) · 3.83 KB
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
144
145
146
147
148
149
150
# stdlib
import subprocess
import sys
# 3rd party
from domdf_python_tools.paths import PathPlus, in_directory
def test_subprocess(tmp_pathplus: PathPlus, monkeypatch):
monkeypatch.delenv("COV_CORE_SOURCE", raising=False)
monkeypatch.delenv("COV_CORE_CONFIG", raising=False)
monkeypatch.delenv("COV_CORE_DATAFILE", raising=False)
monkeypatch.setenv("PYTHONWARNINGS", "ignore")
(tmp_pathplus / "demo.py").write_text("\n\t\ndef foo():\n\tpass\n\t")
with in_directory(tmp_pathplus):
result = subprocess.run(
[sys.executable, "-m", "flake8", "demo.py"],
capture_output=True,
)
assert result.returncode == 1
assert result.stderr == b''
assert result.stdout == b"""\
demo.py:1:1: DALL000 Module lacks __all__.
demo.py:1:1: DALL100 Top-level __dir__ function definition is required.
demo.py:2:1: W191 indentation contains tabs
demo.py:2:1: W293 blank line contains whitespace
demo.py:4:1: W191 indentation contains tabs
demo.py:5:1: W191 indentation contains tabs
demo.py:5:1: W293 blank line contains whitespace
demo.py:5:2: W292 no newline at end of file
"""
with in_directory(tmp_pathplus):
result = subprocess.run(
[sys.executable, "-m", "flake8", "demo.py", "--select", "DALL000"],
capture_output=True,
)
assert result.returncode == 1
assert result.stderr == b''
assert result.stdout == b"demo.py:1:1: DALL000 Module lacks __all__.\n"
(tmp_pathplus / "tox.ini").write_text("""
[flake8]
select = DALL000
""")
with in_directory(tmp_pathplus):
result = subprocess.run(
[sys.executable, "-m", "flake8", "demo.py"],
capture_output=True,
)
assert result.returncode == 1
assert result.stderr == b''
assert result.stdout == b"demo.py:1:1: DALL000 Module lacks __all__.\n"
tox_ini = tmp_pathplus / "tox.ini"
tox_ini.write_text("""
[flake8]
select = DALL000
per-file-ignores =
demo.py: DALL000
""")
with in_directory(tmp_pathplus):
result = subprocess.run(
[sys.executable, "-m", "flake8", "demo.py"],
capture_output=True,
)
assert result.returncode == 0
assert result.stderr == b''
assert result.stdout == b''
def test_subprocess_noqa(tmp_pathplus: PathPlus, monkeypatch):
monkeypatch.delenv("COV_CORE_SOURCE", raising=False)
monkeypatch.delenv("COV_CORE_CONFIG", raising=False)
monkeypatch.delenv("COV_CORE_DATAFILE", raising=False)
monkeypatch.setenv("PYTHONWARNINGS", "ignore")
(tmp_pathplus / "demo.py").write_text(" # noqa: DALL000,DALL100 \n\n\t\ndef foo():\n\tpass\n\t")
with in_directory(tmp_pathplus):
result = subprocess.run(
[sys.executable, "-m", "flake8", "demo.py"],
capture_output=True,
)
assert result.returncode == 1
assert result.stderr == b''
assert result.stdout == b"""\
demo.py:3:1: W191 indentation contains tabs
demo.py:3:1: W293 blank line contains whitespace
demo.py:5:1: W191 indentation contains tabs
demo.py:6:1: W191 indentation contains tabs
demo.py:6:1: W293 blank line contains whitespace
demo.py:6:2: W292 no newline at end of file
"""
with in_directory(tmp_pathplus):
result = subprocess.run(
[sys.executable, "-m", "flake8", "demo.py", "--select", "DALL000"],
capture_output=True,
)
assert result.returncode == 0
assert result.stderr == b''
assert result.stdout == b''
(tmp_pathplus / "tox.ini").write_text("""
[flake8]
select = DALL000
""")
with in_directory(tmp_pathplus):
result = subprocess.run(
[sys.executable, "-m", "flake8", "demo.py"],
capture_output=True,
)
assert result.returncode == 0
assert result.stderr == b''
assert result.stdout == b''
tox_ini = tmp_pathplus / "tox.ini"
tox_ini.write_text("""
[flake8]
select = DALL000
per-file-ignores =
demo.py: DALL000
""")
with in_directory(tmp_pathplus):
result = subprocess.run(
[sys.executable, "-m", "flake8", "demo.py"],
capture_output=True,
)
assert result.returncode == 0
assert result.stderr == b''
assert result.stdout == b''