summaryrefslogtreecommitdiffstats
path: root/tests/clientlib_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/clientlib_test.py')
-rw-r--r--tests/clientlib_test.py136
1 files changed, 7 insertions, 129 deletions
diff --git a/tests/clientlib_test.py b/tests/clientlib_test.py
index b4c3c4e..efb2aa8 100644
--- a/tests/clientlib_test.py
+++ b/tests/clientlib_test.py
@@ -14,11 +14,9 @@ from pre_commit.clientlib import CONFIG_SCHEMA
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 pre_commit.clientlib import parse_version
from testing.fixtures import sample_local_config
@@ -112,78 +110,6 @@ def test_config_schema_does_not_contain_defaults():
assert not isinstance(item, cfgv.Optional)
-def test_validate_manifest_main_ok():
- assert not validate_manifest_main(('.pre-commit-hooks.yaml',))
-
-
-def test_validate_config_main_ok():
- assert not validate_config_main(('.pre-commit-config.yaml',))
-
-
-def test_validate_config_old_list_format_ok(tmpdir, cap_out):
- f = tmpdir.join('cfg.yaml')
- f.write('- {repo: meta, hooks: [{id: identity}]}')
- assert not validate_config_main((f.strpath,))
- msg = '[WARNING] normalizing pre-commit configuration to a top-level map'
- assert msg in cap_out.get()
-
-
-def test_validate_warn_on_unknown_keys_at_repo_level(tmpdir, caplog):
- f = tmpdir.join('cfg.yaml')
- f.write(
- 'repos:\n'
- '- repo: https://gitlab.com/pycqa/flake8\n'
- ' rev: 3.7.7\n'
- ' hooks:\n'
- ' - id: flake8\n'
- ' args: [--some-args]\n',
- )
- ret_val = validate_config_main((f.strpath,))
- assert not ret_val
- assert caplog.record_tuples == [
- (
- 'pre_commit',
- logging.WARNING,
- 'pre-commit-validate-config is deprecated -- '
- 'use `pre-commit validate-config` instead.',
- ),
- (
- 'pre_commit',
- logging.WARNING,
- 'Unexpected key(s) present on https://gitlab.com/pycqa/flake8: '
- 'args',
- ),
- ]
-
-
-def test_validate_warn_on_unknown_keys_at_top_level(tmpdir, caplog):
- f = tmpdir.join('cfg.yaml')
- f.write(
- 'repos:\n'
- '- repo: https://gitlab.com/pycqa/flake8\n'
- ' rev: 3.7.7\n'
- ' hooks:\n'
- ' - id: flake8\n'
- 'foo:\n'
- ' id: 1.0.0\n',
- )
- ret_val = validate_config_main((f.strpath,))
- assert not ret_val
- assert caplog.record_tuples == [
- (
- 'pre_commit',
- logging.WARNING,
- 'pre-commit-validate-config is deprecated -- '
- 'use `pre-commit validate-config` instead.',
- ),
- (
- 'pre_commit',
- logging.WARNING,
- 'Unexpected key(s) present at root: foo',
- ),
- ]
-
-
def test_ci_map_key_allowed_at_top_level(caplog):
cfg = {
'ci': {'skip': ['foo']},
@@ -370,18 +296,6 @@ def test_validate_optional_sensible_regex_at_top_level(caplog, regex, warning):
assert caplog.record_tuples == [('pre_commit', logging.WARNING, warning)]
-@pytest.mark.parametrize('fn', (validate_config_main, validate_manifest_main))
-def test_mains_not_ok(tmpdir, fn):
- not_yaml = tmpdir.join('f.notyaml')
- not_yaml.write('{')
- not_schema = tmpdir.join('notconfig.yaml')
- not_schema.write('{}')
-
- assert fn(('does-not-exist',))
- assert fn((not_yaml.strpath,))
- assert fn((not_schema.strpath,))
-
-
@pytest.mark.parametrize(
('manifest_obj', 'expected'),
(
@@ -426,48 +340,6 @@ def test_valid_manifests(manifest_obj, expected):
@pytest.mark.parametrize(
- 'dct',
- (
- {'repo': 'local'}, {'repo': 'meta'},
- {'repo': 'wat', 'sha': 'wat'}, {'repo': 'wat', 'rev': 'wat'},
- ),
-)
-def test_migrate_sha_to_rev_ok(dct):
- MigrateShaToRev().check(dct)
-
-
-def test_migrate_sha_to_rev_dont_specify_both():
- with pytest.raises(cfgv.ValidationError) as excinfo:
- MigrateShaToRev().check({'repo': 'a', 'sha': 'b', 'rev': 'c'})
- msg, = excinfo.value.args
- assert msg == 'Cannot specify both sha and rev'
-
-
-@pytest.mark.parametrize(
- 'dct',
- (
- {'repo': 'a'},
- {'repo': 'meta', 'sha': 'a'}, {'repo': 'meta', 'rev': 'a'},
- ),
-)
-def test_migrate_sha_to_rev_conditional_check_failures(dct):
- with pytest.raises(cfgv.ValidationError):
- MigrateShaToRev().check(dct)
-
-
-def test_migrate_to_sha_apply_default():
- dct = {'repo': 'a', 'sha': 'b'}
- MigrateShaToRev().apply_default(dct)
- assert dct == {'repo': 'a', 'rev': 'b'}
-
-
-def test_migrate_to_sha_ok():
- dct = {'repo': 'a', 'rev': 'b'}
- MigrateShaToRev().apply_default(dct)
- assert dct == {'repo': 'a', 'rev': 'b'}
-
-
-@pytest.mark.parametrize(
'config_repo',
(
# i-dont-exist isn't a valid hook
@@ -513,6 +385,12 @@ def test_default_language_version_invalid(mapping):
cfgv.validate(mapping, DEFAULT_LANGUAGE_VERSION)
+def test_parse_version():
+ assert parse_version('0.0') == parse_version('0.0')
+ assert parse_version('0.1') > parse_version('0.0')
+ assert parse_version('2.1') >= parse_version('2')
+
+
def test_minimum_pre_commit_version_failing():
with pytest.raises(cfgv.ValidationError) as excinfo:
cfg = {'repos': [], 'minimum_pre_commit_version': '999'}