diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-01-04 07:22:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-01-04 07:22:18 +0000 |
commit | 58a809aa43ae21566be4613eb42ac56faf54f901 (patch) | |
tree | 371b9cc8a265cbabea4b12e5508b8bde6edf0b89 /tests/clientlib_test.py | |
parent | Adding upstream version 2.20.0. (diff) | |
download | pre-commit-58a809aa43ae21566be4613eb42ac56faf54f901.tar.xz pre-commit-58a809aa43ae21566be4613eb42ac56faf54f901.zip |
Adding upstream version 2.21.0.upstream/2.21.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/clientlib_test.py')
-rw-r--r-- | tests/clientlib_test.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/clientlib_test.py b/tests/clientlib_test.py index fb36bb5..b4c3c4e 100644 --- a/tests/clientlib_test.py +++ b/tests/clientlib_test.py @@ -15,6 +15,8 @@ from pre_commit.clientlib import DEFAULT_LANGUAGE_VERSION from pre_commit.clientlib import MANIFEST_SCHEMA from pre_commit.clientlib import META_HOOK_DICT from pre_commit.clientlib import MigrateShaToRev +from pre_commit.clientlib import OptionalSensibleRegexAtHook +from pre_commit.clientlib import OptionalSensibleRegexAtTop from pre_commit.clientlib import validate_config_main from pre_commit.clientlib import validate_manifest_main from testing.fixtures import sample_local_config @@ -262,6 +264,27 @@ def test_warn_mutable_rev_conditional(): @pytest.mark.parametrize( + 'validator_cls', + ( + OptionalSensibleRegexAtHook, + OptionalSensibleRegexAtTop, + ), +) +def test_sensible_regex_validators_dont_pass_none(validator_cls): + key = 'files' + with pytest.raises(cfgv.ValidationError) as excinfo: + validator = validator_cls(key, cfgv.check_string) + validator.check({key: None}) + + assert str(excinfo.value) == ( + '\n' + f'==> At key: {key}' + '\n' + '=====> Expected string got NoneType' + ) + + +@pytest.mark.parametrize( ('regex', 'warning'), ( ( @@ -296,6 +319,22 @@ def test_validate_optional_sensible_regex_at_hook(caplog, regex, warning): assert caplog.record_tuples == [('pre_commit', logging.WARNING, warning)] +def test_validate_optional_sensible_regex_at_local_hook(caplog): + config_obj = sample_local_config() + config_obj['hooks'][0]['files'] = 'dir/*.py' + + cfgv.validate(config_obj, CONFIG_REPO_DICT) + + assert caplog.record_tuples == [ + ( + 'pre_commit', + logging.WARNING, + "The 'files' field in hook 'do_not_commit' is a regex, not a glob " + "-- matching '/*' probably isn't what you want here", + ), + ] + + @pytest.mark.parametrize( ('regex', 'warning'), ( |