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] 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