11
11
from jsonschema import Draft4Validator , __version__ , cli
12
12
from jsonschema .exceptions import SchemaError , ValidationError
13
13
from jsonschema .tests ._helpers import captured_output
14
- from jsonschema .validators import validate
14
+ from jsonschema .validators import _LATEST_VERSION , validate , validator_for
15
15
16
16
17
17
def fake_validator (* errors ):
@@ -691,6 +691,47 @@ def test_real_validator(self):
691
691
stderr = "" ,
692
692
)
693
693
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
+
694
735
695
736
class TestParser (TestCase ):
696
737
@@ -717,6 +758,16 @@ def test_find_validator_in_jsonschema(self):
717
758
)
718
759
self .assertIs (arguments ["validator" ], Draft4Validator )
719
760
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
+
720
771
def test_unknown_output (self ):
721
772
# Avoid the help message on stdout
722
773
with captured_output () as (stdout , stderr ):
0 commit comments