mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Better project structure
This commit is contained in:
parent
f31f092f9b
commit
1746a97e24
52 changed files with 221 additions and 189 deletions
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from pre_commit.clientlib.validate_base import get_validator
|
||||
|
|
@ -7,7 +6,8 @@ from pre_commit.yaml_extensions import ordered_load
|
|||
from testing.util import get_resource_path
|
||||
|
||||
|
||||
class AdditionalValidatorError(ValueError): pass
|
||||
class AdditionalValidatorError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -22,7 +22,7 @@ def array_validator():
|
|||
|
||||
@pytest.fixture
|
||||
def additional_validator():
|
||||
def raises_always(obj):
|
||||
def raises_always(_):
|
||||
raise AdditionalValidatorError
|
||||
|
||||
return get_validator(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
|
||||
import jsonschema
|
||||
import jsonschema.exceptions
|
||||
import pytest
|
||||
|
||||
from pre_commit.clientlib.validate_config import CONFIG_JSON_SCHEMA
|
||||
|
|
@ -8,6 +5,7 @@ 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
|
||||
from pre_commit.jsonschema_extensions import apply_defaults
|
||||
from testing.util import is_valid_according_to_schema
|
||||
|
||||
|
||||
def test_returns_0_for_valid_config():
|
||||
|
|
@ -22,21 +20,13 @@ 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)
|
||||
return True
|
||||
except jsonschema.exceptions.ValidationError:
|
||||
return False
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('manifest_obj', 'expected'), (
|
||||
([], False),
|
||||
(
|
||||
[{
|
||||
'repo': 'git@github.com:pre-commit/pre-commit-hooks',
|
||||
'sha': 'cd74dc150c142c3be70b24eaf0b02cae9d235f37',
|
||||
'hooks': [{'id': 'pyflakes', 'files': '\.py$'}],
|
||||
'repo': 'git@github.com:pre-commit/pre-commit-hooks',
|
||||
'sha': 'cd74dc150c142c3be70b24eaf0b02cae9d235f37',
|
||||
'hooks': [{'id': 'pyflakes', 'files': '\\.py$'}],
|
||||
}],
|
||||
True,
|
||||
),
|
||||
|
|
@ -47,7 +37,7 @@ def is_valid_according_to_schema(obj, schema):
|
|||
'hooks': [
|
||||
{
|
||||
'id': 'pyflakes',
|
||||
'files': '\.py$',
|
||||
'files': '\\.py$',
|
||||
'args': ['foo', 'bar', 'baz'],
|
||||
},
|
||||
],
|
||||
|
|
@ -61,7 +51,7 @@ def is_valid_according_to_schema(obj, schema):
|
|||
'hooks': [
|
||||
{
|
||||
'id': 'pyflakes',
|
||||
'files': '\.py$',
|
||||
'files': '\\.py$',
|
||||
# Exclude pattern must be a string
|
||||
'exclude': 0,
|
||||
'args': ['foo', 'bar', 'baz'],
|
||||
|
|
@ -95,7 +85,7 @@ def test_config_with_ok_regexes_passes():
|
|||
[{
|
||||
'repo': 'foo',
|
||||
'sha': 'foo',
|
||||
'hooks': [{'id': 'hook_id', 'files': '\.py$'}],
|
||||
'hooks': [{'id': 'hook_id', 'files': '\\.py$'}],
|
||||
}],
|
||||
CONFIG_JSON_SCHEMA,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
|
||||
import jsonschema
|
||||
import jsonschema.exceptions
|
||||
import pytest
|
||||
|
||||
from pre_commit.clientlib.validate_manifest import additional_manifest_check
|
||||
from pre_commit.clientlib.validate_manifest import InvalidManifestError
|
||||
from pre_commit.clientlib.validate_manifest import MANIFEST_JSON_SCHEMA
|
||||
from pre_commit.clientlib.validate_manifest import run
|
||||
from testing.util import is_valid_according_to_schema
|
||||
|
||||
|
||||
def test_returns_0_for_valid_manifest():
|
||||
|
|
@ -34,24 +32,16 @@ def test_additional_manifest_check_languages(obj):
|
|||
additional_manifest_check(obj)
|
||||
|
||||
|
||||
def is_valid_according_to_schema(obj, schema):
|
||||
try:
|
||||
jsonschema.validate(obj, schema)
|
||||
return True
|
||||
except jsonschema.exceptions.ValidationError:
|
||||
return False
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('manifest_obj', 'expected'), (
|
||||
([], False),
|
||||
([{'id': 'a', 'name': 'b', 'entry': 'c', 'language': 'python'}], True),
|
||||
(
|
||||
[{
|
||||
'id': 'a',
|
||||
'name': 'b',
|
||||
'entry': 'c',
|
||||
'language': 'python',
|
||||
'expected_return_value': 0,
|
||||
'id': 'a',
|
||||
'name': 'b',
|
||||
'entry': 'c',
|
||||
'language': 'python',
|
||||
'expected_return_value': 0,
|
||||
}],
|
||||
True,
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue