1313from pre_commit .clientlib import validate_config_main
1414from pre_commit .clientlib import validate_manifest_main
1515from testing .fixtures import sample_local_config
16- from testing .util import get_resource_path
1716
1817
1918def is_valid_according_to_schema (obj , obj_schema ):
@@ -30,19 +29,6 @@ def test_check_type_tag_failures(value):
3029 check_type_tag (value )
3130
3231
33- @pytest .mark .parametrize (
34- ('args' , 'expected_output' ),
35- (
36- (['.pre-commit-config.yaml' ], 0 ),
37- (['non_existent_file.yaml' ], 1 ),
38- ([get_resource_path ('valid_yaml_but_invalid_config.yaml' )], 1 ),
39- ([get_resource_path ('non_parseable_yaml_file.notyaml' )], 1 ),
40- ),
41- )
42- def test_validate_config_main (args , expected_output ):
43- assert validate_config_main (args ) == expected_output
44-
45-
4632@pytest .mark .parametrize (
4733 ('config_obj' , 'expected' ), (
4834 (
@@ -91,39 +77,13 @@ def test_config_valid(config_obj, expected):
9177
9278
9379def test_local_hooks_with_rev_fails ():
94- config_obj = {'repos' : [sample_local_config ()]}
95- config_obj ['repos' ][0 ]['rev' ] = 'foo'
80+ config_obj = {'repos' : [dict (sample_local_config (), rev = 'foo' )]}
9681 with pytest .raises (cfgv .ValidationError ):
9782 cfgv .validate (config_obj , CONFIG_SCHEMA )
9883
9984
100- @pytest .mark .parametrize (
101- 'config_obj' , (
102- {'repos' : [{
103- 'repo' : 'local' ,
104- 'hooks' : [{
105- 'id' : 'arg-per-line' ,
106- 'name' : 'Args per line hook' ,
107- 'entry' : 'bin/hook.sh' ,
108- 'language' : 'script' ,
109- 'files' : '' ,
110- 'args' : ['hello' , 'world' ],
111- }],
112- }]},
113- {'repos' : [{
114- 'repo' : 'local' ,
115- 'hooks' : [{
116- 'id' : 'arg-per-line' ,
117- 'name' : 'Args per line hook' ,
118- 'entry' : 'bin/hook.sh' ,
119- 'language' : 'script' ,
120- 'files' : '' ,
121- 'args' : ['hello' , 'world' ],
122- }],
123- }]},
124- ),
125- )
126- def test_config_with_local_hooks_definition_passes (config_obj ):
85+ def test_config_with_local_hooks_definition_passes ():
86+ config_obj = {'repos' : [sample_local_config ()]}
12787 cfgv .validate (config_obj , CONFIG_SCHEMA )
12888
12989
@@ -135,17 +95,30 @@ def test_config_schema_does_not_contain_defaults():
13595 assert not isinstance (item , cfgv .Optional )
13696
13797
138- @pytest .mark .parametrize (
139- ('args' , 'expected_output' ),
140- (
141- (['.pre-commit-hooks.yaml' ], 0 ),
142- (['non_existent_file.yaml' ], 1 ),
143- ([get_resource_path ('valid_yaml_but_invalid_manifest.yaml' )], 1 ),
144- ([get_resource_path ('non_parseable_yaml_file.notyaml' )], 1 ),
145- ),
146- )
147- def test_validate_manifest_main (args , expected_output ):
148- assert validate_manifest_main (args ) == expected_output
98+ def test_validate_manifest_main_ok ():
99+ assert not validate_manifest_main (('.pre-commit-hooks.yaml' ,))
100+
101+
102+ def test_validate_config_main_ok ():
103+ assert not validate_config_main (('.pre-commit-config.yaml' ,))
104+
105+
106+ def test_validate_config_old_list_format_ok (tmpdir ):
107+ f = tmpdir .join ('cfg.yaml' )
108+ f .write ('- {repo: meta, hooks: [{id: identity}]}' )
109+ assert not validate_config_main ((f .strpath ,))
110+
111+
112+ @pytest .mark .parametrize ('fn' , (validate_config_main , validate_manifest_main ))
113+ def test_mains_not_ok (tmpdir , fn ):
114+ not_yaml = tmpdir .join ('f.notyaml' )
115+ not_yaml .write ('{' )
116+ not_schema = tmpdir .join ('notconfig.yaml' )
117+ not_schema .write ('{}' )
118+
119+ assert fn (('does-not-exist' ,))
120+ assert fn ((not_yaml .strpath ,))
121+ assert fn ((not_schema .strpath ,))
149122
150123
151124@pytest .mark .parametrize (
@@ -174,8 +147,6 @@ def test_validate_manifest_main(args, expected_output):
174147 ),
175148 (
176149 # A regression in 0.13.5: always_run and files are permissible
177- # together (but meaningless). In a future version upgrade this to
178- # an error
179150 [{
180151 'id' : 'a' ,
181152 'name' : 'b' ,
0 commit comments