Skip to content

Commit

Permalink
Update json schema tester to neglect old ActC versions
Browse files Browse the repository at this point in the history
  • Loading branch information
e-backmark-ericsson committed Jan 9, 2024
1 parent 0be89f8 commit 68e1ca7
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion definitions/EiffelActivityCanceledEvent/1.0.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ required:
- meta
- data
- links
additionalProperties: false
additonalProperties: false
_links:
ACTIVITY_EXECUTION:
description: Declares the activity execution that was canceled.
Expand Down
2 changes: 1 addition & 1 deletion definitions/EiffelActivityCanceledEvent/1.1.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ required:
- meta
- data
- links
additionalProperties: false
additonalProperties: false
_links:
ACTIVITY_EXECUTION:
description: Declares the activity execution that was canceled.
Expand Down
2 changes: 1 addition & 1 deletion definitions/EiffelActivityCanceledEvent/2.0.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ required:
- meta
- data
- links
additionalProperties: false
additonalProperties: false
_links:
ACTIVITY_EXECUTION:
description: Declares the activity execution that was canceled.
Expand Down
2 changes: 1 addition & 1 deletion definitions/EiffelActivityCanceledEvent/3.0.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ required:
- meta
- data
- links
additionalProperties: false
additonalProperties: false
_links:
ACTIVITY_EXECUTION:
description: Declares the activity execution that was canceled.
Expand Down
2 changes: 1 addition & 1 deletion definitions/EiffelActivityCanceledEvent/3.1.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ required:
- meta
- data
- links
additionalProperties: false
additonalProperties: false
_links:
ACTIVITY_EXECUTION:
description: Declares the activity execution that was canceled.
Expand Down
2 changes: 1 addition & 1 deletion definitions/EiffelActivityCanceledEvent/3.2.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ required:
- meta
- data
- links
additionalProperties: false
additonalProperties: false
_links:
ACTIVITY_EXECUTION:
description: Declares the activity execution that was canceled.
Expand Down
2 changes: 1 addition & 1 deletion schemas/EiffelActivityCanceledEvent/1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,5 @@
"data",
"links"
],
"additionalProperties": false
"additonalProperties": false
}
2 changes: 1 addition & 1 deletion schemas/EiffelActivityCanceledEvent/1.1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,5 @@
"data",
"links"
],
"additionalProperties": false
"additonalProperties": false
}
2 changes: 1 addition & 1 deletion schemas/EiffelActivityCanceledEvent/2.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,5 @@
"data",
"links"
],
"additionalProperties": false
"additonalProperties": false
}
2 changes: 1 addition & 1 deletion schemas/EiffelActivityCanceledEvent/3.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,5 @@
"data",
"links"
],
"additionalProperties": false
"additonalProperties": false
}
2 changes: 1 addition & 1 deletion schemas/EiffelActivityCanceledEvent/3.1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,5 @@
"data",
"links"
],
"additionalProperties": false
"additonalProperties": false
}
2 changes: 1 addition & 1 deletion schemas/EiffelActivityCanceledEvent/3.2.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,5 @@
"data",
"links"
],
"additionalProperties": false
"additonalProperties": false
}
29 changes: 22 additions & 7 deletions test_jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
7 changes: 0 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ envlist =
black
isort
jsonformat
jsonschema
pytest
markdownlint

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 68e1ca7

Please sign in to comment.