mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-16 05:09:53 -06:00
Add better tests for manifest json schema
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
|
||||
import jsonschema
|
||||
import jsonschema.exceptions
|
||||
import pytest
|
||||
|
||||
from pre_commit.clientlib.validate_manifest import additional_manifest_check
|
||||
from pre_commit.clientlib.validate_manifest import InvalidManifestError
|
||||
from pre_commit.clientlib.validate_manifest import MANIFEST_JSON_SCHEMA
|
||||
from pre_commit.clientlib.validate_manifest import run
|
||||
|
||||
|
||||
@@ -29,4 +32,31 @@ def test_additional_manifest_check_raises_for_bad_language():
|
||||
[{'language': 'python>2.6'}],
|
||||
))
|
||||
def test_additional_manifest_check_is_ok_with_missing_language(obj):
|
||||
additional_manifest_check(obj)
|
||||
additional_manifest_check(obj)
|
||||
|
||||
|
||||
def is_valid_according_to_schema(obj, schema):
|
||||
try:
|
||||
jsonschema.validate(obj, schema)
|
||||
return True
|
||||
except jsonschema.exceptions.ValidationError:
|
||||
return False
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('manifest_obj', 'expected'), (
|
||||
([], False),
|
||||
([{'id': 'a', 'name': 'b', 'entry': 'c'}], True),
|
||||
(
|
||||
[{
|
||||
'id': 'a',
|
||||
'name': 'b',
|
||||
'entry': 'c',
|
||||
'language': 'python',
|
||||
'expected_return_value': 0,
|
||||
}],
|
||||
True,
|
||||
),
|
||||
))
|
||||
def test_is_valid_according_to_schema(manifest_obj, expected):
|
||||
ret = is_valid_according_to_schema(manifest_obj, MANIFEST_JSON_SCHEMA)
|
||||
assert ret is expected
|
||||
Reference in New Issue
Block a user