15
15
import jsonschema .validators
16
16
except ImportError :
17
17
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
+ }
18
29
19
30
20
31
ROOT_DIR = os .path .abspath (
@@ -23,6 +34,7 @@ ROOT_DIR = os.path.abspath(
23
34
SUITE_ROOT_DIR = os .path .join (ROOT_DIR , "tests" )
24
35
REMOTES_DIR = os .path .join (ROOT_DIR , "remotes" )
25
36
37
+
26
38
with open (os .path .join (ROOT_DIR , "test-schema.json" )) as schema :
27
39
TESTSUITE_SCHEMA = json .load (schema )
28
40
@@ -114,13 +126,13 @@ class SanityTests(unittest.TestCase):
114
126
115
127
@unittest .skipIf (jsonschema is None , "Validation library not present!" )
116
128
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 ))
121
133
for case in cases (test_files ):
122
134
try :
123
- schema_validator .check_schema (case ["schema" ])
135
+ Validator .check_schema (case ["schema" ])
124
136
except jsonschema .SchemaError as error :
125
137
self .fail ("%s contains an invalid schema (%s)" %
126
138
(case , error ))
0 commit comments