Skip to content

Commit

Permalink
Squashed 'json/' changes from d3f5cd43..39d1d24d
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Julian committed Jun 30, 2022
1 parent 118726f commit 09edc31
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 27 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ on:
release:
types: [published]
schedule:
# Daily at 6:42
# Daily at 6:42, arbitrarily as a time that's possibly non-busy
- cron: '42 6 * * *'

jobs:
ci:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.7
python-version: '3.x'
- name: Install tox
run: python -m pip install tox
- name: Run the sanity checks
Expand Down
22 changes: 17 additions & 5 deletions bin/jsonschema_suite
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ try:
import jsonschema.validators
except ImportError:
jsonschema = None
VALIDATORS = {}
else:
VALIDATORS = {
"draft3": jsonschema.validators.Draft3Validator,
"draft4": jsonschema.validators.Draft4Validator,
"draft6": jsonschema.validators.Draft6Validator,
"draft7": jsonschema.validators.Draft7Validator,
"draft2019-09": jsonschema.validators.Draft201909Validator,
"draft2020-12": jsonschema.validators.Draft202012Validator,
"latest": jsonschema.validators.Draft202012Validator,
}


ROOT_DIR = os.path.abspath(
Expand All @@ -23,6 +34,7 @@ ROOT_DIR = os.path.abspath(
SUITE_ROOT_DIR = os.path.join(ROOT_DIR, "tests")
REMOTES_DIR = os.path.join(ROOT_DIR, "remotes")


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

Expand Down Expand Up @@ -114,13 +126,13 @@ class SanityTests(unittest.TestCase):

@unittest.skipIf(jsonschema is None, "Validation library not present!")
def test_all_schemas_are_valid(self):
for schema in os.listdir(SUITE_ROOT_DIR):
schema_validator = jsonschema.validators.validators.get(schema)
if schema_validator is not None:
test_files = collect(os.path.join(SUITE_ROOT_DIR, schema))
for version in os.listdir(SUITE_ROOT_DIR):
Validator = VALIDATORS.get(version)
if Validator is not None:
test_files = collect(os.path.join(SUITE_ROOT_DIR, version))
for case in cases(test_files):
try:
schema_validator.check_schema(case["schema"])
Validator.check_schema(case["schema"])
except jsonschema.SchemaError as error:
self.fail("%s contains an invalid schema (%s)" %
(case, error))
Expand Down
28 changes: 27 additions & 1 deletion tests/draft-next/unevaluatedItems.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,33 @@
{
"description": "unevaluatedItems with nested items",
"schema": {
"type": "array",
"unevaluatedItems": {"type": "boolean"},
"anyOf": [
{ "items": {"type": "string"} },
true
]
},
"tests": [
{
"description": "with only (valid) additional items",
"data": [true, false],
"valid": true
},
{
"description": "with no additional items",
"data": ["yes", "no"],
"valid": true
},
{
"description": "with invalid additional item",
"data": ["yes", false],
"valid": false
}
]
},
{
"description": "unevaluatedItems with nested prefixItems and items",
"schema": {
"allOf": [
{
"prefixItems": [
Expand Down
29 changes: 28 additions & 1 deletion tests/draft2019-09/unevaluatedItems.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,34 @@
]
},
{
"description": "unevaluatedItems with nested additionalItems",
"description": "unevaluatedItems with nested items",
"schema": {
"unevaluatedItems": {"type": "boolean"},
"anyOf": [
{ "items": {"type": "string"} },
true
]
},
"tests": [
{
"description": "with only (valid) additional items",
"data": [true, false],
"valid": true
},
{
"description": "with no additional items",
"data": ["yes", "no"],
"valid": true
},
{
"description": "with invalid additional item",
"data": ["yes", false],
"valid": false
}
]
},
{
"description": "unevaluatedItems with nested items and additionalItems",
"schema": {
"type": "array",
"allOf": [
Expand Down
28 changes: 27 additions & 1 deletion tests/draft2020-12/unevaluatedItems.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,33 @@
{
"description": "unevaluatedItems with nested items",
"schema": {
"type": "array",
"unevaluatedItems": {"type": "boolean"},
"anyOf": [
{ "items": {"type": "string"} },
true
]
},
"tests": [
{
"description": "with only (valid) additional items",
"data": [true, false],
"valid": true
},
{
"description": "with no additional items",
"data": ["yes", "no"],
"valid": true
},
{
"description": "with invalid additional item",
"data": ["yes", false],
"valid": false
}
]
},
{
"description": "unevaluatedItems with nested prefixItems and items",
"schema": {
"allOf": [
{
"prefixItems": [
Expand Down
48 changes: 34 additions & 14 deletions tests/draft6/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,23 @@
}
}
},
"if": {
"const": "skip not_a_real_anchor"
},
"then": true,
"else" : {
"$ref": "#/$defs/const_not_anchor"
}
"oneOf": [
{
"const": "skip not_a_real_anchor"
},
{
"allOf": [
{
"not": {
"const": "skip not_a_real_anchor"
}
},
{
"$ref": "#/$defs/const_not_anchor"
}
]
}
]
},
"tests": [
{
Expand All @@ -90,13 +100,23 @@
}
}
},
"if": {
"const": "skip not_a_real_id"
},
"then": true,
"else" : {
"$ref": "#/$defs/const_not_id"
}
"oneOf": [
{
"const":"skip not_a_real_id"
},
{
"allOf": [
{
"not": {
"const": "skip not_a_real_id"
}
},
{
"$ref": "#/$defs/const_not_id"
}
]
}
]
},
"tests": [
{
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ skipsdist = True

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

0 comments on commit 09edc31

Please sign in to comment.