
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 run


def test_returns_0_for_valid_manifest():
    assert run(['example_manifest.yaml']) == 0


def test_returns_0_for_our_manifest():
    assert run([]) == 0


def test_returns_1_for_failing():
    assert run(['tests/data/valid_yaml_but_invalid_manifest.yaml']) == 1


def test_additional_manifest_check_raises_for_bad_language():
    with pytest.raises(InvalidManifestError):
        additional_manifest_check([{'id': 'foo', 'language': 'not valid'}])


@pytest.mark.parametrize(('obj'), (
    [{}],
    [{'language': 'python'}],
    [{'language': 'python>2.6'}],
))
def test_additional_manifest_check_is_ok_with_missing_language(obj):
    additional_manifest_check(obj)
@@ -1,8 +1,55 @@
+%0Aimport jsonschema%0Aimport jsonschema.exceptions
 %0Aimport 
@@ -55,16 +55,16 @@
  pytest%0A
-
 %0Afrom pr
@@ -205,16 +205,88 @@
 stError%0A
+from pre_commit.clientlib.validate_manifest import MANIFEST_JSON_SCHEMA%0A
 from pre
@@ -966,16 +966,16 @@
 e(obj):%0A
-
     addi
@@ -996,12 +996,703 @@
 t_check(obj)
+%0A%0A%0Adef is_valid_according_to_schema(obj, schema):%0A    try:%0A        jsonschema.validate(obj, schema)%0A        return True%0A    except jsonschema.exceptions.ValidationError:%0A        return False%0A%0A%0A@pytest.mark.parametrize(('manifest_obj', 'expected'), (%0A    (%5B%5D, False),%0A    (%5B%7B'id': 'a', 'name': 'b', 'entry': 'c'%7D%5D, True),%0A    (%0A        %5B%7B%0A             'id': 'a',%0A             'name': 'b',%0A             'entry': 'c',%0A             'language': 'python',%0A             'expected_return_value': 0,%0A        %7D%5D,%0A        True,%0A    ),%0A))%0Adef test_is_valid_according_to_schema(manifest_obj, expected):%0A    ret = is_valid_according_to_schema(manifest_obj, MANIFEST_JSON_SCHEMA)%0A    assert ret is expected

Add better tests for manifest json schema