mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Enable map configurations (config v2).
This commit is contained in:
parent
ef8347cf2d
commit
3e76cdaf25
11 changed files with 70 additions and 52 deletions
|
|
@ -60,15 +60,15 @@ def test_validate_config_main(args, expected_output):
|
|||
('config_obj', 'expected'), (
|
||||
([], False),
|
||||
(
|
||||
[{
|
||||
{'repos': [{
|
||||
'repo': 'git@github.com:pre-commit/pre-commit-hooks',
|
||||
'sha': 'cd74dc150c142c3be70b24eaf0b02cae9d235f37',
|
||||
'hooks': [{'id': 'pyflakes', 'files': '\\.py$'}],
|
||||
}],
|
||||
}]},
|
||||
True,
|
||||
),
|
||||
(
|
||||
[{
|
||||
{'repos': [{
|
||||
'repo': 'git@github.com:pre-commit/pre-commit-hooks',
|
||||
'sha': 'cd74dc150c142c3be70b24eaf0b02cae9d235f37',
|
||||
'hooks': [
|
||||
|
|
@ -78,11 +78,11 @@ def test_validate_config_main(args, expected_output):
|
|||
'args': ['foo', 'bar', 'baz'],
|
||||
},
|
||||
],
|
||||
}],
|
||||
}]},
|
||||
True,
|
||||
),
|
||||
(
|
||||
[{
|
||||
{'repos': [{
|
||||
'repo': 'git@github.com:pre-commit/pre-commit-hooks',
|
||||
'sha': 'cd74dc150c142c3be70b24eaf0b02cae9d235f37',
|
||||
'hooks': [
|
||||
|
|
@ -94,7 +94,7 @@ def test_validate_config_main(args, expected_output):
|
|||
'args': ['foo', 'bar', 'baz'],
|
||||
},
|
||||
],
|
||||
}],
|
||||
}]},
|
||||
False,
|
||||
),
|
||||
),
|
||||
|
|
@ -104,29 +104,25 @@ def test_config_valid(config_obj, expected):
|
|||
assert ret is expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'config_obj', (
|
||||
[{
|
||||
'repo': 'local',
|
||||
'sha': 'foo',
|
||||
'hooks': [{
|
||||
'id': 'do_not_commit',
|
||||
'name': 'Block if "DO NOT COMMIT" is found',
|
||||
'entry': 'DO NOT COMMIT',
|
||||
'language': 'pcre',
|
||||
'files': '^(.*)$',
|
||||
}],
|
||||
def test_config_with_local_hooks_definition_fails():
|
||||
config_obj = {'repos': [{
|
||||
'repo': 'local',
|
||||
'sha': 'foo',
|
||||
'hooks': [{
|
||||
'id': 'do_not_commit',
|
||||
'name': 'Block if "DO NOT COMMIT" is found',
|
||||
'entry': 'DO NOT COMMIT',
|
||||
'language': 'pcre',
|
||||
'files': '^(.*)$',
|
||||
}],
|
||||
),
|
||||
)
|
||||
def test_config_with_local_hooks_definition_fails(config_obj):
|
||||
}]}
|
||||
with pytest.raises(schema.ValidationError):
|
||||
schema.validate(config_obj, CONFIG_SCHEMA)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'config_obj', (
|
||||
[{
|
||||
{'repos': [{
|
||||
'repo': 'local',
|
||||
'hooks': [{
|
||||
'id': 'arg-per-line',
|
||||
|
|
@ -136,8 +132,8 @@ def test_config_with_local_hooks_definition_fails(config_obj):
|
|||
'files': '',
|
||||
'args': ['hello', 'world'],
|
||||
}],
|
||||
}],
|
||||
[{
|
||||
}]},
|
||||
{'repos': [{
|
||||
'repo': 'local',
|
||||
'hooks': [{
|
||||
'id': 'arg-per-line',
|
||||
|
|
@ -147,7 +143,7 @@ def test_config_with_local_hooks_definition_fails(config_obj):
|
|||
'files': '',
|
||||
'args': ['hello', 'world'],
|
||||
}],
|
||||
}],
|
||||
}]},
|
||||
),
|
||||
)
|
||||
def test_config_with_local_hooks_definition_passes(config_obj):
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ def test_autoupdate_local_hooks(tempdir_factory):
|
|||
assert autoupdate(runner, tags_only=False) == 0
|
||||
new_config_writen = load_config(runner.config_file_path)
|
||||
assert len(new_config_writen) == 1
|
||||
assert new_config_writen[0] == config
|
||||
assert new_config_writen['repos'][0] == config
|
||||
|
||||
|
||||
def test_autoupdate_local_hooks_with_out_of_date_repo(
|
||||
|
|
@ -289,5 +289,5 @@ def test_autoupdate_local_hooks_with_out_of_date_repo(
|
|||
runner = Runner('.', C.CONFIG_FILE)
|
||||
assert autoupdate(runner, tags_only=False) == 0
|
||||
new_config_writen = load_config(runner.config_file_path)
|
||||
assert len(new_config_writen) == 2
|
||||
assert new_config_writen[0] == local_config
|
||||
assert len(new_config_writen['repos']) == 2
|
||||
assert new_config_writen['repos'][0] == local_config
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ def test_always_run(
|
|||
cap_out, repo_with_passing_hook, mock_out_store_directory,
|
||||
):
|
||||
with modify_config() as config:
|
||||
config[0]['hooks'][0]['always_run'] = True
|
||||
config['repos'][0]['hooks'][0]['always_run'] = True
|
||||
_test_run(
|
||||
cap_out,
|
||||
repo_with_passing_hook,
|
||||
|
|
@ -288,7 +288,7 @@ def test_always_run_alt_config(
|
|||
):
|
||||
repo_root = '.'
|
||||
config = read_config(repo_root)
|
||||
config[0]['hooks'][0]['always_run'] = True
|
||||
config['repos'][0]['hooks'][0]['always_run'] = True
|
||||
alt_config_file = 'alternate_config.yaml'
|
||||
add_config_to_repo(repo_root, config, config_file=alt_config_file)
|
||||
|
||||
|
|
@ -428,7 +428,7 @@ def test_multiple_hooks_same_id(
|
|||
with cwd(repo_with_passing_hook):
|
||||
# Add bash hook on there again
|
||||
with modify_config() as config:
|
||||
config[0]['hooks'].append({'id': 'bash_hook'})
|
||||
config['repos'][0]['hooks'].append({'id': 'bash_hook'})
|
||||
stage_a_file()
|
||||
|
||||
ret, output = _do_run(cap_out, repo_with_passing_hook, _get_opts())
|
||||
|
|
@ -455,7 +455,7 @@ def test_stdout_write_bug_py26(
|
|||
):
|
||||
with cwd(repo_with_failing_hook):
|
||||
with modify_config() as config:
|
||||
config[0]['hooks'][0]['args'] = ['☃']
|
||||
config['repos'][0]['hooks'][0]['args'] = ['☃']
|
||||
stage_a_file()
|
||||
|
||||
install(Runner(repo_with_failing_hook, C.CONFIG_FILE))
|
||||
|
|
@ -505,7 +505,7 @@ def test_lots_of_files(mock_out_store_directory, tempdir_factory):
|
|||
with cwd(git_path):
|
||||
# Override files so we run against them
|
||||
with modify_config() as config:
|
||||
config[0]['hooks'][0]['files'] = ''
|
||||
config['repos'][0]['hooks'][0]['files'] = ''
|
||||
|
||||
# Write a crap ton of files
|
||||
for i in range(400):
|
||||
|
|
@ -660,7 +660,7 @@ def test_local_hook_fails(
|
|||
def modified_config_repo(repo_with_passing_hook):
|
||||
with modify_config(repo_with_passing_hook, commit=False) as config:
|
||||
# Some minor modification
|
||||
config[0]['hooks'][0]['files'] = ''
|
||||
config['repos'][0]['hooks'][0]['files'] = ''
|
||||
yield repo_with_passing_hook
|
||||
|
||||
|
||||
|
|
@ -721,8 +721,8 @@ def test_pass_filenames(
|
|||
expected_out,
|
||||
):
|
||||
with modify_config() as config:
|
||||
config[0]['hooks'][0]['pass_filenames'] = pass_filenames
|
||||
config[0]['hooks'][0]['args'] = hook_args
|
||||
config['repos'][0]['hooks'][0]['pass_filenames'] = pass_filenames
|
||||
config['repos'][0]['hooks'][0]['args'] = hook_args
|
||||
stage_a_file()
|
||||
ret, printed = _do_run(
|
||||
cap_out, repo_with_passing_hook, _get_opts(verbose=True),
|
||||
|
|
|
|||
|
|
@ -11,8 +11,9 @@ def test_sample_config(capsys):
|
|||
assert out == '''\
|
||||
# See http://pre-commit.com for more information
|
||||
# See http://pre-commit.com/hooks.html for more hooks
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
sha: v0.9.1
|
||||
sha: v0.9.2
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue