Skip to content

Commit

Permalink
Add test for valid schema
Browse files Browse the repository at this point in the history
  • Loading branch information
e-backmark-ericsson committed Dec 21, 2023
1 parent d09c69f commit 49978a5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 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
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
Expand Down
40 changes: 40 additions & 0 deletions test_jsonschema.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ envlist =
black
isort
jsonformat
jsonschema
pytest
markdownlint

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

0 comments on commit 49978a5

Please sign in to comment.