mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Make the config validator more strict for correct regexes
This commit is contained in:
parent
6b1097d3c9
commit
be8d1b811a
3 changed files with 37 additions and 5 deletions
|
|
@ -4,7 +4,9 @@ import jsonschema.exceptions
|
|||
import pytest
|
||||
|
||||
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
||||
from pre_commit.clientlib.validate_config import InvalidConfigError
|
||||
from pre_commit.clientlib.validate_config import run
|
||||
from pre_commit.clientlib.validate_config import validate_config_extra
|
||||
|
||||
|
||||
def test_returns_0_for_valid_config():
|
||||
|
|
@ -18,6 +20,7 @@ def test_returns_0_for_out_manifest():
|
|||
def test_returns_1_for_failing():
|
||||
assert run(['tests/data/valid_yaml_but_invalid_config.yaml']) == 1
|
||||
|
||||
|
||||
def is_valid_according_to_schema(obj, schema):
|
||||
try:
|
||||
jsonschema.validate(obj, schema)
|
||||
|
|
@ -58,4 +61,18 @@ def is_valid_according_to_schema(obj, schema):
|
|||
))
|
||||
def test_is_valid_according_to_schema(manifest_obj, expected):
|
||||
ret = is_valid_according_to_schema(manifest_obj, CONFIG_JSON_SCHEMA)
|
||||
assert ret is expected
|
||||
assert ret is expected
|
||||
|
||||
|
||||
def test_config_with_failing_regexes_fails():
|
||||
with pytest.raises(InvalidConfigError):
|
||||
# Note the regex '(' is invalid (unbalanced parens)
|
||||
validate_config_extra(
|
||||
[{'repo': 'foo', 'hooks': [{'id': 'hook_id', 'files': '('}]}]
|
||||
)
|
||||
|
||||
|
||||
def test_config_with_ok_regexes_passes():
|
||||
validate_config_extra(
|
||||
[{'repo': 'foo', 'hooks': [{'id': 'hook_id', 'files': '\.py$'}]}]
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue