mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #2658 from pre-commit/remove-pre-commit-validate
remove pre-commit-validate-config and pre-commit-validate-manifest
This commit is contained in:
commit
848a73ed40
7 changed files with 88 additions and 121 deletions
|
|
@ -16,8 +16,6 @@ from pre_commit.clientlib import MANIFEST_SCHEMA
|
|||
from pre_commit.clientlib import META_HOOK_DICT
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -111,70 +109,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_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']},
|
||||
|
|
@ -361,18 +295,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'),
|
||||
(
|
||||
|
|
|
|||
64
tests/commands/validate_config_test.py
Normal file
64
tests/commands/validate_config_test.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from pre_commit.commands.validate_config import validate_config
|
||||
|
||||
|
||||
def test_validate_config_ok():
|
||||
assert not validate_config(('.pre-commit-config.yaml',))
|
||||
|
||||
|
||||
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((f.strpath,))
|
||||
assert not ret_val
|
||||
assert caplog.record_tuples == [
|
||||
(
|
||||
'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((f.strpath,))
|
||||
assert not ret_val
|
||||
assert caplog.record_tuples == [
|
||||
(
|
||||
'pre_commit',
|
||||
logging.WARNING,
|
||||
'Unexpected key(s) present at root: foo',
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def test_mains_not_ok(tmpdir):
|
||||
not_yaml = tmpdir.join('f.notyaml')
|
||||
not_yaml.write('{')
|
||||
not_schema = tmpdir.join('notconfig.yaml')
|
||||
not_schema.write('{}')
|
||||
|
||||
assert validate_config(('does-not-exist',))
|
||||
assert validate_config((not_yaml.strpath,))
|
||||
assert validate_config((not_schema.strpath,))
|
||||
18
tests/commands/validate_manifest_test.py
Normal file
18
tests/commands/validate_manifest_test.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from pre_commit.commands.validate_manifest import validate_manifest
|
||||
|
||||
|
||||
def test_validate_manifest_ok():
|
||||
assert not validate_manifest(('.pre-commit-hooks.yaml',))
|
||||
|
||||
|
||||
def test_not_ok(tmpdir):
|
||||
not_yaml = tmpdir.join('f.notyaml')
|
||||
not_yaml.write('{')
|
||||
not_schema = tmpdir.join('notconfig.yaml')
|
||||
not_schema.write('{}')
|
||||
|
||||
assert validate_manifest(('does-not-exist',))
|
||||
assert validate_manifest((not_yaml.strpath,))
|
||||
assert validate_manifest((not_schema.strpath,))
|
||||
Loading…
Add table
Add a link
Reference in a new issue