| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,11 +116,12 @@ def check(self, dct: dict[str, Any]) -> None: | |||
| 116 | 116 | if self.key not in dct: | |
| 117 | 117 | return | |
| 118 | 118 | ||
| 119 | - val = dct[self.key] | ||
| 120 | - cfgv.check_array(cfgv.check_any)(val) | ||
| 119 | + with cfgv.validate_context(f'At key: {self.key}'): | ||
| 120 | + val = dct[self.key] | ||
| 121 | + cfgv.check_array(cfgv.check_any)(val) | ||
| 121 | 122 | ||
| 122 | - val = [transform_stage(v) for v in val] | ||
| 123 | - cfgv.check_array(cfgv.check_one_of(STAGES))(val) | ||
| 123 | + val = [transform_stage(v) for v in val] | ||
| 124 | + cfgv.check_array(cfgv.check_one_of(STAGES))(val) | ||
| 124 | 125 | ||
| 125 | 126 | def apply_default(self, dct: dict[str, Any]) -> None: | |
| 126 | 127 | if self.key not in dct: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -309,6 +309,27 @@ def test_validate_optional_sensible_regex_at_top_level(caplog, regex, warning): | |||
| 309 | 309 | assert caplog.record_tuples == [('pre_commit', logging.WARNING, warning)] | |
| 310 | 310 | ||
| 311 | 311 | ||
| 312 | + def test_invalid_stages_error(): | ||
| 313 | + cfg = {'repos': [sample_local_config()]} | ||
| 314 | + cfg['repos'][0]['hooks'][0]['stages'] = ['invalid'] | ||
| 315 | + | ||
| 316 | + with pytest.raises(cfgv.ValidationError) as excinfo: | ||
| 317 | + cfgv.validate(cfg, CONFIG_SCHEMA) | ||
| 318 | + | ||
| 319 | + assert str(excinfo.value) == ( | ||
| 320 | + '\n' | ||
| 321 | + '==> At Config()\n' | ||
| 322 | + '==> At key: repos\n' | ||
| 323 | + "==> At Repository(repo='local')\n" | ||
| 324 | + '==> At key: hooks\n' | ||
| 325 | + "==> At Hook(id='do_not_commit')\n" | ||
| 326 | + # this line was missing due to the custom validator | ||
| 327 | + '==> At key: stages\n' | ||
| 328 | + '==> At index 0\n' | ||
| 329 | + "=====> 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 | ||
| 330 | + ) | ||
| 331 | + | ||
| 332 | + | ||
| 312 | 333 | def test_warning_for_deprecated_stages(caplog): | |
| 313 | 334 | config_obj = sample_local_config() | |
| 314 | 335 | config_obj['hooks'][0]['stages'] = ['commit', 'push'] | |
| Back | FazBrowse Home | New Git URL |
0 commit comments