@@ -30,11 +30,13 @@ else:
30
30
31
31
ROOT_DIR = Path (__file__ ).parent .parent
32
32
SUITE_ROOT_DIR = ROOT_DIR / "tests"
33
+ OUTPUT_ROOT_DIR = ROOT_DIR / "output-tests"
33
34
34
35
REMOTES_DIR = ROOT_DIR / "remotes"
35
36
REMOTES_BASE_URL = "http://localhost:1234/"
36
37
37
38
TESTSUITE_SCHEMA = json .loads ((ROOT_DIR / "test-schema.json" ).read_text ())
39
+ OUTPUTTESTSUITE_SCHEMA = json .loads ((ROOT_DIR / "output-test-schema.json" ).read_text ())
38
40
39
41
40
42
def files (paths ):
@@ -88,12 +90,17 @@ class SanityTests(unittest.TestCase):
88
90
@classmethod
89
91
def setUpClass (cls ):
90
92
print (f"Looking for tests in { SUITE_ROOT_DIR } " )
93
+ print (f"Looking for output tests in { OUTPUT_ROOT_DIR } " )
91
94
print (f"Looking for remotes in { REMOTES_DIR } " )
92
95
93
96
cls .test_files = list (collect (SUITE_ROOT_DIR ))
94
97
assert cls .test_files , "Didn't find the test files!"
95
98
print (f"Found { len (cls .test_files )} test files" )
96
99
100
+ cls .output_test_files = list (collect (OUTPUT_ROOT_DIR ))
101
+ assert cls .remote_files , "Didn't find the output test files!"
102
+ print (f"Found { len (cls .remote_files )} output test files" )
103
+
97
104
cls .remote_files = list (collect (REMOTES_DIR ))
98
105
assert cls .remote_files , "Didn't find the remote files!"
99
106
print (f"Found { len (cls .remote_files )} remote files" )
@@ -142,6 +149,17 @@ class SanityTests(unittest.TestCase):
142
149
except ValueError as error :
143
150
self .fail (f"{ path } contains invalid JSON ({ error } )" )
144
151
152
+ def test_all_output_test_files_are_valid_json (self ):
153
+ """
154
+ All test files contain valid JSON.
155
+ """
156
+ for path in self .output_test_files :
157
+ with self .subTest (path = path ):
158
+ try :
159
+ json .loads (path .read_text ())
160
+ except ValueError as error :
161
+ self .fail (f"{ path } contains invalid JSON ({ error } )" )
162
+
145
163
def test_all_remote_files_are_valid_json (self ):
146
164
"""
147
165
All remote files contain valid JSON.
@@ -157,7 +175,7 @@ class SanityTests(unittest.TestCase):
157
175
"""
158
176
All cases have reasonably long descriptions.
159
177
"""
160
- for case in cases (self .test_files ):
178
+ for case in cases (self .test_files + self . output_test_files ):
161
179
with self .subTest (description = case ["description" ]):
162
180
self .assertLess (
163
181
len (case ["description" ]),
@@ -169,7 +187,7 @@ class SanityTests(unittest.TestCase):
169
187
"""
170
188
All tests have reasonably long descriptions.
171
189
"""
172
- for count , test in enumerate (tests (self .test_files )):
190
+ for count , test in enumerate (tests (self .test_files + self . output_test_files )):
173
191
with self .subTest (description = test ["description" ]):
174
192
self .assertLess (
175
193
len (test ["description" ]),
@@ -182,28 +200,28 @@ class SanityTests(unittest.TestCase):
182
200
"""
183
201
All cases have unique descriptions in their files.
184
202
"""
185
- for path , cases in files (self .test_files ):
203
+ for path , cases in files (self .test_files + self . output_test_files ):
186
204
with self .subTest (path = path ):
187
205
self .assertUnique (case ["description" ] for case in cases )
188
206
189
207
def test_all_test_descriptions_are_unique (self ):
190
208
"""
191
209
All test cases have unique test descriptions in their tests.
192
210
"""
193
- for count , case in enumerate (cases (self .test_files )):
211
+ for count , case in enumerate (cases (self .test_files + self . output_test_files )):
194
212
with self .subTest (description = case ["description" ]):
195
213
self .assertUnique (
196
214
test ["description" ] for test in case ["tests" ]
197
215
)
198
216
print (f"Found { count } test cases." )
199
217
200
218
def test_case_descriptions_do_not_use_modal_verbs (self ):
201
- for case in cases (self .test_files ):
219
+ for case in cases (self .test_files + self . output_test_files ):
202
220
with self .subTest (description = case ["description" ]):
203
221
self .assertFollowsDescriptionStyle (case ["description" ])
204
222
205
223
def test_test_descriptions_do_not_use_modal_verbs (self ):
206
- for test in tests (self .test_files ):
224
+ for test in tests (self .test_files + self . output_test_files ):
207
225
with self .subTest (description = test ["description" ]):
208
226
self .assertFollowsDescriptionStyle (test ["description" ])
209
227
@@ -244,6 +262,17 @@ class SanityTests(unittest.TestCase):
244
262
validator .validate (cases )
245
263
except jsonschema .ValidationError as error :
246
264
self .fail (str (error ))
265
+ """
266
+ All output test files are valid under output-test-schema.json.
267
+ """
268
+ Validator = jsonschema .validators .validator_for (OUTPUTTESTSUITE_SCHEMA )
269
+ validator = Validator (OUTPUTTESTSUITE_SCHEMA )
270
+ for path , cases in files (self .output_test_files ):
271
+ with self .subTest (path = path ):
272
+ try :
273
+ validator .validate (cases )
274
+ except jsonschema .ValidationError as error :
275
+ self .fail (str (error ))
247
276
248
277
249
278
def main (arguments ):
0 commit comments