summaryrefslogtreecommitdiffstats
path: root/tests/clientlib_test.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-01-30 06:41:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-01-30 06:41:13 +0000
commit110f2a64b57a8781ccbe1040021d5baaec761e01 (patch)
treed9bf0d538aff0d47e28ea2da949c00955bf920d4 /tests/clientlib_test.py
parentAdding upstream version 2.9.3. (diff)
downloadpre-commit-110f2a64b57a8781ccbe1040021d5baaec761e01.tar.xz
pre-commit-110f2a64b57a8781ccbe1040021d5baaec761e01.zip
Adding upstream version 2.10.0.upstream/2.10.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/clientlib_test.py')
-rw-r--r--tests/clientlib_test.py97
1 files changed, 96 insertions, 1 deletions
diff --git a/tests/clientlib_test.py b/tests/clientlib_test.py
index bfb754b..6bdb0d6 100644
--- a/tests/clientlib_test.py
+++ b/tests/clientlib_test.py
@@ -166,7 +166,85 @@ def test_validate_warn_on_unknown_keys_at_top_level(tmpdir, caplog):
]
-def test_validate_optional_sensible_regex(caplog):
+def test_ci_map_key_allowed_at_top_level(caplog):
+ cfg = {
+ 'ci': {'skip': ['foo']},
+ 'repos': [{'repo': 'meta', 'hooks': [{'id': 'identity'}]}],
+ }
+ cfgv.validate(cfg, CONFIG_SCHEMA)
+ assert not caplog.record_tuples
+
+
+def test_ci_key_must_be_map():
+ with pytest.raises(cfgv.ValidationError):
+ cfgv.validate({'ci': 'invalid', 'repos': []}, CONFIG_SCHEMA)
+
+
+@pytest.mark.parametrize(
+ 'rev',
+ (
+ 'v0.12.4',
+ 'b27f281',
+ 'b27f281eb9398fc8504415d7fbdabf119ea8c5e1',
+ '19.10b0',
+ '4.3.21-2',
+ ),
+)
+def test_warn_mutable_rev_ok(caplog, rev):
+ config_obj = {
+ 'repo': 'https://gitlab.com/pycqa/flake8',
+ 'rev': rev,
+ 'hooks': [{'id': 'flake8'}],
+ }
+ cfgv.validate(config_obj, CONFIG_REPO_DICT)
+
+ assert caplog.record_tuples == []
+
+
+@pytest.mark.parametrize(
+ 'rev',
+ (
+ '',
+ 'HEAD',
+ 'stable',
+ 'master',
+ 'some_branch_name',
+ ),
+)
+def test_warn_mutable_rev_invalid(caplog, rev):
+ config_obj = {
+ 'repo': 'https://gitlab.com/pycqa/flake8',
+ 'rev': rev,
+ 'hooks': [{'id': 'flake8'}],
+ }
+ cfgv.validate(config_obj, CONFIG_REPO_DICT)
+
+ assert caplog.record_tuples == [
+ (
+ 'pre_commit',
+ logging.WARNING,
+ "The 'rev' field of repo 'https://gitlab.com/pycqa/flake8' "
+ 'appears to be a mutable reference (moving tag / branch). '
+ 'Mutable references are never updated after first install and are '
+ 'not supported. '
+ 'See https://pre-commit.com/#using-the-latest-version-for-a-repository ' # noqa: E501
+ 'for more details.',
+ ),
+ ]
+
+
+def test_warn_mutable_rev_conditional():
+ config_obj = {
+ 'repo': 'meta',
+ 'rev': '3.7.7',
+ 'hooks': [{'id': 'flake8'}],
+ }
+
+ with pytest.raises(cfgv.ValidationError):
+ cfgv.validate(config_obj, CONFIG_REPO_DICT)
+
+
+def test_validate_optional_sensible_regex_at_hook_level(caplog):
config_obj = {
'id': 'flake8',
'files': 'dir/*.py',
@@ -183,6 +261,23 @@ def test_validate_optional_sensible_regex(caplog):
]
+def test_validate_optional_sensible_regex_at_top_level(caplog):
+ config_obj = {
+ 'files': 'dir/*.py',
+ 'repos': [],
+ }
+ cfgv.validate(config_obj, CONFIG_SCHEMA)
+
+ assert caplog.record_tuples == [
+ (
+ 'pre_commit',
+ logging.WARNING,
+ "The top-level 'files' field is a regex, not a glob -- matching "
+ "'/*' probably isn't what you want here",
+ ),
+ ]
+
+
@pytest.mark.parametrize('fn', (validate_config_main, validate_manifest_main))
def test_mains_not_ok(tmpdir, fn):
not_yaml = tmpdir.join('f.notyaml')