Skip to content

Commit 09edc31

Browse files
committed
Squashed 'json/' changes from d3f5cd43..39d1d24d
39d1d24d Merge pull request #317 from Relequestual/#291 b683de5a Forward-port and reword the new unevaluatedItems test. 816441f4 Add tests for Single-schema items and unevaluatedItems Resolves #291 1e0ebd20 Merge pull request #563 from json-schema-org/update-sanity-checker e1dbaebb Merge pull request #562 from json-schema-org/remove-conditional-id-tests-from-draft6 53da77f3 Update the sanity checker to use a version which supports 2019+. 5aff83e5 reintroduce tests without using if/then/else 9495e3e4 remove conditional $id tests from draft 6 git-subtree-dir: json git-subtree-split: 39d1d24dbc1920953dec90369edec5a2fa7158fa
1 parent 118726f commit 09edc31

File tree

7 files changed

+138
-27
lines changed

7 files changed

+138
-27
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ on:
66
release:
77
types: [published]
88
schedule:
9-
# Daily at 6:42
9+
# Daily at 6:42, arbitrarily as a time that's possibly non-busy
1010
- cron: '42 6 * * *'
1111

1212
jobs:
1313
ci:
1414
runs-on: ubuntu-latest
1515

1616
steps:
17-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v3
1818
- name: Set up Python
19-
uses: actions/setup-python@v2
19+
uses: actions/setup-python@v4
2020
with:
21-
python-version: 3.7
21+
python-version: '3.x'
2222
- name: Install tox
2323
run: python -m pip install tox
2424
- name: Run the sanity checks

bin/jsonschema_suite

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ try:
1515
import jsonschema.validators
1616
except ImportError:
1717
jsonschema = None
18+
VALIDATORS = {}
19+
else:
20+
VALIDATORS = {
21+
"draft3": jsonschema.validators.Draft3Validator,
22+
"draft4": jsonschema.validators.Draft4Validator,
23+
"draft6": jsonschema.validators.Draft6Validator,
24+
"draft7": jsonschema.validators.Draft7Validator,
25+
"draft2019-09": jsonschema.validators.Draft201909Validator,
26+
"draft2020-12": jsonschema.validators.Draft202012Validator,
27+
"latest": jsonschema.validators.Draft202012Validator,
28+
}
1829

1930

2031
ROOT_DIR = os.path.abspath(
@@ -23,6 +34,7 @@ ROOT_DIR = os.path.abspath(
2334
SUITE_ROOT_DIR = os.path.join(ROOT_DIR, "tests")
2435
REMOTES_DIR = os.path.join(ROOT_DIR, "remotes")
2536

37+
2638
with open(os.path.join(ROOT_DIR, "test-schema.json")) as schema:
2739
TESTSUITE_SCHEMA = json.load(schema)
2840

@@ -114,13 +126,13 @@ class SanityTests(unittest.TestCase):
114126

115127
@unittest.skipIf(jsonschema is None, "Validation library not present!")
116128
def test_all_schemas_are_valid(self):
117-
for schema in os.listdir(SUITE_ROOT_DIR):
118-
schema_validator = jsonschema.validators.validators.get(schema)
119-
if schema_validator is not None:
120-
test_files = collect(os.path.join(SUITE_ROOT_DIR, schema))
129+
for version in os.listdir(SUITE_ROOT_DIR):
130+
Validator = VALIDATORS.get(version)
131+
if Validator is not None:
132+
test_files = collect(os.path.join(SUITE_ROOT_DIR, version))
121133
for case in cases(test_files):
122134
try:
123-
schema_validator.check_schema(case["schema"])
135+
Validator.check_schema(case["schema"])
124136
except jsonschema.SchemaError as error:
125137
self.fail("%s contains an invalid schema (%s)" %
126138
(case, error))

tests/draft-next/unevaluatedItems.json

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,33 @@
149149
{
150150
"description": "unevaluatedItems with nested items",
151151
"schema": {
152-
"type": "array",
152+
"unevaluatedItems": {"type": "boolean"},
153+
"anyOf": [
154+
{ "items": {"type": "string"} },
155+
true
156+
]
157+
},
158+
"tests": [
159+
{
160+
"description": "with only (valid) additional items",
161+
"data": [true, false],
162+
"valid": true
163+
},
164+
{
165+
"description": "with no additional items",
166+
"data": ["yes", "no"],
167+
"valid": true
168+
},
169+
{
170+
"description": "with invalid additional item",
171+
"data": ["yes", false],
172+
"valid": false
173+
}
174+
]
175+
},
176+
{
177+
"description": "unevaluatedItems with nested prefixItems and items",
178+
"schema": {
153179
"allOf": [
154180
{
155181
"prefixItems": [

tests/draft2019-09/unevaluatedItems.json

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,34 @@
147147
]
148148
},
149149
{
150-
"description": "unevaluatedItems with nested additionalItems",
150+
"description": "unevaluatedItems with nested items",
151+
"schema": {
152+
"unevaluatedItems": {"type": "boolean"},
153+
"anyOf": [
154+
{ "items": {"type": "string"} },
155+
true
156+
]
157+
},
158+
"tests": [
159+
{
160+
"description": "with only (valid) additional items",
161+
"data": [true, false],
162+
"valid": true
163+
},
164+
{
165+
"description": "with no additional items",
166+
"data": ["yes", "no"],
167+
"valid": true
168+
},
169+
{
170+
"description": "with invalid additional item",
171+
"data": ["yes", false],
172+
"valid": false
173+
}
174+
]
175+
},
176+
{
177+
"description": "unevaluatedItems with nested items and additionalItems",
151178
"schema": {
152179
"type": "array",
153180
"allOf": [

tests/draft2020-12/unevaluatedItems.json

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,33 @@
149149
{
150150
"description": "unevaluatedItems with nested items",
151151
"schema": {
152-
"type": "array",
152+
"unevaluatedItems": {"type": "boolean"},
153+
"anyOf": [
154+
{ "items": {"type": "string"} },
155+
true
156+
]
157+
},
158+
"tests": [
159+
{
160+
"description": "with only (valid) additional items",
161+
"data": [true, false],
162+
"valid": true
163+
},
164+
{
165+
"description": "with no additional items",
166+
"data": ["yes", "no"],
167+
"valid": true
168+
},
169+
{
170+
"description": "with invalid additional item",
171+
"data": ["yes", false],
172+
"valid": false
173+
}
174+
]
175+
},
176+
{
177+
"description": "unevaluatedItems with nested prefixItems and items",
178+
"schema": {
153179
"allOf": [
154180
{
155181
"prefixItems": [

tests/draft6/id.json

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,23 @@
5959
}
6060
}
6161
},
62-
"if": {
63-
"const": "skip not_a_real_anchor"
64-
},
65-
"then": true,
66-
"else" : {
67-
"$ref": "#/$defs/const_not_anchor"
68-
}
62+
"oneOf": [
63+
{
64+
"const": "skip not_a_real_anchor"
65+
},
66+
{
67+
"allOf": [
68+
{
69+
"not": {
70+
"const": "skip not_a_real_anchor"
71+
}
72+
},
73+
{
74+
"$ref": "#/$defs/const_not_anchor"
75+
}
76+
]
77+
}
78+
]
6979
},
7080
"tests": [
7181
{
@@ -90,13 +100,23 @@
90100
}
91101
}
92102
},
93-
"if": {
94-
"const": "skip not_a_real_id"
95-
},
96-
"then": true,
97-
"else" : {
98-
"$ref": "#/$defs/const_not_id"
99-
}
103+
"oneOf": [
104+
{
105+
"const":"skip not_a_real_id"
106+
},
107+
{
108+
"allOf": [
109+
{
110+
"not": {
111+
"const": "skip not_a_real_id"
112+
}
113+
},
114+
{
115+
"$ref": "#/$defs/const_not_id"
116+
}
117+
]
118+
}
119+
]
100120
},
101121
"tests": [
102122
{

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ skipsdist = True
55

66
[testenv:sanity]
77
# used just for validating the structure of the test case files themselves
8-
deps = jsonschema==3.2.0
8+
deps = jsonschema==4.6.1
99
commands = {envpython} bin/jsonschema_suite check

0 commit comments

Comments
 (0)