@@ -35,29 +35,40 @@ def is_valid_according_to_schema(obj, schema):
3535 [{
3636 'repo' : '[email protected] :pre-commit/pre-commit-hooks' , 3737 'sha' : 'cd74dc150c142c3be70b24eaf0b02cae9d235f37' ,
38- 'hooks' : [
39- {
40- 'id' : 'pyflakes' ,
41- 'files' : '*.py' ,
42- }
43- ]
38+ 'hooks' : [{'id' : 'pyflakes' , 'files' : '\.py$' }],
4439 }],
4540 True ,
4641 ),
4742 (
4843 [{
49- 'repo' : '[email protected] :pre-commit/pre-commit-hooks' , 50- 'sha' : 'cd74dc150c142c3be70b24eaf0b02cae9d235f37' ,
51- 'hooks' : [
52- {
53- 'id' : 'pyflakes' ,
54- 'files' : '* .py' ,
55- 'args' : ['foo' , 'bar' , 'baz' ],
56- }
57- ]
44+ 'repo' : '[email protected] :pre-commit/pre-commit-hooks' , 45+ 'sha' : 'cd74dc150c142c3be70b24eaf0b02cae9d235f37' ,
46+ 'hooks' : [
47+ {
48+ 'id' : 'pyflakes' ,
49+ 'files' : '\ .py$ ' ,
50+ 'args' : ['foo' , 'bar' , 'baz' ],
51+ },
52+ ],
5853 }],
5954 True ,
6055 ),
56+ (
57+ [{
58+ 'repo' : '[email protected] :pre-commit/pre-commit-hooks' , 59+ 'sha' : 'cd74dc150c142c3be70b24eaf0b02cae9d235f37' ,
60+ 'hooks' : [
61+ {
62+ 'id' : 'pyflakes' ,
63+ 'files' : '\.py$' ,
64+ # Exclude pattern must be a string
65+ 'exclude' : 0 ,
66+ 'args' : ['foo' , 'bar' , 'baz' ],
67+ },
68+ ],
69+ }],
70+ False ,
71+ ),
6172))
6273def test_is_valid_according_to_schema (manifest_obj , expected ):
6374 ret = is_valid_according_to_schema (manifest_obj , CONFIG_JSON_SCHEMA )
@@ -67,12 +78,28 @@ def test_is_valid_according_to_schema(manifest_obj, expected):
6778def test_config_with_failing_regexes_fails ():
6879 with pytest .raises (InvalidConfigError ):
6980 # Note the regex '(' is invalid (unbalanced parens)
70- validate_config_extra (
71- [{ 'repo' : 'foo' , 'hooks' : [{'id' : 'hook_id' , 'files' : '(' }] }]
72- )
81+ validate_config_extra ([{
82+ 'repo' : 'foo' , 'hooks' : [{'id' : 'hook_id' , 'files' : '(' }]
83+ }] )
7384
7485
7586def test_config_with_ok_regexes_passes ():
76- validate_config_extra (
77- [{'repo' : 'foo' , 'hooks' : [{'id' : 'hook_id' , 'files' : '\.py$' }]}]
78- )
87+ validate_config_extra ([{
88+ 'repo' : 'foo' , 'hooks' : [{'id' : 'hook_id' , 'files' : '\.py$' }],
89+ }])
90+
91+
92+ def test_config_with_invalid_exclude_regex_fails ():
93+ with pytest .raises (InvalidConfigError ):
94+ # NOte the regex '(' is invalid (unbalanced parens)
95+ validate_config_extra ([{
96+ 'repo' : 'foo' ,
97+ 'hooks' : [{'id' : 'hook_id' , 'files' : '' , 'exclude' : '(' }],
98+ }])
99+
100+
101+ def test_config_with_ok_exclude_regex_passes ():
102+ validate_config_extra ([{
103+ 'repo' : 'foo' ,
104+ 'hooks' : [{'id' : 'hook_id' , 'files' : '' , 'exclude' : '^vendor/' }],
105+ }])
0 commit comments