mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Default local / meta through cfgv
This commit is contained in:
parent
46ae88c1f0
commit
fc84567923
11 changed files with 109 additions and 112 deletions
|
|
@ -5,6 +5,7 @@ import pytest
|
|||
|
||||
from pre_commit.clientlib import check_type_tag
|
||||
from pre_commit.clientlib import CONFIG_HOOK_DICT
|
||||
from pre_commit.clientlib import CONFIG_REPO_DICT
|
||||
from pre_commit.clientlib import CONFIG_SCHEMA
|
||||
from pre_commit.clientlib import is_local_repo
|
||||
from pre_commit.clientlib import MANIFEST_SCHEMA
|
||||
|
|
@ -236,3 +237,19 @@ def test_migrate_to_sha_ok():
|
|||
dct = {'repo': 'a', 'rev': 'b'}
|
||||
MigrateShaToRev().apply_default(dct)
|
||||
assert dct == {'repo': 'a', 'rev': 'b'}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'config_repo',
|
||||
(
|
||||
# i-dont-exist isn't a valid hook
|
||||
{'repo': 'meta', 'hooks': [{'id': 'i-dont-exist'}]},
|
||||
# invalid to set a language for a meta hook
|
||||
{'repo': 'meta', 'hooks': [{'id': 'identity', 'language': 'python'}]},
|
||||
# name override must be string
|
||||
{'repo': 'meta', 'hooks': [{'id': 'identity', 'name': False}]},
|
||||
),
|
||||
)
|
||||
def test_meta_hook_invalid_id(config_repo):
|
||||
with pytest.raises(cfgv.ValidationError):
|
||||
cfgv.validate(config_repo, CONFIG_REPO_DICT)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import pytest
|
|||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit import git
|
||||
from pre_commit.clientlib import load_config
|
||||
from pre_commit.commands.autoupdate import _update_repo
|
||||
from pre_commit.commands.autoupdate import autoupdate
|
||||
from pre_commit.commands.autoupdate import RepositoryCannotBeUpdatedError
|
||||
|
|
@ -17,6 +16,7 @@ from testing.auto_namedtuple import auto_namedtuple
|
|||
from testing.fixtures import add_config_to_repo
|
||||
from testing.fixtures import make_config_from_repo
|
||||
from testing.fixtures import make_repo
|
||||
from testing.fixtures import read_config
|
||||
from testing.fixtures import sample_local_config
|
||||
from testing.fixtures import write_config
|
||||
from testing.util import get_resource_path
|
||||
|
|
@ -319,7 +319,7 @@ def test_autoupdate_local_hooks(in_git_dir, store):
|
|||
config = sample_local_config()
|
||||
add_config_to_repo('.', config)
|
||||
assert autoupdate(C.CONFIG_FILE, store, tags_only=False) == 0
|
||||
new_config_writen = load_config(C.CONFIG_FILE)
|
||||
new_config_writen = read_config('.')
|
||||
assert len(new_config_writen['repos']) == 1
|
||||
assert new_config_writen['repos'][0] == config
|
||||
|
||||
|
|
@ -334,7 +334,7 @@ def test_autoupdate_local_hooks_with_out_of_date_repo(
|
|||
config = {'repos': [local_config, stale_config]}
|
||||
write_config('.', config)
|
||||
assert autoupdate(C.CONFIG_FILE, store, tags_only=False) == 0
|
||||
new_config_writen = load_config(C.CONFIG_FILE)
|
||||
new_config_writen = read_config('.')
|
||||
assert len(new_config_writen['repos']) == 2
|
||||
assert new_config_writen['repos'][0] == local_config
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import os
|
|||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit import git
|
||||
from pre_commit.clientlib import load_config
|
||||
from pre_commit.commands.autoupdate import autoupdate
|
||||
from pre_commit.commands.gc import gc
|
||||
from pre_commit.repository import all_hooks
|
||||
|
|
@ -91,7 +92,7 @@ def test_gc_unused_local_repo_with_env(store, in_git_dir, cap_out):
|
|||
store.mark_config_used(C.CONFIG_FILE)
|
||||
|
||||
# this causes the repositories to be created
|
||||
all_hooks({'repos': [config]}, store)
|
||||
all_hooks(load_config(C.CONFIG_FILE), store)
|
||||
|
||||
assert _config_count(store) == 1
|
||||
assert _repo_count(store) == 1
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@ import os.path
|
|||
import re
|
||||
import shutil
|
||||
|
||||
import cfgv
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
import pre_commit.constants as C
|
||||
from pre_commit import five
|
||||
from pre_commit import parse_shebang
|
||||
from pre_commit.clientlib import CONFIG_REPO_DICT
|
||||
from pre_commit.clientlib import load_manifest
|
||||
from pre_commit.languages import golang
|
||||
from pre_commit.languages import helpers
|
||||
|
|
@ -42,6 +44,8 @@ def _norm_out(b):
|
|||
|
||||
|
||||
def _get_hook(config, store, hook_id):
|
||||
config = cfgv.validate(config, CONFIG_REPO_DICT)
|
||||
config = cfgv.apply_defaults(config, CONFIG_REPO_DICT)
|
||||
hooks = repository_hooks(config, store)
|
||||
install_hook_envs(hooks, store)
|
||||
hook, = [hook for hook in hooks if hook.id == hook_id]
|
||||
|
|
@ -711,17 +715,6 @@ def test_hook_id_not_present(tempdir_factory, store, fake_log_handler):
|
|||
)
|
||||
|
||||
|
||||
def test_meta_hook_not_present(store, fake_log_handler):
|
||||
config = {'repo': 'meta', 'hooks': [{'id': 'i-dont-exist'}]}
|
||||
with pytest.raises(SystemExit):
|
||||
_get_hook(config, store, 'i-dont-exist')
|
||||
assert fake_log_handler.handle.call_args[0][0].msg == (
|
||||
'`i-dont-exist` is not a valid meta hook. '
|
||||
'Typo? Perhaps it is introduced in a newer version? '
|
||||
'Often `pip install --upgrade pre-commit` fixes this.'
|
||||
)
|
||||
|
||||
|
||||
def test_too_new_version(tempdir_factory, store, fake_log_handler):
|
||||
path = make_repo(tempdir_factory, 'script_hooks_repo')
|
||||
with modify_manifest(path) as manifest:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue