Skip to content

Commit 4a6e20b

Browse files
committed
Clarify and check corpus split
i.e. ensure that if the schemas become valid, we update our tagging system and start actually testing against them.
1 parent c1a12bb commit 4a6e20b

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/hypothesis_jsonschema/_canonicalise.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ def resolve_all_refs(
562562
"""
563563
if isinstance(schema, bool):
564564
return canonicalish(schema)
565+
assert isinstance(schema, dict), schema
565566
if resolver is None:
566567
resolver = LocalResolver.from_schema(deepcopy(schema))
567568
if not isinstance(resolver, jsonschema.RefResolver):

tests/test_from_schema.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from hypothesis_jsonschema._canonicalise import (
2323
HypothesisRefResolutionError,
2424
canonicalish,
25+
resolve_all_refs,
2526
)
2627
from hypothesis_jsonschema._from_schema import from_schema, rfc3339
2728

@@ -72,12 +73,6 @@ def test_invalid_schemas_raise(schema):
7273

7374

7475
INVALID_SCHEMAS = {
75-
# Includes a list where it should have a dict
76-
"TypeScript Lint configuration file",
77-
# This schema is missing the "definitions" key which means they're not resolvable.
78-
"Cirrus CI configuration files",
79-
# This schema similarly refers to a non-existent definition
80-
"The Bamboo Specs allows you to define Bamboo configuration as code, and have corresponding plans/deployments created or updated automatically in Bamboo",
8176
# Empty list for requires, which is invalid
8277
"Release Drafter configuration file",
8378
# Many, many schemas have invalid $schema keys, which emit a warning (-Werror)
@@ -91,6 +86,12 @@ def test_invalid_schemas_raise(schema):
9186
"Static Analysis Results Format (SARIF), Version 2.1.0-rtm.2",
9287
"Zuul CI configuration file",
9388
}
89+
NON_EXISTENT_REF_SCHEMAS = {
90+
"Cirrus CI configuration files",
91+
"The Bamboo Specs allows you to define Bamboo configuration as code, and have corresponding plans/deployments created or updated automatically in Bamboo",
92+
# Special case - reference is valid, but target is list-format `items` rather than a subschema
93+
"TypeScript Lint configuration file",
94+
}
9495
UNSUPPORTED_SCHEMAS = {
9596
# Technically valid, but using regex patterns not supported by Python
9697
"draft7/ECMA 262 regex escapes control codes with \\c and lower letter",
@@ -155,7 +156,7 @@ def test_invalid_schemas_raise(schema):
155156

156157
def to_name_params(corpus):
157158
for n in sorted(corpus):
158-
if n in INVALID_SCHEMAS:
159+
if n in INVALID_SCHEMAS | NON_EXISTENT_REF_SCHEMAS:
159160
continue
160161
if n in UNSUPPORTED_SCHEMAS:
161162
continue
@@ -169,6 +170,18 @@ def to_name_params(corpus):
169170
yield n
170171

171172

173+
@pytest.mark.parametrize("name", sorted(INVALID_SCHEMAS))
174+
def test_invalid_schemas_are_invalid(name):
175+
with pytest.raises(Exception):
176+
jsonschema.validators.validator_for(catalog[name]).check_schema(catalog[name])
177+
178+
179+
@pytest.mark.parametrize("name", sorted(NON_EXISTENT_REF_SCHEMAS))
180+
def test_invalid_ref_schemas_are_invalid(name):
181+
with pytest.raises(Exception):
182+
resolve_all_refs(catalog[name])
183+
184+
172185
RECURSIVE_REFS = {
173186
# From upstream validation test suite
174187
"draft4/valid definition",

0 commit comments

Comments
 (0)