From 788ea8e5bf060d80dd01c8f658f5d51d7ca7fc98 Mon Sep 17 00:00:00 2001 From: William Speirs Date: Mon, 3 Oct 2016 12:44:15 -0400 Subject: [PATCH] Added unit test for cli --- jsonschema/tests/test_cli.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/jsonschema/tests/test_cli.py b/jsonschema/tests/test_cli.py index f625ca9..3052de7 100644 --- a/jsonschema/tests/test_cli.py +++ b/jsonschema/tests/test_cli.py @@ -1,6 +1,7 @@ from jsonschema import Draft4Validator, ValidationError, cli from jsonschema.compat import StringIO from jsonschema.tests.compat import mock, unittest +from jsonschema.exceptions import SchemaError def fake_validator(*errors): @@ -14,6 +15,10 @@ def fake_validator(*errors): if errors: return errors.pop() return [] + + def check_schema(self, schema): + return True + return FakeValidator @@ -55,6 +60,26 @@ class TestParser(unittest.TestCase): class TestCLI(unittest.TestCase): + def test_draft3_schema_draft4_validator(self): + stdout, stderr = StringIO(), StringIO() + with self.assertRaises(SchemaError): + exit_code = cli.run( + { + "validator": Draft4Validator, + "schema": { + "anyOf": [ + {"minimum": 20}, + {"type": "string"}, + {"required": True} + ] + }, + "instances": [1], + "error_format": "{error.message}", + }, + stdout=stdout, + stderr=stderr, + ) + def test_successful_validation(self): stdout, stderr = StringIO(), StringIO() exit_code = cli.run(