@@ -31,12 +31,49 @@ def cases(paths):
31
31
yield test
32
32
33
33
34
+ def errortree_messages (et , path = "" ):
35
+ for e in et .errors .values ():
36
+ yield "%s: %s" % (path , e )
37
+ for key in et :
38
+ for msg in errortree_messages (et [key ], "%s/%s" % (path , key )):
39
+ yield msg
40
+
41
+
42
+ TESTSUITE_SCHEMA = {
43
+ "$schema" : "http://json-schema.org/draft-03/schema#" ,
44
+ "type" : "array" ,
45
+ "items" : {
46
+ "type" : "object" ,
47
+ "properties" : {
48
+ "description" : {"type" : "string" , "required" : True },
49
+ "schema" : {"required" : True },
50
+ "tests" : {
51
+ "type" : "array" ,
52
+ "items" : {
53
+ "type" : "object" ,
54
+ "properties" : {
55
+ "description" : {"type" : "string" , "required" : True },
56
+ "data" : {"required" : True },
57
+ "valid" : {"type" : "boolean" , "required" : True }
58
+ },
59
+ "additionalProperties" : False
60
+ },
61
+ "minItems" : 1
62
+ }
63
+ },
64
+ "additionalProperties" : False ,
65
+ "minItems" : 1
66
+ }
67
+ }
68
+
69
+
34
70
class SanityTests (TestCase ):
35
71
@classmethod
36
72
def setUpClass (cls ):
37
- test_glob = os .path .join (SUITE_ROOT_DIR , "*/*.json" )
38
- logging .info ("Looking for tests in %s" , test_glob )
39
- cls .test_files = glob (test_glob )
73
+ logging .info ("Looking for tests in %s" , SUITE_ROOT_DIR )
74
+ cls .test_files = []
75
+ for root , dirs , files in os .walk (SUITE_ROOT_DIR ):
76
+ cls .test_files .extend (glob (os .path .join (root , "*.json" )))
40
77
logging .info ("Found %s test files" , len (cls .test_files ))
41
78
assert cls .test_files , "Didn't find the test files!"
42
79
@@ -56,6 +93,18 @@ class SanityTests(TestCase):
56
93
descriptions = {test ["description" ] for test in group ["tests" ]}
57
94
self .assertEqual (len (descriptions ), len (group ["tests" ]))
58
95
96
+ def test_suites_are_valid (self ):
97
+ validator = jsonschema .Draft3Validator (TESTSUITE_SCHEMA )
98
+ for root , dirs , files in os .walk (SUITE_ROOT_DIR ):
99
+ for f in glob (os .path .join (root , "*.json" )):
100
+ with open (f ) as test_file :
101
+ test_data = json .load (test_file )
102
+ errortree = jsonschema .ErrorTree (validator .iter_errors (test_data ))
103
+ msg = "Test suite '%s' does not follow the test format:\n " % f
104
+ msg += "\n " .join ("\t " + e for e in errortree_messages (errortree ))
105
+ assert not len (errortree ), msg
106
+
107
+
59
108
60
109
if __name__ == "__main__" :
61
110
from unittest import main
0 commit comments