1212
1313import pre_commit .constants as C
1414from pre_commit import five
15- from pre_commit import parse_shebang
1615from pre_commit .clientlib import CONFIG_SCHEMA
1716from pre_commit .clientlib import load_manifest
1817from pre_commit .envcontext import envcontext
1918from pre_commit .languages import golang
2019from pre_commit .languages import helpers
2120from pre_commit .languages import node
22- from pre_commit .languages import pcre
2321from pre_commit .languages import python
2422from pre_commit .languages import ruby
2523from pre_commit .languages import rust
3735from testing .util import skipif_cant_run_docker
3836from testing .util import skipif_cant_run_swift
3937from testing .util import xfailif_broken_deep_listdir
40- from testing .util import xfailif_no_pcre_support
4138from testing .util import xfailif_no_venv
4239from testing .util import xfailif_windows_no_ruby
4340
@@ -426,13 +423,13 @@ def test_output_isatty(tempdir_factory, store):
426423 )
427424
428425
429- def _make_grep_repo (language , entry , store , args = ()):
426+ def _make_grep_repo (entry , store , args = ()):
430427 config = {
431428 'repo' : 'local' ,
432429 'hooks' : [{
433430 'id' : 'grep-hook' ,
434431 'name' : 'grep-hook' ,
435- 'language' : language ,
432+ 'language' : 'pygrep' ,
436433 'entry' : entry ,
437434 'args' : args ,
438435 'types' : ['text' ],
@@ -451,53 +448,25 @@ def greppable_files(tmpdir):
451448 yield tmpdir
452449
453450
454- class TestPygrep (object ):
455- language = 'pygrep'
456-
457- def test_grep_hook_matching (self , greppable_files , store ):
458- hook = _make_grep_repo (self .language , 'ello' , store )
459- ret , out = hook .run (('f1' , 'f2' , 'f3' ), color = False )
460- assert ret == 1
461- assert _norm_out (out ) == b"f1:1:hello'hi\n "
462-
463- def test_grep_hook_case_insensitive (self , greppable_files , store ):
464- hook = _make_grep_repo (self .language , 'ELLO' , store , args = ['-i' ])
465- ret , out = hook .run (('f1' , 'f2' , 'f3' ), color = False )
466- assert ret == 1
467- assert _norm_out (out ) == b"f1:1:hello'hi\n "
468-
469- @pytest .mark .parametrize ('regex' , ('nope' , "foo'bar" , r'^\[INFO\]' ))
470- def test_grep_hook_not_matching (self , regex , greppable_files , store ):
471- hook = _make_grep_repo (self .language , regex , store )
472- ret , out = hook .run (('f1' , 'f2' , 'f3' ), color = False )
473- assert (ret , out ) == (0 , b'' )
474-
475-
476- @xfailif_no_pcre_support # pragma: windows no cover
477- class TestPCRE (TestPygrep ):
478- """organized as a class for xfailing pcre"""
479- language = 'pcre'
480-
481- def test_pcre_hook_many_files (self , greppable_files , store ):
482- # This is intended to simulate lots of passing files and one failing
483- # file to make sure it still fails. This is not the case when naively
484- # using a system hook with `grep -H -n '...'`
485- hook = _make_grep_repo ('pcre' , 'ello' , store )
486- ret , out = hook .run ((os .devnull ,) * 15000 + ('f1' ,), color = False )
487- assert ret == 1
488- assert _norm_out (out ) == b"f1:1:hello'hi\n "
489-
490- def test_missing_pcre_support (self , greppable_files , store ):
491- def no_grep (exe , ** kwargs ):
492- assert exe == pcre .GREP
493- return None
494-
495- with mock .patch .object (parse_shebang , 'find_executable' , no_grep ):
496- hook = _make_grep_repo ('pcre' , 'ello' , store )
497- ret , out = hook .run (('f1' , 'f2' , 'f3' ), color = False )
498- assert ret == 1
499- expected = 'Executable `{}` not found' .format (pcre .GREP ).encode ()
500- assert out == expected
451+ def test_grep_hook_matching (greppable_files , store ):
452+ hook = _make_grep_repo ('ello' , store )
453+ ret , out = hook .run (('f1' , 'f2' , 'f3' ), color = False )
454+ assert ret == 1
455+ assert _norm_out (out ) == b"f1:1:hello'hi\n "
456+
457+
458+ def test_grep_hook_case_insensitive (greppable_files , store ):
459+ hook = _make_grep_repo ('ELLO' , store , args = ['-i' ])
460+ ret , out = hook .run (('f1' , 'f2' , 'f3' ), color = False )
461+ assert ret == 1
462+ assert _norm_out (out ) == b"f1:1:hello'hi\n "
463+
464+
465+ @pytest .mark .parametrize ('regex' , ('nope' , "foo'bar" , r'^\[INFO\]' ))
466+ def test_grep_hook_not_matching (regex , greppable_files , store ):
467+ hook = _make_grep_repo (regex , store )
468+ ret , out = hook .run (('f1' , 'f2' , 'f3' ), color = False )
469+ assert (ret , out ) == (0 , b'' )
501470
502471
503472def _norm_pwd (path ):
0 commit comments