From 104e2a2d9f6ff2b3a4864e6f1b48088a68df730c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20B=C3=A4ckmark?= Date: Thu, 21 Dec 2023 10:05:57 +0100 Subject: [PATCH 1/7] Add test for valid schema --- Makefile | 4 ++-- test_jsonschema.py | 40 ++++++++++++++++++++++++++++++++++++++++ tox.ini | 7 +++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 test_jsonschema.py diff --git a/Makefile b/Makefile index 5e333607..92baf0fc 100644 --- a/Makefile +++ b/Makefile @@ -25,8 +25,8 @@ help: ## Show this help. @egrep -h '\s##\s' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-30s\033[0m %s\n", $$1, $$2}' .PHONY: tests -test: ## Run all document related checks found in tox: pytest, jsonformat, validate - tox run -e pytest,jsonformat,validate +test: ## Run all document related checks found in tox: pytest, jsonformat, validate, jsonschema + tox run -e pytest,jsonformat,validate,jsonschema .PHONY: generate_docs generate_docs: ## Generate the Markdown files based on the YAML definitions diff --git a/test_jsonschema.py b/test_jsonschema.py new file mode 100644 index 00000000..20394e11 --- /dev/null +++ b/test_jsonschema.py @@ -0,0 +1,40 @@ +# Copyright 2022 Axis Communications AB. +# For a full list of individual contributors, please see the commit history. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +import subprocess + +import jsonschema +import pytest + + +@pytest.mark.parametrize( + "filename", + subprocess.check_output(["git", "ls-files", "--exclude-standard", "schemas/*.json"]) + .decode("utf-8") + .splitlines(), +) +def test_json_schema(filename): + with open(filename) as input_file: + data = input_file.read() + + event_schema = json.loads(data) + stricter_metaschema = dict( + jsonschema.Draft4Validator.META_SCHEMA, additionalProperties=False + ) + StrictDraft4Validator = jsonschema.validators.create( + stricter_metaschema, jsonschema.Draft4Validator.VALIDATORS, "StrictDraft4" + ) + StrictDraft4Validator.check_schema(event_schema) diff --git a/tox.ini b/tox.ini index c89a9d0d..b5c2fee6 100644 --- a/tox.ini +++ b/tox.ini @@ -20,6 +20,7 @@ envlist = black isort jsonformat + jsonschema pytest markdownlint @@ -49,6 +50,12 @@ deps = pytest==6.2.5 commands = pytest test_jsonformat.py {posargs} +[testenv:jsonschema] +deps = + pytest==6.2.5 + jsonschema==4.20.0 +commands = pytest test_jsonschema.py {posargs} + [testenv:pytest] deps = -rrequirements.txt From 97e3c3518db621e03b89038953fb63d298815c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20B=C3=A4ckmark?= Date: Thu, 21 Dec 2023 10:23:14 +0100 Subject: [PATCH 2/7] Corrected old schemas --- definitions/EiffelActivityCanceledEvent/1.0.0.yml | 2 +- definitions/EiffelActivityCanceledEvent/1.1.0.yml | 2 +- definitions/EiffelActivityCanceledEvent/2.0.0.yml | 2 +- definitions/EiffelActivityCanceledEvent/3.0.0.yml | 2 +- definitions/EiffelActivityCanceledEvent/3.1.0.yml | 2 +- definitions/EiffelActivityCanceledEvent/3.2.0.yml | 2 +- schemas/EiffelActivityCanceledEvent/1.0.0.json | 2 +- schemas/EiffelActivityCanceledEvent/1.1.0.json | 2 +- schemas/EiffelActivityCanceledEvent/2.0.0.json | 2 +- schemas/EiffelActivityCanceledEvent/3.0.0.json | 2 +- schemas/EiffelActivityCanceledEvent/3.1.0.json | 2 +- schemas/EiffelActivityCanceledEvent/3.2.0.json | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/definitions/EiffelActivityCanceledEvent/1.0.0.yml b/definitions/EiffelActivityCanceledEvent/1.0.0.yml index 3bc9fbbc..e007f8b1 100644 --- a/definitions/EiffelActivityCanceledEvent/1.0.0.yml +++ b/definitions/EiffelActivityCanceledEvent/1.0.0.yml @@ -44,7 +44,7 @@ required: - meta - data - links -additonalProperties: false +additionalProperties: false _links: ACTIVITY_EXECUTION: description: Declares the activity execution that was canceled. diff --git a/definitions/EiffelActivityCanceledEvent/1.1.0.yml b/definitions/EiffelActivityCanceledEvent/1.1.0.yml index 5e025367..4b04b45f 100644 --- a/definitions/EiffelActivityCanceledEvent/1.1.0.yml +++ b/definitions/EiffelActivityCanceledEvent/1.1.0.yml @@ -44,7 +44,7 @@ required: - meta - data - links -additonalProperties: false +additionalProperties: false _links: ACTIVITY_EXECUTION: description: Declares the activity execution that was canceled. diff --git a/definitions/EiffelActivityCanceledEvent/2.0.0.yml b/definitions/EiffelActivityCanceledEvent/2.0.0.yml index a1b10ee3..a0caf5a6 100644 --- a/definitions/EiffelActivityCanceledEvent/2.0.0.yml +++ b/definitions/EiffelActivityCanceledEvent/2.0.0.yml @@ -44,7 +44,7 @@ required: - meta - data - links -additonalProperties: false +additionalProperties: false _links: ACTIVITY_EXECUTION: description: Declares the activity execution that was canceled. diff --git a/definitions/EiffelActivityCanceledEvent/3.0.0.yml b/definitions/EiffelActivityCanceledEvent/3.0.0.yml index 1e0e9304..34f83791 100644 --- a/definitions/EiffelActivityCanceledEvent/3.0.0.yml +++ b/definitions/EiffelActivityCanceledEvent/3.0.0.yml @@ -44,7 +44,7 @@ required: - meta - data - links -additonalProperties: false +additionalProperties: false _links: ACTIVITY_EXECUTION: description: Declares the activity execution that was canceled. diff --git a/definitions/EiffelActivityCanceledEvent/3.1.0.yml b/definitions/EiffelActivityCanceledEvent/3.1.0.yml index f6ab2bce..33d81396 100644 --- a/definitions/EiffelActivityCanceledEvent/3.1.0.yml +++ b/definitions/EiffelActivityCanceledEvent/3.1.0.yml @@ -44,7 +44,7 @@ required: - meta - data - links -additonalProperties: false +additionalProperties: false _links: ACTIVITY_EXECUTION: description: Declares the activity execution that was canceled. diff --git a/definitions/EiffelActivityCanceledEvent/3.2.0.yml b/definitions/EiffelActivityCanceledEvent/3.2.0.yml index a94fd492..1c73daeb 100644 --- a/definitions/EiffelActivityCanceledEvent/3.2.0.yml +++ b/definitions/EiffelActivityCanceledEvent/3.2.0.yml @@ -44,7 +44,7 @@ required: - meta - data - links -additonalProperties: false +additionalProperties: false _links: ACTIVITY_EXECUTION: description: Declares the activity execution that was canceled. diff --git a/schemas/EiffelActivityCanceledEvent/1.0.0.json b/schemas/EiffelActivityCanceledEvent/1.0.0.json index b0419e70..81c7b761 100644 --- a/schemas/EiffelActivityCanceledEvent/1.0.0.json +++ b/schemas/EiffelActivityCanceledEvent/1.0.0.json @@ -152,5 +152,5 @@ "data", "links" ], - "additonalProperties": false + "additionalProperties": false } diff --git a/schemas/EiffelActivityCanceledEvent/1.1.0.json b/schemas/EiffelActivityCanceledEvent/1.1.0.json index 08e1d241..bc00332a 100644 --- a/schemas/EiffelActivityCanceledEvent/1.1.0.json +++ b/schemas/EiffelActivityCanceledEvent/1.1.0.json @@ -152,5 +152,5 @@ "data", "links" ], - "additonalProperties": false + "additionalProperties": false } diff --git a/schemas/EiffelActivityCanceledEvent/2.0.0.json b/schemas/EiffelActivityCanceledEvent/2.0.0.json index 7c8e2810..7f559237 100644 --- a/schemas/EiffelActivityCanceledEvent/2.0.0.json +++ b/schemas/EiffelActivityCanceledEvent/2.0.0.json @@ -136,5 +136,5 @@ "data", "links" ], - "additonalProperties": false + "additionalProperties": false } diff --git a/schemas/EiffelActivityCanceledEvent/3.0.0.json b/schemas/EiffelActivityCanceledEvent/3.0.0.json index edf01ca0..1911de6a 100644 --- a/schemas/EiffelActivityCanceledEvent/3.0.0.json +++ b/schemas/EiffelActivityCanceledEvent/3.0.0.json @@ -178,5 +178,5 @@ "data", "links" ], - "additonalProperties": false + "additionalProperties": false } diff --git a/schemas/EiffelActivityCanceledEvent/3.1.0.json b/schemas/EiffelActivityCanceledEvent/3.1.0.json index 6e8f25e8..a6a4ddc1 100644 --- a/schemas/EiffelActivityCanceledEvent/3.1.0.json +++ b/schemas/EiffelActivityCanceledEvent/3.1.0.json @@ -181,5 +181,5 @@ "data", "links" ], - "additonalProperties": false + "additionalProperties": false } diff --git a/schemas/EiffelActivityCanceledEvent/3.2.0.json b/schemas/EiffelActivityCanceledEvent/3.2.0.json index cb4655c2..7993f7e1 100644 --- a/schemas/EiffelActivityCanceledEvent/3.2.0.json +++ b/schemas/EiffelActivityCanceledEvent/3.2.0.json @@ -184,5 +184,5 @@ "data", "links" ], - "additonalProperties": false + "additionalProperties": false } From 0be89f8ceb15cba58d613be18493b190f868447a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20B=C3=A4ckmark?= Date: Tue, 2 Jan 2024 11:05:58 +0100 Subject: [PATCH 3/7] Minor optimization and a copyright fix --- test_jsonschema.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test_jsonschema.py b/test_jsonschema.py index 20394e11..8c4c6d27 100644 --- a/test_jsonschema.py +++ b/test_jsonschema.py @@ -1,4 +1,4 @@ -# Copyright 2022 Axis Communications AB. +# Copyright 2022-2023 Axis Communications AB and others. # For a full list of individual contributors, please see the commit history. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,9 +28,8 @@ ) def test_json_schema(filename): with open(filename) as input_file: - data = input_file.read() + event_schema = json.loads(input_file.read()) - event_schema = json.loads(data) stricter_metaschema = dict( jsonschema.Draft4Validator.META_SCHEMA, additionalProperties=False ) From 68e1ca7b847d4557f8d2ac56329b162de9d9b1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20B=C3=A4ckmark?= Date: Thu, 4 Jan 2024 14:46:08 +0100 Subject: [PATCH 4/7] Update json schema tester to neglect old ActC versions --- Makefile | 4 +-- .../EiffelActivityCanceledEvent/1.0.0.yml | 2 +- .../EiffelActivityCanceledEvent/1.1.0.yml | 2 +- .../EiffelActivityCanceledEvent/2.0.0.yml | 2 +- .../EiffelActivityCanceledEvent/3.0.0.yml | 2 +- .../EiffelActivityCanceledEvent/3.1.0.yml | 2 +- .../EiffelActivityCanceledEvent/3.2.0.yml | 2 +- .../EiffelActivityCanceledEvent/1.0.0.json | 2 +- .../EiffelActivityCanceledEvent/1.1.0.json | 2 +- .../EiffelActivityCanceledEvent/2.0.0.json | 2 +- .../EiffelActivityCanceledEvent/3.0.0.json | 2 +- .../EiffelActivityCanceledEvent/3.1.0.json | 2 +- .../EiffelActivityCanceledEvent/3.2.0.json | 2 +- test_jsonschema.py | 29 ++++++++++++++----- tox.ini | 7 ----- 15 files changed, 36 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 92baf0fc..5e333607 100644 --- a/Makefile +++ b/Makefile @@ -25,8 +25,8 @@ help: ## Show this help. @egrep -h '\s##\s' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-30s\033[0m %s\n", $$1, $$2}' .PHONY: tests -test: ## Run all document related checks found in tox: pytest, jsonformat, validate, jsonschema - tox run -e pytest,jsonformat,validate,jsonschema +test: ## Run all document related checks found in tox: pytest, jsonformat, validate + tox run -e pytest,jsonformat,validate .PHONY: generate_docs generate_docs: ## Generate the Markdown files based on the YAML definitions diff --git a/definitions/EiffelActivityCanceledEvent/1.0.0.yml b/definitions/EiffelActivityCanceledEvent/1.0.0.yml index e007f8b1..3bc9fbbc 100644 --- a/definitions/EiffelActivityCanceledEvent/1.0.0.yml +++ b/definitions/EiffelActivityCanceledEvent/1.0.0.yml @@ -44,7 +44,7 @@ required: - meta - data - links -additionalProperties: false +additonalProperties: false _links: ACTIVITY_EXECUTION: description: Declares the activity execution that was canceled. diff --git a/definitions/EiffelActivityCanceledEvent/1.1.0.yml b/definitions/EiffelActivityCanceledEvent/1.1.0.yml index 4b04b45f..5e025367 100644 --- a/definitions/EiffelActivityCanceledEvent/1.1.0.yml +++ b/definitions/EiffelActivityCanceledEvent/1.1.0.yml @@ -44,7 +44,7 @@ required: - meta - data - links -additionalProperties: false +additonalProperties: false _links: ACTIVITY_EXECUTION: description: Declares the activity execution that was canceled. diff --git a/definitions/EiffelActivityCanceledEvent/2.0.0.yml b/definitions/EiffelActivityCanceledEvent/2.0.0.yml index a0caf5a6..a1b10ee3 100644 --- a/definitions/EiffelActivityCanceledEvent/2.0.0.yml +++ b/definitions/EiffelActivityCanceledEvent/2.0.0.yml @@ -44,7 +44,7 @@ required: - meta - data - links -additionalProperties: false +additonalProperties: false _links: ACTIVITY_EXECUTION: description: Declares the activity execution that was canceled. diff --git a/definitions/EiffelActivityCanceledEvent/3.0.0.yml b/definitions/EiffelActivityCanceledEvent/3.0.0.yml index 34f83791..1e0e9304 100644 --- a/definitions/EiffelActivityCanceledEvent/3.0.0.yml +++ b/definitions/EiffelActivityCanceledEvent/3.0.0.yml @@ -44,7 +44,7 @@ required: - meta - data - links -additionalProperties: false +additonalProperties: false _links: ACTIVITY_EXECUTION: description: Declares the activity execution that was canceled. diff --git a/definitions/EiffelActivityCanceledEvent/3.1.0.yml b/definitions/EiffelActivityCanceledEvent/3.1.0.yml index 33d81396..f6ab2bce 100644 --- a/definitions/EiffelActivityCanceledEvent/3.1.0.yml +++ b/definitions/EiffelActivityCanceledEvent/3.1.0.yml @@ -44,7 +44,7 @@ required: - meta - data - links -additionalProperties: false +additonalProperties: false _links: ACTIVITY_EXECUTION: description: Declares the activity execution that was canceled. diff --git a/definitions/EiffelActivityCanceledEvent/3.2.0.yml b/definitions/EiffelActivityCanceledEvent/3.2.0.yml index 1c73daeb..a94fd492 100644 --- a/definitions/EiffelActivityCanceledEvent/3.2.0.yml +++ b/definitions/EiffelActivityCanceledEvent/3.2.0.yml @@ -44,7 +44,7 @@ required: - meta - data - links -additionalProperties: false +additonalProperties: false _links: ACTIVITY_EXECUTION: description: Declares the activity execution that was canceled. diff --git a/schemas/EiffelActivityCanceledEvent/1.0.0.json b/schemas/EiffelActivityCanceledEvent/1.0.0.json index 81c7b761..b0419e70 100644 --- a/schemas/EiffelActivityCanceledEvent/1.0.0.json +++ b/schemas/EiffelActivityCanceledEvent/1.0.0.json @@ -152,5 +152,5 @@ "data", "links" ], - "additionalProperties": false + "additonalProperties": false } diff --git a/schemas/EiffelActivityCanceledEvent/1.1.0.json b/schemas/EiffelActivityCanceledEvent/1.1.0.json index bc00332a..08e1d241 100644 --- a/schemas/EiffelActivityCanceledEvent/1.1.0.json +++ b/schemas/EiffelActivityCanceledEvent/1.1.0.json @@ -152,5 +152,5 @@ "data", "links" ], - "additionalProperties": false + "additonalProperties": false } diff --git a/schemas/EiffelActivityCanceledEvent/2.0.0.json b/schemas/EiffelActivityCanceledEvent/2.0.0.json index 7f559237..7c8e2810 100644 --- a/schemas/EiffelActivityCanceledEvent/2.0.0.json +++ b/schemas/EiffelActivityCanceledEvent/2.0.0.json @@ -136,5 +136,5 @@ "data", "links" ], - "additionalProperties": false + "additonalProperties": false } diff --git a/schemas/EiffelActivityCanceledEvent/3.0.0.json b/schemas/EiffelActivityCanceledEvent/3.0.0.json index 1911de6a..edf01ca0 100644 --- a/schemas/EiffelActivityCanceledEvent/3.0.0.json +++ b/schemas/EiffelActivityCanceledEvent/3.0.0.json @@ -178,5 +178,5 @@ "data", "links" ], - "additionalProperties": false + "additonalProperties": false } diff --git a/schemas/EiffelActivityCanceledEvent/3.1.0.json b/schemas/EiffelActivityCanceledEvent/3.1.0.json index a6a4ddc1..6e8f25e8 100644 --- a/schemas/EiffelActivityCanceledEvent/3.1.0.json +++ b/schemas/EiffelActivityCanceledEvent/3.1.0.json @@ -181,5 +181,5 @@ "data", "links" ], - "additionalProperties": false + "additonalProperties": false } diff --git a/schemas/EiffelActivityCanceledEvent/3.2.0.json b/schemas/EiffelActivityCanceledEvent/3.2.0.json index 7993f7e1..cb4655c2 100644 --- a/schemas/EiffelActivityCanceledEvent/3.2.0.json +++ b/schemas/EiffelActivityCanceledEvent/3.2.0.json @@ -184,5 +184,5 @@ "data", "links" ], - "additionalProperties": false + "additonalProperties": false } diff --git a/test_jsonschema.py b/test_jsonschema.py index 8c4c6d27..66ef1f40 100644 --- a/test_jsonschema.py +++ b/test_jsonschema.py @@ -15,10 +15,21 @@ import json import subprocess +import logging import jsonschema import pytest +# Set up a console logger +logger = logging.getLogger("__Logger__") +console_handler = logging.StreamHandler() +formatter = logging.Formatter( + "%(asctime)s - %(name)s - %(levelname)s - %(message)s", + datefmt="%m/%d/%Y %I:%M:%S%p", +) +console_handler.setFormatter(formatter) +logger.addHandler(console_handler) + @pytest.mark.parametrize( "filename", @@ -30,10 +41,14 @@ def test_json_schema(filename): with open(filename) as input_file: event_schema = json.loads(input_file.read()) - stricter_metaschema = dict( - jsonschema.Draft4Validator.META_SCHEMA, additionalProperties=False - ) - StrictDraft4Validator = jsonschema.validators.create( - stricter_metaschema, jsonschema.Draft4Validator.VALIDATORS, "StrictDraft4" - ) - StrictDraft4Validator.check_schema(event_schema) + # Use standard validator for old ActC schemas, to cope with bug https://github.com/eiffel-community/eiffel/issues/376 + if ("ActivityCanceled" in filename) and (event_schema["properties"]["meta"]["properties"]["version"]["default"] in ["1.0.0", "1.1.0", "2.0.0", "3.0.0", "3.1.0", "3.2.0"]): + jsonschema.Draft4Validator.check_schema(event_schema) + else: + stricter_metaschema = dict( + jsonschema.Draft4Validator.META_SCHEMA, additionalProperties=False + ) + StrictDraft4Validator = jsonschema.validators.create( + stricter_metaschema, jsonschema.Draft4Validator.VALIDATORS, "StrictDraft4" + ) + StrictDraft4Validator.check_schema(event_schema) diff --git a/tox.ini b/tox.ini index b5c2fee6..c89a9d0d 100644 --- a/tox.ini +++ b/tox.ini @@ -20,7 +20,6 @@ envlist = black isort jsonformat - jsonschema pytest markdownlint @@ -50,12 +49,6 @@ deps = pytest==6.2.5 commands = pytest test_jsonformat.py {posargs} -[testenv:jsonschema] -deps = - pytest==6.2.5 - jsonschema==4.20.0 -commands = pytest test_jsonschema.py {posargs} - [testenv:pytest] deps = -rrequirements.txt From 1155f8168727405b8b81ccc83c379148e8ba6816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20B=C3=A4ckmark?= Date: Thu, 4 Jan 2024 14:53:54 +0100 Subject: [PATCH 5/7] Fix formatting errors --- test_jsonschema.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test_jsonschema.py b/test_jsonschema.py index 66ef1f40..842176c6 100644 --- a/test_jsonschema.py +++ b/test_jsonschema.py @@ -14,8 +14,8 @@ # limitations under the License. import json -import subprocess import logging +import subprocess import jsonschema import pytest @@ -42,8 +42,11 @@ def test_json_schema(filename): event_schema = json.loads(input_file.read()) # Use standard validator for old ActC schemas, to cope with bug https://github.com/eiffel-community/eiffel/issues/376 - if ("ActivityCanceled" in filename) and (event_schema["properties"]["meta"]["properties"]["version"]["default"] in ["1.0.0", "1.1.0", "2.0.0", "3.0.0", "3.1.0", "3.2.0"]): - jsonschema.Draft4Validator.check_schema(event_schema) + if ("ActivityCanceled" in filename) and ( + event_schema["properties"]["meta"]["properties"]["version"]["default"] + in ["1.0.0", "1.1.0", "2.0.0", "3.0.0", "3.1.0", "3.2.0"] + ): + jsonschema.Draft4Validator.check_schema(event_schema) else: stricter_metaschema = dict( jsonschema.Draft4Validator.META_SCHEMA, additionalProperties=False From 53f45ad633554e25591b52431ee80a195c8e2a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20B=C3=A4ckmark?= Date: Wed, 10 Jan 2024 16:04:42 +0100 Subject: [PATCH 6/7] Update copyright header --- test_jsonschema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_jsonschema.py b/test_jsonschema.py index 842176c6..d8ff5791 100644 --- a/test_jsonschema.py +++ b/test_jsonschema.py @@ -1,4 +1,4 @@ -# Copyright 2022-2023 Axis Communications AB and others. +# Copyright 2023-2024 Ericsson AB. # For a full list of individual contributors, please see the commit history. # # Licensed under the Apache License, Version 2.0 (the "License"); From 61b0276face0dfbe0da5a84ae366a35cd98c132d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20B=C3=A4ckmark?= Date: Thu, 11 Jan 2024 09:13:40 +0100 Subject: [PATCH 7/7] Break out schema check --- test_jsonschema.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/test_jsonschema.py b/test_jsonschema.py index d8ff5791..7646d8f2 100644 --- a/test_jsonschema.py +++ b/test_jsonschema.py @@ -14,22 +14,11 @@ # limitations under the License. import json -import logging import subprocess import jsonschema import pytest -# Set up a console logger -logger = logging.getLogger("__Logger__") -console_handler = logging.StreamHandler() -formatter = logging.Formatter( - "%(asctime)s - %(name)s - %(levelname)s - %(message)s", - datefmt="%m/%d/%Y %I:%M:%S%p", -) -console_handler.setFormatter(formatter) -logger.addHandler(console_handler) - @pytest.mark.parametrize( "filename", @@ -39,19 +28,22 @@ ) def test_json_schema(filename): with open(filename) as input_file: - event_schema = json.loads(input_file.read()) + event_schema = json.load(input_file) - # Use standard validator for old ActC schemas, to cope with bug https://github.com/eiffel-community/eiffel/issues/376 + # Evaluate which schema validator to use. Use standard validator for old ActC + # schemas, to cope with bug https://github.com/eiffel-community/eiffel/issues/376 + schema_validator = None if ("ActivityCanceled" in filename) and ( event_schema["properties"]["meta"]["properties"]["version"]["default"] in ["1.0.0", "1.1.0", "2.0.0", "3.0.0", "3.1.0", "3.2.0"] ): - jsonschema.Draft4Validator.check_schema(event_schema) + schema_validator = jsonschema.Draft4Validator else: stricter_metaschema = dict( jsonschema.Draft4Validator.META_SCHEMA, additionalProperties=False ) - StrictDraft4Validator = jsonschema.validators.create( + schema_validator = jsonschema.validators.create( stricter_metaschema, jsonschema.Draft4Validator.VALIDATORS, "StrictDraft4" ) - StrictDraft4Validator.check_schema(event_schema) + + schema_validator.check_schema(event_schema)