@@ -30,11 +30,13 @@ else:
3030
3131ROOT_DIR = Path (__file__ ).parent .parent
3232SUITE_ROOT_DIR = ROOT_DIR / "tests"
33+ OUTPUT_ROOT_DIR = ROOT_DIR / "output-tests"
3334
3435REMOTES_DIR = ROOT_DIR / "remotes"
3536REMOTES_BASE_URL = "http://localhost:1234/"
3637
3738TESTSUITE_SCHEMA = json .loads ((ROOT_DIR / "test-schema.json" ).read_text ())
39+ OUTPUTTESTSUITE_SCHEMA = json .loads ((ROOT_DIR / "output-test-schema.json" ).read_text ())
3840
3941
4042def files (paths ):
@@ -88,12 +90,17 @@ class SanityTests(unittest.TestCase):
8890 @classmethod
8991 def setUpClass (cls ):
9092 print (f"Looking for tests in { SUITE_ROOT_DIR } " )
93+ print (f"Looking for output tests in { OUTPUT_ROOT_DIR } " )
9194 print (f"Looking for remotes in { REMOTES_DIR } " )
9295
9396 cls .test_files = list (collect (SUITE_ROOT_DIR ))
9497 assert cls .test_files , "Didn't find the test files!"
9598 print (f"Found { len (cls .test_files )} test files" )
9699
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+
97104 cls .remote_files = list (collect (REMOTES_DIR ))
98105 assert cls .remote_files , "Didn't find the remote files!"
99106 print (f"Found { len (cls .remote_files )} remote files" )
@@ -142,6 +149,17 @@ class SanityTests(unittest.TestCase):
142149 except ValueError as error :
143150 self .fail (f"{ path } contains invalid JSON ({ error } )" )
144151
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+
145163 def test_all_remote_files_are_valid_json (self ):
146164 """
147165 All remote files contain valid JSON.
@@ -157,7 +175,7 @@ class SanityTests(unittest.TestCase):
157175 """
158176 All cases have reasonably long descriptions.
159177 """
160- for case in cases (self .test_files ):
178+ for case in cases (self .test_files + self . output_test_files ):
161179 with self .subTest (description = case ["description" ]):
162180 self .assertLess (
163181 len (case ["description" ]),
@@ -169,7 +187,7 @@ class SanityTests(unittest.TestCase):
169187 """
170188 All tests have reasonably long descriptions.
171189 """
172- for count , test in enumerate (tests (self .test_files )):
190+ for count , test in enumerate (tests (self .test_files + self . output_test_files )):
173191 with self .subTest (description = test ["description" ]):
174192 self .assertLess (
175193 len (test ["description" ]),
@@ -182,28 +200,28 @@ class SanityTests(unittest.TestCase):
182200 """
183201 All cases have unique descriptions in their files.
184202 """
185- for path , cases in files (self .test_files ):
203+ for path , cases in files (self .test_files + self . output_test_files ):
186204 with self .subTest (path = path ):
187205 self .assertUnique (case ["description" ] for case in cases )
188206
189207 def test_all_test_descriptions_are_unique (self ):
190208 """
191209 All test cases have unique test descriptions in their tests.
192210 """
193- for count , case in enumerate (cases (self .test_files )):
211+ for count , case in enumerate (cases (self .test_files + self . output_test_files )):
194212 with self .subTest (description = case ["description" ]):
195213 self .assertUnique (
196214 test ["description" ] for test in case ["tests" ]
197215 )
198216 print (f"Found { count } test cases." )
199217
200218 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 ):
202220 with self .subTest (description = case ["description" ]):
203221 self .assertFollowsDescriptionStyle (case ["description" ])
204222
205223 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 ):
207225 with self .subTest (description = test ["description" ]):
208226 self .assertFollowsDescriptionStyle (test ["description" ])
209227
@@ -244,6 +262,17 @@ class SanityTests(unittest.TestCase):
244262 validator .validate (cases )
245263 except jsonschema .ValidationError as error :
246264 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 ))
247276
248277
249278def main (arguments ):
0 commit comments