Skip to content

Commit 4dc02b0

Browse files
rossbarstefmolin
andcommitted
TST: Switch to f-strings for expected logs.
Co-authored-by: Stefanie Molin <24376333+stefmolin@users.noreply.github.com>
1 parent d5bb8f2 commit 4dc02b0

File tree

1 file changed

+43
-55
lines changed

1 file changed

+43
-55
lines changed

numpydoc/tests/hooks/test_validate_hook.py

Lines changed: 43 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -26,46 +26,44 @@ def test_validate_hook(example_module, config, capsys):
2626
"""Test that a file is correctly processed in the absence of config files."""
2727

2828
expected = inspect.cleandoc(
29-
"""
30-
numpydoc/tests/hooks/example_module.py:4: ES01 No extended summary found
29+
f"""
30+
{str(example_module)}:4: ES01 No extended summary found
3131
32-
numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented
32+
{str(example_module)}:4: PR01 Parameters {{'name'}} not documented
3333
34-
numpydoc/tests/hooks/example_module.py:4: SA01 See Also section not found
34+
{str(example_module)}:4: SA01 See Also section not found
3535
36-
numpydoc/tests/hooks/example_module.py:4: EX01 No examples section found
36+
{str(example_module)}:4: EX01 No examples section found
3737
38-
numpydoc/tests/hooks/example_module.py:8: ES01 No extended summary found
38+
{str(example_module)}:8: ES01 No extended summary found
3939
40-
numpydoc/tests/hooks/example_module.py:8: SA01 See Also section not found
40+
{str(example_module)}:8: SA01 See Also section not found
4141
42-
numpydoc/tests/hooks/example_module.py:8: EX01 No examples section found
42+
{str(example_module)}:8: EX01 No examples section found
4343
44-
numpydoc/tests/hooks/example_module.py:11: GL08 The object does not have a docstring
44+
{str(example_module)}:11: GL08 The object does not have a docstring
4545
46-
numpydoc/tests/hooks/example_module.py:17: ES01 No extended summary found
46+
{str(example_module)}:17: ES01 No extended summary found
4747
48-
numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented
48+
{str(example_module)}:17: PR01 Parameters {{'**kwargs'}} not documented
4949
50-
numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description
50+
{str(example_module)}:17: PR07 Parameter "*args" has no description
5151
52-
numpydoc/tests/hooks/example_module.py:17: SA01 See Also section not found
52+
{str(example_module)}:17: SA01 See Also section not found
5353
54-
numpydoc/tests/hooks/example_module.py:17: EX01 No examples section found
54+
{str(example_module)}:17: EX01 No examples section found
5555
56-
numpydoc/tests/hooks/example_module.py:26: SS05 Summary must start with infinitive verb, not third person (e.g. use "Generate" instead of "Generates")
56+
{str(example_module)}:26: SS05 Summary must start with infinitive verb, not third person (e.g. use "Generate" instead of "Generates")
5757
58-
numpydoc/tests/hooks/example_module.py:26: ES01 No extended summary found
58+
{str(example_module)}:26: ES01 No extended summary found
5959
60-
numpydoc/tests/hooks/example_module.py:26: SA01 See Also section not found
60+
{str(example_module)}:26: SA01 See Also section not found
6161
62-
numpydoc/tests/hooks/example_module.py:26: EX01 No examples section found
62+
{str(example_module)}:26: EX01 No examples section found
6363
64-
numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring
64+
{str(example_module)}:30: GL08 The object does not have a docstring
6565
"""
6666
)
67-
if sys.platform == "win32":
68-
expected = expected.replace("/", "\\")
6967

7068
return_code = run_hook([example_module], config=config)
7169
assert return_code == 1
@@ -79,22 +77,20 @@ def test_validate_hook_with_ignore(example_module, capsys):
7977
"""
8078

8179
expected = inspect.cleandoc(
82-
"""
83-
numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented
80+
f"""
81+
{str(example_module)}:4: PR01 Parameters {{'name'}} not documented
8482
85-
numpydoc/tests/hooks/example_module.py:11: GL08 The object does not have a docstring
83+
{str(example_module)}:11: GL08 The object does not have a docstring
8684
87-
numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented
85+
{str(example_module)}:17: PR01 Parameters {{'**kwargs'}} not documented
8886
89-
numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description
87+
{str(example_module)}:17: PR07 Parameter "*args" has no description
9088
91-
numpydoc/tests/hooks/example_module.py:26: SS05 Summary must start with infinitive verb, not third person (e.g. use "Generate" instead of "Generates")
89+
{str(example_module)}:26: SS05 Summary must start with infinitive verb, not third person (e.g. use "Generate" instead of "Generates")
9290
93-
numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring
91+
{str(example_module)}:30: GL08 The object does not have a docstring
9492
"""
9593
)
96-
if sys.platform == "win32":
97-
expected = expected.replace("/", "\\")
9894

9995
return_code = run_hook([example_module], ignore=["ES01", "SA01", "EX01"])
10096

@@ -128,18 +124,16 @@ def test_validate_hook_with_toml_config(example_module, tmp_path, capsys):
128124
)
129125

130126
expected = inspect.cleandoc(
131-
"""
132-
numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented
127+
f"""
128+
{str(example_module)}:4: PR01 Parameters {{'name'}} not documented
133129
134-
numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented
130+
{str(example_module)}:17: PR01 Parameters {{'**kwargs'}} not documented
135131
136-
numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description
132+
{str(example_module)}:17: PR07 Parameter "*args" has no description
137133
138-
numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring
134+
{str(example_module)}:30: GL08 The object does not have a docstring
139135
"""
140136
)
141-
if sys.platform == "win32":
142-
expected = expected.replace("/", "\\")
143137

144138
return_code = run_hook([example_module], config=tmp_path)
145139
assert return_code == 1
@@ -165,18 +159,16 @@ def test_validate_hook_with_setup_cfg(example_module, tmp_path, capsys):
165159
)
166160

167161
expected = inspect.cleandoc(
168-
"""
169-
numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented
162+
f"""
163+
{str(example_module)}:4: PR01 Parameters {{'name'}} not documented
170164
171-
numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented
165+
{str(example_module)}:17: PR01 Parameters {{'**kwargs'}} not documented
172166
173-
numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description
167+
{str(example_module)}:17: PR07 Parameter "*args" has no description
174168
175-
numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring
169+
{str(example_module)}:30: GL08 The object does not have a docstring
176170
"""
177171
)
178-
if sys.platform == "win32":
179-
expected = expected.replace("/", "\\")
180172

181173
return_code = run_hook([example_module], config=tmp_path)
182174
assert return_code == 1
@@ -212,14 +204,12 @@ def test_validate_hook_exclude_option_pyproject(example_module, tmp_path, capsys
212204
)
213205

214206
expected = inspect.cleandoc(
215-
"""
216-
numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented
207+
f"""
208+
{str(example_module)}:4: PR01 Parameters {{'name'}} not documented
217209
218-
numpydoc/tests/hooks/example_module.py:30: GL08 The object does not have a docstring
210+
{str(example_module)}:30: GL08 The object does not have a docstring
219211
"""
220212
)
221-
if sys.platform == "win32":
222-
expected = expected.replace("/", "\\")
223213

224214
return_code = run_hook([example_module], config=tmp_path)
225215
assert return_code == 1
@@ -245,16 +235,14 @@ def test_validate_hook_exclude_option_setup_cfg(example_module, tmp_path, capsys
245235
)
246236

247237
expected = inspect.cleandoc(
248-
"""
249-
numpydoc/tests/hooks/example_module.py:4: PR01 Parameters {'name'} not documented
238+
f"""
239+
{str(example_module)}:4: PR01 Parameters {{'name'}} not documented
250240
251-
numpydoc/tests/hooks/example_module.py:17: PR01 Parameters {'**kwargs'} not documented
241+
{str(example_module)}:17: PR01 Parameters {{'**kwargs'}} not documented
252242
253-
numpydoc/tests/hooks/example_module.py:17: PR07 Parameter "*args" has no description
243+
{str(example_module)}:17: PR07 Parameter "*args" has no description
254244
"""
255245
)
256-
if sys.platform == "win32":
257-
expected = expected.replace("/", "\\")
258246

259247
return_code = run_hook([example_module], config=tmp_path)
260248
assert return_code == 1

0 commit comments

Comments
 (0)