@@ -139,45 +139,6 @@ def test_validate_hook_with_toml_config(example_module, tmp_path, capsys):
139
139
assert capsys .readouterr ().err .strip () == expected
140
140
141
141
142
- @pytest .mark .parametrize (
143
- "regex, expected_code" ,
144
- [(""".*/example.*\.py""" , 0 ), (""".*/non_existent_match.*\.py""" , 1 )],
145
- )
146
- def test_validate_hook_with_toml_config_exclude_files (
147
- example_module , regex , expected_code , tmp_path , capsys
148
- ):
149
- """
150
- Test that a file is correctly processed in the absence of config files
151
- with command line ignore options.
152
- """
153
-
154
- with open (tmp_path / "pyproject.toml" , "w" ) as config_file :
155
- config_file .write (
156
- inspect .cleandoc (
157
- """
158
- [tool.numpydoc_validation]
159
- checks = [
160
- "all",
161
- "EX01",
162
- "SA01",
163
- "ES01",
164
- ]
165
- exclude = '\\ .__init__$'
166
- override_SS05 = [
167
- '^Creates',
168
- ]
169
- exclude_files = [
170
- """
171
- + regex
172
- + """]
173
- """
174
- )
175
- )
176
-
177
- return_code = run_hook ([example_module ], config = tmp_path )
178
- assert return_code == expected_code # Should not-report/report findings.
179
-
180
-
181
142
def test_validate_hook_with_setup_cfg (example_module , tmp_path , capsys ):
182
143
"""
183
144
Test that a file is correctly processed with the config coming from
@@ -285,3 +246,69 @@ def test_validate_hook_exclude_option_setup_cfg(example_module, tmp_path, capsys
285
246
return_code = run_hook ([example_module ], config = tmp_path )
286
247
assert return_code == 1
287
248
assert capsys .readouterr ().err .strip () == expected
249
+
250
+
251
+ @pytest .mark .parametrize (
252
+ "regex, expected_code" ,
253
+ [(".*(/|\\ \\ )example.*\.py" , 0 ), (".*/non_existent_match.*\.py" , 1 )],
254
+ )
255
+ def test_validate_hook_exclude_files_option_pyproject (
256
+ example_module , regex , expected_code , tmp_path
257
+ ):
258
+ """
259
+ Test that the hook correctly processes the toml config and either includes
260
+ or excludes files based on the `exclude_files` option.
261
+ """
262
+
263
+ with open (tmp_path / "pyproject.toml" , "w" ) as config_file :
264
+ config_file .write (
265
+ inspect .cleandoc (
266
+ f"""
267
+ [tool.numpydoc_validation]
268
+ checks = [
269
+ "all",
270
+ "EX01",
271
+ "SA01",
272
+ "ES01",
273
+ ]
274
+ exclude = '\\ .__init__$'
275
+ override_SS05 = [
276
+ '^Creates',
277
+ ]
278
+ exclude_files = [
279
+ '{ regex } ',
280
+ ]"""
281
+ )
282
+ )
283
+
284
+ return_code = run_hook ([example_module ], config = tmp_path )
285
+ assert return_code == expected_code # Should not-report/report findings.
286
+
287
+
288
+ @pytest .mark .parametrize (
289
+ "regex, expected_code" ,
290
+ [(".*(/|\\ \\ )example.*\.py" , 0 ), (".*/non_existent_match.*\.py" , 1 )],
291
+ )
292
+ def test_validate_hook_exclude_files_option_setup_cfg (
293
+ example_module , regex , expected_code , tmp_path
294
+ ):
295
+ """
296
+ Test that the hook correctly processes the setup config and either includes
297
+ or excludes files based on the `exclude_files` option.
298
+ """
299
+
300
+ with open (tmp_path / "setup.cfg" , "w" ) as config_file :
301
+ config_file .write (
302
+ inspect .cleandoc (
303
+ f"""
304
+ [tool:numpydoc_validation]
305
+ checks = all,EX01,SA01,ES01
306
+ exclude = \\ .NewClass$,\\ .__init__$
307
+ override_SS05 = ^Creates
308
+ exclude_files = { regex }
309
+ """
310
+ )
311
+ )
312
+
313
+ return_code = run_hook ([example_module ], config = tmp_path )
314
+ assert return_code == expected_code # Should not-report/report findings.
0 commit comments