From 80442d329ba49e91b86d51c5b88b8cb3d75c0b7a Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Sun, 16 Jun 2024 23:39:44 +0100 Subject: [PATCH] QA: Test signals exist. --- tests/test_validate_data.py | 25 ++++++++++++++++--------- tests/test_validate_json.py | 10 ++++++++-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/tests/test_validate_data.py b/tests/test_validate_data.py index cd27460..7233067 100644 --- a/tests/test_validate_data.py +++ b/tests/test_validate_data.py @@ -3,20 +3,27 @@ import pytest +chip_cache = {} -def validate_alt_mode(data): - # name = data["name"] - mode_type = data.get("type", "") - assert mode_type != "" - assert not mode_type.endswith("?") +def chip_path(chip): + return f"chips/{chip}.json" + + +def get_chip(chip): + if chip not in chip_cache: + chip_cache[chip] = json.load(open(chip_path(chip))) + + return chip_cache[chip] def validate_pin(data): - alt_modes = data.get("alt_modes", []) + chip = get_chip(data["chip"]) + path = chip_path(data["chip"]) + signal = data["signal"] - for alt_mode in alt_modes: - validate_alt_mode(alt_mode) + if signal not in chip["signals"]: + raise AssertionError(f"Signal {signal} not found in {path}") def validate_header(data): @@ -32,7 +39,7 @@ def validate_header(data): validate_pin(pin) -@pytest.mark.parametrize('board_file', glob.glob("boards/*.json")) +@pytest.mark.parametrize("board_file", glob.glob("boards/*.json")) def test_validate_board_json_files(board_file): data = json.load(open(board_file, "r")) diff --git a/tests/test_validate_json.py b/tests/test_validate_json.py index 9e5789f..28c6a78 100644 --- a/tests/test_validate_json.py +++ b/tests/test_validate_json.py @@ -4,9 +4,15 @@ import pytest from jsonschema import validate -from schema import board +from schema.board import board +from schema.chip import chip -@pytest.mark.parametrize('board_file', glob.glob("boards/*.json")) +@pytest.mark.parametrize("board_file", glob.glob("boards/*.json")) def test_validate_board_json_schema(board_file): validate(instance=json.load(open(board_file, "r")), schema=board) + + +@pytest.mark.parametrize("chip_file", glob.glob("chips/*.json")) +def test_validate_chip_json_schema(chip_file): + validate(instance=json.load(open(chip_file, "r")), schema=chip)