Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 914a74f

Browse files
committed
Make language check more strict.
1 parent fdd6989 commit 914a74f

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

pre_commit/clientlib/validate_manifest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def additional_manifest_check(obj):
3131
for hook_config in obj:
3232
language = hook_config['language']
3333

34-
if not any(language.startswith(lang) for lang in all_languages):
34+
if language not in all_languages:
3535
raise InvalidManifestError(
36-
'Expected language {0} for {1} to start with one of {2!r}'.format(
36+
'Expected language {0} for {1} to be one of {2!r}'.format(
3737
hook_config['id'],
3838
hook_config['language'],
3939
all_languages,

tests/clientlib/validate_manifest_test.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,25 @@ def test_additional_manifest_check_raises_for_bad_language():
2727
additional_manifest_check([{'id': 'foo', 'language': 'not valid'}])
2828

2929

30-
@pytest.mark.parametrize(('obj'), (
31-
[{'language': 'python'}],
32-
[{'language': 'ruby'}],
33-
))
30+
@pytest.mark.parametrize(
31+
'obj', ([{'language': 'python'}], [{'language': 'ruby'}]),
32+
)
3433
def test_additional_manifest_check_languages(obj):
3534
additional_manifest_check(obj)
3635

3736

37+
@pytest.mark.parametrize(
38+
'obj',
39+
(
40+
[{'id': 'a', 'language': 'not a language'}],
41+
[{'id': 'a', 'language': 'python3'}],
42+
),
43+
)
44+
def test_additional_manifest_check_languages_failing(obj):
45+
with pytest.raises(InvalidManifestError):
46+
additional_manifest_check(obj)
47+
48+
3849
@pytest.mark.parametrize(('manifest_obj', 'expected'), (
3950
([], False),
4051
([{'id': 'a', 'name': 'b', 'entry': 'c', 'language': 'python'}], True),

0 commit comments

Comments
 (0)