@@ -247,38 +247,64 @@ def test_warn_mutable_rev_conditional():
247247 cfgv .validate (config_obj , CONFIG_REPO_DICT )
248248
249249
250- def test_validate_optional_sensible_regex_at_hook_level (caplog ):
250+ @pytest .mark .parametrize (
251+ ('regex' , 'warning' ),
252+ (
253+ (
254+ r'dir/*.py' ,
255+ "The 'files' field in hook 'flake8' is a regex, not a glob -- "
256+ "matching '/*' probably isn't what you want here" ,
257+ ),
258+ (
259+ r'dir[\/].*\.py' ,
260+ r"pre-commit normalizes slashes in the 'files' field in hook "
261+ r"'flake8' to forward slashes, so you can use / instead of [\/]" ,
262+ ),
263+ (
264+ r'dir[/\\].*\.py' ,
265+ r"pre-commit normalizes slashes in the 'files' field in hook "
266+ r"'flake8' to forward slashes, so you can use / instead of [/\\]" ,
267+ ),
268+ ),
269+ )
270+ def test_validate_optional_sensible_regex_at_hook (caplog , regex , warning ):
251271 config_obj = {
252272 'id' : 'flake8' ,
253- 'files' : 'dir/*.py' ,
273+ 'files' : regex ,
254274 }
255275 cfgv .validate (config_obj , CONFIG_HOOK_DICT )
256276
257- assert caplog .record_tuples == [
277+ assert caplog .record_tuples == [('pre_commit' , logging .WARNING , warning )]
278+
279+
280+ @pytest .mark .parametrize (
281+ ('regex' , 'warning' ),
282+ (
258283 (
259- 'pre_commit' ,
260- logging .WARNING ,
261- "The 'files' field in hook 'flake8' is a regex, not a glob -- "
284+ r'dir/*.py' ,
285+ "The top-level 'files' field is a regex, not a glob -- "
262286 "matching '/*' probably isn't what you want here" ,
263287 ),
264- ]
265-
266-
267- def test_validate_optional_sensible_regex_at_top_level (caplog ):
288+ (
289+ r'dir[\/].*\.py' ,
290+ r"pre-commit normalizes the slashes in the top-level 'files' "
291+ r'field to forward slashes, so you can use / instead of [\/]' ,
292+ ),
293+ (
294+ r'dir[/\\].*\.py' ,
295+ r"pre-commit normalizes the slashes in the top-level 'files' "
296+ r'field to forward slashes, so you can use / instead of [/\\]' ,
297+ ),
298+ ),
299+ )
300+ def test_validate_optional_sensible_regex_at_top_level (caplog , regex , warning ):
268301 config_obj = {
269- 'files' : 'dir/*.py' ,
302+ 'files' : regex ,
270303 'repos' : [],
271304 }
272305 cfgv .validate (config_obj , CONFIG_SCHEMA )
273306
274- assert caplog .record_tuples == [
275- (
276- 'pre_commit' ,
277- logging .WARNING ,
278- "The top-level 'files' field is a regex, not a glob -- matching "
279- "'/*' probably isn't what you want here" ,
280- ),
281- ]
307+ assert caplog .record_tuples == [('pre_commit' , logging .WARNING , warning )]
282308
283309
284310@pytest .mark .parametrize ('fn' , (validate_config_main , validate_manifest_main ))
0 commit comments