Skip to content

Commit

Permalink
QA: Test signals exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Jun 16, 2024
1 parent 5799ece commit 80442d3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
25 changes: 16 additions & 9 deletions tests/test_validate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"))

Expand Down
10 changes: 8 additions & 2 deletions tests/test_validate_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 80442d3

Please sign in to comment.