mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
fix missing context in error for stages
This commit is contained in:
parent
46297f7cd6
commit
aa2961c122
2 changed files with 26 additions and 4 deletions
|
|
@ -116,11 +116,12 @@ class StagesMigrationNoDefault(NamedTuple):
|
|||
if self.key not in dct:
|
||||
return
|
||||
|
||||
val = dct[self.key]
|
||||
cfgv.check_array(cfgv.check_any)(val)
|
||||
with cfgv.validate_context(f'At key: {self.key}'):
|
||||
val = dct[self.key]
|
||||
cfgv.check_array(cfgv.check_any)(val)
|
||||
|
||||
val = [transform_stage(v) for v in val]
|
||||
cfgv.check_array(cfgv.check_one_of(STAGES))(val)
|
||||
val = [transform_stage(v) for v in val]
|
||||
cfgv.check_array(cfgv.check_one_of(STAGES))(val)
|
||||
|
||||
def apply_default(self, dct: dict[str, Any]) -> None:
|
||||
if self.key not in dct:
|
||||
|
|
|
|||
|
|
@ -309,6 +309,27 @@ def test_validate_optional_sensible_regex_at_top_level(caplog, regex, warning):
|
|||
assert caplog.record_tuples == [('pre_commit', logging.WARNING, warning)]
|
||||
|
||||
|
||||
def test_invalid_stages_error():
|
||||
cfg = {'repos': [sample_local_config()]}
|
||||
cfg['repos'][0]['hooks'][0]['stages'] = ['invalid']
|
||||
|
||||
with pytest.raises(cfgv.ValidationError) as excinfo:
|
||||
cfgv.validate(cfg, CONFIG_SCHEMA)
|
||||
|
||||
assert str(excinfo.value) == (
|
||||
'\n'
|
||||
'==> At Config()\n'
|
||||
'==> At key: repos\n'
|
||||
"==> At Repository(repo='local')\n"
|
||||
'==> At key: hooks\n'
|
||||
"==> At Hook(id='do_not_commit')\n"
|
||||
# this line was missing due to the custom validator
|
||||
'==> At key: stages\n'
|
||||
'==> At index 0\n'
|
||||
"=====> Expected one of commit-msg, manual, post-checkout, post-commit, post-merge, post-rewrite, pre-commit, pre-merge-commit, pre-push, pre-rebase, prepare-commit-msg but got: 'invalid'" # noqa: E501
|
||||
)
|
||||
|
||||
|
||||
def test_warning_for_deprecated_stages(caplog):
|
||||
config_obj = sample_local_config()
|
||||
config_obj['hooks'][0]['stages'] = ['commit', 'push']
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue