Skip to content

Commit dc50921

Browse files
committed
add test case
1 parent 5680761 commit dc50921

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

jsonschema/tests/test_cli.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from jsonschema import Draft4Validator, __version__, cli
1212
from jsonschema.exceptions import SchemaError, ValidationError
1313
from jsonschema.tests._helpers import captured_output
14-
from jsonschema.validators import validate
14+
from jsonschema.validators import _LATEST_VERSION, validate, validator_for
1515

1616

1717
def fake_validator(*errors):
@@ -691,6 +691,47 @@ def test_real_validator(self):
691691
stderr="",
692692
)
693693

694+
def test_draft07_check_const(self):
695+
schema = """
696+
{
697+
"$schema": "http://json-schema.org/draft-07/schema#",
698+
"properties": {
699+
"value": {
700+
"type": "string",
701+
"const": "check"
702+
}
703+
}
704+
}
705+
"""
706+
instance = """{"value": "2"}"""
707+
self.assertOutputs(
708+
files=dict(some_schema=schema, some_instance=instance),
709+
argv=["-i", "some_instance", "some_schema"],
710+
exit_code=1,
711+
stdout="",
712+
stderr="2: 'check' was expected\n",
713+
)
714+
715+
def test_draft04_not_check_const(self):
716+
schema = """
717+
{
718+
"$schema": "http://json-schema.org/draft-04/schema#",
719+
"properties": {
720+
"value": {
721+
"type": "string",
722+
"const": "check"
723+
}
724+
}
725+
}
726+
"""
727+
instance = """{"value": "2"}"""
728+
self.assertOutputs(
729+
files=dict(some_schema=schema, some_instance=instance),
730+
argv=["-i", "some_instance", "some_schema"],
731+
stdout="",
732+
stderr="",
733+
)
734+
694735

695736
class TestParser(TestCase):
696737

@@ -717,6 +758,16 @@ def test_find_validator_in_jsonschema(self):
717758
)
718759
self.assertIs(arguments["validator"], Draft4Validator)
719760

761+
def test_latest_validator_is_the_default(self):
762+
arguments = cli.parse_args(
763+
[
764+
"--instance", "mem://some/instance",
765+
"mem://some/schema",
766+
]
767+
)
768+
arguments["validator"] = validator_for(arguments["schema"])
769+
self.assertIs(arguments["validator"], _LATEST_VERSION)
770+
720771
def test_unknown_output(self):
721772
# Avoid the help message on stdout
722773
with captured_output() as (stdout, stderr):

0 commit comments

Comments
 (0)