Skip to content

Commit 788ea8e

Browse files
author
William Speirs
committed
Added unit test for cli
1 parent b44c1a2 commit 788ea8e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

jsonschema/tests/test_cli.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from jsonschema import Draft4Validator, ValidationError, cli
22
from jsonschema.compat import StringIO
33
from jsonschema.tests.compat import mock, unittest
4+
from jsonschema.exceptions import SchemaError
45

56

67
def fake_validator(*errors):
@@ -14,6 +15,10 @@ def iter_errors(self, instance):
1415
if errors:
1516
return errors.pop()
1617
return []
18+
19+
def check_schema(self, schema):
20+
return True
21+
1722
return FakeValidator
1823

1924

@@ -55,6 +60,26 @@ def test_find_validator_in_jsonschema(self):
5560

5661

5762
class TestCLI(unittest.TestCase):
63+
def test_draft3_schema_draft4_validator(self):
64+
stdout, stderr = StringIO(), StringIO()
65+
with self.assertRaises(SchemaError):
66+
exit_code = cli.run(
67+
{
68+
"validator": Draft4Validator,
69+
"schema": {
70+
"anyOf": [
71+
{"minimum": 20},
72+
{"type": "string"},
73+
{"required": True}
74+
]
75+
},
76+
"instances": [1],
77+
"error_format": "{error.message}",
78+
},
79+
stdout=stdout,
80+
stderr=stderr,
81+
)
82+
5883
def test_successful_validation(self):
5984
stdout, stderr = StringIO(), StringIO()
6085
exit_code = cli.run(

0 commit comments

Comments
 (0)