Added unit test for cli
This commit is contained in:
parent
b44c1a234d
commit
788ea8e5bf
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue