mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Make language check more strict.
This commit is contained in:
parent
fdd6989ece
commit
914a74f80b
2 changed files with 17 additions and 6 deletions
|
|
@ -31,9 +31,9 @@ def additional_manifest_check(obj):
|
||||||
for hook_config in obj:
|
for hook_config in obj:
|
||||||
language = hook_config['language']
|
language = hook_config['language']
|
||||||
|
|
||||||
if not any(language.startswith(lang) for lang in all_languages):
|
if language not in all_languages:
|
||||||
raise InvalidManifestError(
|
raise InvalidManifestError(
|
||||||
'Expected language {0} for {1} to start with one of {2!r}'.format(
|
'Expected language {0} for {1} to be one of {2!r}'.format(
|
||||||
hook_config['id'],
|
hook_config['id'],
|
||||||
hook_config['language'],
|
hook_config['language'],
|
||||||
all_languages,
|
all_languages,
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,25 @@ def test_additional_manifest_check_raises_for_bad_language():
|
||||||
additional_manifest_check([{'id': 'foo', 'language': 'not valid'}])
|
additional_manifest_check([{'id': 'foo', 'language': 'not valid'}])
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(('obj'), (
|
@pytest.mark.parametrize(
|
||||||
[{'language': 'python'}],
|
'obj', ([{'language': 'python'}], [{'language': 'ruby'}]),
|
||||||
[{'language': 'ruby'}],
|
)
|
||||||
))
|
|
||||||
def test_additional_manifest_check_languages(obj):
|
def test_additional_manifest_check_languages(obj):
|
||||||
additional_manifest_check(obj)
|
additional_manifest_check(obj)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'obj',
|
||||||
|
(
|
||||||
|
[{'id': 'a', 'language': 'not a language'}],
|
||||||
|
[{'id': 'a', 'language': 'python3'}],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_additional_manifest_check_languages_failing(obj):
|
||||||
|
with pytest.raises(InvalidManifestError):
|
||||||
|
additional_manifest_check(obj)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(('manifest_obj', 'expected'), (
|
@pytest.mark.parametrize(('manifest_obj', 'expected'), (
|
||||||
([], False),
|
([], False),
|
||||||
([{'id': 'a', 'name': 'b', 'entry': 'c', 'language': 'python'}], True),
|
([{'id': 'a', 'name': 'b', 'entry': 'c', 'language': 'python'}], True),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue