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,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import mock
|
||||
import pytest
|
||||
import sys
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import os
|
||||
import os.path
|
||||
import pkg_resources
|
||||
|
|
|
|||
|
|
@ -81,12 +81,12 @@ def _make_config(path, hook_id, file_regex):
|
|||
|
||||
@pytest.yield_fixture
|
||||
def config_for_node_hooks_repo(node_hooks_repo):
|
||||
yield _make_config(node_hooks_repo, 'foo', '\.js$')
|
||||
yield _make_config(node_hooks_repo, 'foo', '\\.js$')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def config_for_python_hooks_repo(python_hooks_repo):
|
||||
yield _make_config(python_hooks_repo, 'foo', '\.py$')
|
||||
yield _make_config(python_hooks_repo, 'foo', '\\.py$')
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import pytest
|
||||
from plumbum import local
|
||||
|
||||
|
|
@ -38,7 +37,7 @@ def test_get_files_matching_base(get_files_matching_func):
|
|||
|
||||
|
||||
def test_get_files_matching_total_match(get_files_matching_func):
|
||||
ret = get_files_matching_func('^.*\.py$', '^$')
|
||||
ret = get_files_matching_func('^.*\\.py$', '^$')
|
||||
assert ret == set([
|
||||
'pre_commit/run.py',
|
||||
'pre_commit/git.py',
|
||||
|
|
@ -46,7 +45,7 @@ def test_get_files_matching_total_match(get_files_matching_func):
|
|||
|
||||
|
||||
def test_does_search_instead_of_match(get_files_matching_func):
|
||||
ret = get_files_matching_func('\.yaml$', '^$')
|
||||
ret = get_files_matching_func('\\.yaml$', '^$')
|
||||
assert ret == set(['hooks.yaml'])
|
||||
|
||||
|
||||
|
|
@ -56,5 +55,5 @@ def test_does_not_include_deleted_fileS(get_files_matching_func):
|
|||
|
||||
|
||||
def test_exclude_removes_files(get_files_matching_func):
|
||||
ret = get_files_matching_func('', '\.py$')
|
||||
ret = get_files_matching_func('', '\\.py$')
|
||||
assert ret == set(['hooks.yaml'])
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
from pre_commit.jsonschema_extensions import apply_defaults
|
||||
from pre_commit.jsonschema_extensions import remove_defaults
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from pre_commit.languages.all import all_languages
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import os
|
||||
import mock
|
||||
import pytest
|
||||
|
|
@ -94,7 +93,8 @@ def test_path_multiple_args():
|
|||
assert ret == 'foo/bar/baz'
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('prefix', 'path_end', 'expected_output'),
|
||||
@pytest.mark.parametrize(
|
||||
('prefix', 'path_end', 'expected_output'),
|
||||
tuple(
|
||||
(prefix, path_end, expected_output + os.sep)
|
||||
for prefix, path_end, expected_output in PATH_TESTS
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ def test_create_repo_in_env(dummy_repo_config, dummy_git_repo):
|
|||
os.path.join(dummy_git_repo, C.HOOKS_WORKSPACE, repo.sha),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
def test_install_python_repo_in_env(config_for_python_hooks_repo):
|
||||
repo = Repository(config_for_python_hooks_repo)
|
||||
|
|
@ -110,7 +111,7 @@ def mock_repo_config():
|
|||
'sha': '5e713f8878b7d100c0e059f8cc34be4fc2e8f897',
|
||||
'hooks': [{
|
||||
'id': 'pyflakes',
|
||||
'files': '\.py$',
|
||||
'files': '\\.py$',
|
||||
}],
|
||||
}
|
||||
config_wrapped = apply_defaults([config], CONFIG_JSON_SCHEMA)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import os
|
||||
import os.path
|
||||
import pytest
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import os.path
|
||||
import pytest
|
||||
import shutil
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import mock
|
||||
import pytest
|
||||
import os
|
||||
|
|
@ -17,7 +16,7 @@ from pre_commit.util import memoize_by_cwd
|
|||
def class_with_cached_property():
|
||||
class Foo(object):
|
||||
@cached_property
|
||||
def foo(self):
|
||||
def my_property(self):
|
||||
return "Foo" + str(random.getrandbits(64))
|
||||
|
||||
return Foo
|
||||
|
|
@ -25,14 +24,14 @@ def class_with_cached_property():
|
|||
|
||||
def test_cached_property(class_with_cached_property):
|
||||
instance = class_with_cached_property()
|
||||
val = instance.foo
|
||||
val2 = instance.foo
|
||||
val = instance.my_property
|
||||
val2 = instance.my_property
|
||||
assert val is val2
|
||||
|
||||
|
||||
def test_unbound_cached_property(class_with_cached_property):
|
||||
# Make sure we don't blow up when accessing the property unbound
|
||||
prop = class_with_cached_property.foo
|
||||
prop = class_with_cached_property.my_property
|
||||
assert isinstance(prop, cached_property)
|
||||
|
||||
|
||||
|
|
@ -90,7 +89,8 @@ def test_no_arguments_passed_uses_argv(entry_func):
|
|||
|
||||
|
||||
def test_clean_on_failure_noop(in_tmpdir):
|
||||
with clean_path_on_failure('foo'): pass
|
||||
with clean_path_on_failure('foo'):
|
||||
pass
|
||||
|
||||
|
||||
def test_clean_path_on_failure_does_nothing_when_not_raising(in_tmpdir):
|
||||
|
|
@ -100,7 +100,8 @@ def test_clean_path_on_failure_does_nothing_when_not_raising(in_tmpdir):
|
|||
|
||||
|
||||
def test_clean_path_on_failure_cleans_for_normal_exception(in_tmpdir):
|
||||
class MyException(Exception): pass
|
||||
class MyException(Exception):
|
||||
pass
|
||||
|
||||
with pytest.raises(MyException):
|
||||
with clean_path_on_failure('foo'):
|
||||
|
|
@ -111,7 +112,8 @@ def test_clean_path_on_failure_cleans_for_normal_exception(in_tmpdir):
|
|||
|
||||
|
||||
def test_clean_path_on_failure_cleans_for_system_exit(in_tmpdir):
|
||||
class MySystemExit(SystemExit): pass
|
||||
class MySystemExit(SystemExit):
|
||||
pass
|
||||
|
||||
with pytest.raises(MySystemExit):
|
||||
with clean_path_on_failure('foo'):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit.ordereddict import OrderedDict
|
||||
from pre_commit.yaml_extensions import ordered_dump
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue