Skip to content

Commit daf42a7

Browse files
committed
attempt to update ci for output tests
1 parent 46bc7ac commit daf42a7

File tree

3 files changed

+78
-9
lines changed

3 files changed

+78
-9
lines changed

bin/jsonschema_suite

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ else:
3030

3131
ROOT_DIR = Path(__file__).parent.parent
3232
SUITE_ROOT_DIR = ROOT_DIR / "tests"
33+
OUTPUT_ROOT_DIR = ROOT_DIR / "output-tests"
3334

3435
REMOTES_DIR = ROOT_DIR / "remotes"
3536
REMOTES_BASE_URL = "http://localhost:1234/"
3637

3738
TESTSUITE_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

4042
def 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

249278
def main(arguments):

output-test-schema.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://json-schema.org/tests/output-test-schema",
4+
"description": "A schema for files contained within this suite",
5+
6+
"$ref": "test-schema",
7+
8+
"$defs": {
9+
"test": {
10+
"$dynamicAnchor": "foo",
11+
"description": "A single output test",
12+
13+
"allOf": [
14+
{ "$ref": "test-schema#/$defs/test" },
15+
{
16+
"properties": {
17+
"output": {
18+
"description": "schemas that are used to verify output",
19+
"type": "object",
20+
"properties": {
21+
"flag": { "$ref": "https://json-schema.org/draft/2020-12/schema" },
22+
"basic": { "$ref": "https://json-schema.org/draft/2020-12/schema" },
23+
"detailed": { "$ref": "https://json-schema.org/draft/2020-12/schema" },
24+
"verbose": { "$ref": "https://json-schema.org/draft/2020-12/schema" },
25+
"list": { "$ref": "https://json-schema.org/draft/2020-12/schema" },
26+
"hierarchy": { "$ref": "https://json-schema.org/draft/2020-12/schema" }
27+
},
28+
"minProperties": 1,
29+
"additionalProperties": false
30+
}
31+
}
32+
}
33+
]
34+
}
35+
}
36+
}

test-schema.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://json-schema.org/tests/test-schema",
34
"description": "A schema for files contained within this suite",
45

56
"type": "array",
@@ -24,7 +25,10 @@
2425
"tests": {
2526
"description": "A set of related tests all using the same schema",
2627
"type": "array",
27-
"items": { "$ref": "#/$defs/test" },
28+
"items": {
29+
"$dynamicRef": "#foo",
30+
"unevaluatedProperties": false
31+
},
2832
"minItems": 1
2933
}
3034
},
@@ -33,6 +37,7 @@
3337

3438
"$defs": {
3539
"test": {
40+
"$dynamicAnchor": "foo",
3641
"description": "A single test",
3742

3843
"type": "object",
@@ -53,8 +58,7 @@
5358
"description": "Whether the validation process of this instance should consider the instance valid or not",
5459
"type": "boolean"
5560
}
56-
},
57-
"additionalProperties": false
61+
}
5862
}
5963
}
6064
}

0 commit comments

Comments
 (0)