7
7
import os
8
8
import subprocess
9
9
import sys
10
+ import tempfile
10
11
11
12
from jsonschema import Draft4Validator , Draft7Validator , __version__ , cli
12
13
from jsonschema .exceptions import SchemaError , ValidationError
@@ -683,6 +684,32 @@ def test_successful_validation_of_just_the_schema_pretty_output(self):
683
684
stderr = "" ,
684
685
)
685
686
687
+ def test_successful_validation_with_specifying_base_uri (self ):
688
+ try :
689
+ schema_file = tempfile .NamedTemporaryFile (
690
+ mode = 'w+' ,
691
+ prefix = 'schema' ,
692
+ suffix = '.json' ,
693
+ dir = '..' ,
694
+ delete = False
695
+ )
696
+ self .addCleanup (os .remove , schema_file .name )
697
+ schema = """
698
+ {"type": "object", "properties": {"KEY1":
699
+ {"$ref": %s%s#definitions/schemas"}},
700
+ "definitions": {"schemas": {"type": "string"}}}
701
+ """ % ("\" " , os .path .basename (schema_file .name ))
702
+ schema_file .write (schema )
703
+ finally :
704
+ schema_file .close ()
705
+
706
+ self .assertOutputs (
707
+ files = dict (some_schema = schema , some_instance = '{"KEY1": "1"}' ),
708
+ argv = ["-i" , "some_instance" , "--base-uri" , ".." , "some_schema" ],
709
+ stdout = "" ,
710
+ stderr = "" ,
711
+ )
712
+
686
713
def test_it_validates_using_the_latest_validator_when_unspecified (self ):
687
714
# There isn't a better way now I can think of to ensure that the
688
715
# latest version was used, given that the call to validator_for
@@ -818,4 +845,4 @@ def test_no_arguments_shows_usage_notes(self):
818
845
[sys .executable , "-m" , "jsonschema" , "--help" ],
819
846
stderr = subprocess .STDOUT ,
820
847
)
821
- self .assertEqual (output , output_for_help )
848
+ self .assertEqual (output , output_for_help )
0 commit comments