mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 16:24:40 +04:00
Move pre_commit.schema to cfgv library
This commit is contained in:
parent
8bb4d63d3b
commit
bdad930d71
9 changed files with 58 additions and 791 deletions
|
|
@ -1,9 +1,8 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import cfgv
|
||||
import pytest
|
||||
|
||||
from pre_commit import schema
|
||||
from pre_commit.clientlib import check_language
|
||||
from pre_commit.clientlib import check_type_tag
|
||||
from pre_commit.clientlib import CONFIG_HOOK_DICT
|
||||
from pre_commit.clientlib import CONFIG_SCHEMA
|
||||
|
|
@ -16,29 +15,18 @@ from testing.util import get_resource_path
|
|||
|
||||
def is_valid_according_to_schema(obj, obj_schema):
|
||||
try:
|
||||
schema.validate(obj, obj_schema)
|
||||
cfgv.validate(obj, obj_schema)
|
||||
return True
|
||||
except schema.ValidationError:
|
||||
except cfgv.ValidationError:
|
||||
return False
|
||||
|
||||
|
||||
@pytest.mark.parametrize('value', ('not a language', 'python3'))
|
||||
def test_check_language_failures(value):
|
||||
with pytest.raises(schema.ValidationError):
|
||||
check_language(value)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('value', ('definitely-not-a-tag', 'fiel'))
|
||||
def test_check_type_tag_failures(value):
|
||||
with pytest.raises(schema.ValidationError):
|
||||
with pytest.raises(cfgv.ValidationError):
|
||||
check_type_tag(value)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('value', ('python', 'node', 'pcre'))
|
||||
def test_check_language_ok(value):
|
||||
check_language(value)
|
||||
|
||||
|
||||
def test_is_local_repo():
|
||||
assert is_local_repo({'repo': 'local'})
|
||||
|
||||
|
|
@ -58,7 +46,6 @@ def test_validate_config_main(args, expected_output):
|
|||
|
||||
@pytest.mark.parametrize(
|
||||
('config_obj', 'expected'), (
|
||||
([], False),
|
||||
(
|
||||
{'repos': [{
|
||||
'repo': 'git@github.com:pre-commit/pre-commit-hooks',
|
||||
|
|
@ -116,8 +103,8 @@ def test_config_with_local_hooks_definition_fails():
|
|||
'files': '^(.*)$',
|
||||
}],
|
||||
}]}
|
||||
with pytest.raises(schema.ValidationError):
|
||||
schema.validate(config_obj, CONFIG_SCHEMA)
|
||||
with pytest.raises(cfgv.ValidationError):
|
||||
cfgv.validate(config_obj, CONFIG_SCHEMA)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -147,7 +134,7 @@ def test_config_with_local_hooks_definition_fails():
|
|||
),
|
||||
)
|
||||
def test_config_with_local_hooks_definition_passes(config_obj):
|
||||
schema.validate(config_obj, CONFIG_SCHEMA)
|
||||
cfgv.validate(config_obj, CONFIG_SCHEMA)
|
||||
|
||||
|
||||
def test_config_schema_does_not_contain_defaults():
|
||||
|
|
@ -155,7 +142,7 @@ def test_config_schema_does_not_contain_defaults():
|
|||
will clobber potentially useful values in the backing manifest. #227
|
||||
"""
|
||||
for item in CONFIG_HOOK_DICT.items:
|
||||
assert not isinstance(item, schema.Optional)
|
||||
assert not isinstance(item, cfgv.Optional)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -174,7 +161,6 @@ def test_validate_manifest_main(args, expected_output):
|
|||
@pytest.mark.parametrize(
|
||||
('manifest_obj', 'expected'),
|
||||
(
|
||||
([], False),
|
||||
(
|
||||
[{
|
||||
'id': 'a',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue