1515 import jsonschema .validators
1616except ImportError :
1717 jsonschema = None
18+ VALIDATORS = {}
19+ else :
20+ VALIDATORS = {
21+ "draft3" : jsonschema .validators .Draft3Validator ,
22+ "draft4" : jsonschema .validators .Draft4Validator ,
23+ "draft6" : jsonschema .validators .Draft6Validator ,
24+ "draft7" : jsonschema .validators .Draft7Validator ,
25+ "draft2019-09" : jsonschema .validators .Draft201909Validator ,
26+ "draft2020-12" : jsonschema .validators .Draft202012Validator ,
27+ "latest" : jsonschema .validators .Draft202012Validator ,
28+ }
1829
1930
2031ROOT_DIR = os .path .abspath (
@@ -23,6 +34,7 @@ ROOT_DIR = os.path.abspath(
2334SUITE_ROOT_DIR = os .path .join (ROOT_DIR , "tests" )
2435REMOTES_DIR = os .path .join (ROOT_DIR , "remotes" )
2536
37+
2638with open (os .path .join (ROOT_DIR , "test-schema.json" )) as schema :
2739 TESTSUITE_SCHEMA = json .load (schema )
2840
@@ -114,13 +126,13 @@ class SanityTests(unittest.TestCase):
114126
115127 @unittest .skipIf (jsonschema is None , "Validation library not present!" )
116128 def test_all_schemas_are_valid (self ):
117- for schema in os .listdir (SUITE_ROOT_DIR ):
118- schema_validator = jsonschema . validators . validators . get (schema )
119- if schema_validator is not None :
120- test_files = collect (os .path .join (SUITE_ROOT_DIR , schema ))
129+ for version in os .listdir (SUITE_ROOT_DIR ):
130+ Validator = VALIDATORS . get (version )
131+ if Validator is not None :
132+ test_files = collect (os .path .join (SUITE_ROOT_DIR , version ))
121133 for case in cases (test_files ):
122134 try :
123- schema_validator .check_schema (case ["schema" ])
135+ Validator .check_schema (case ["schema" ])
124136 except jsonschema .SchemaError as error :
125137 self .fail ("%s contains an invalid schema (%s)" %
126138 (case , error ))
0 commit comments