Skip to content

Commit 80442d3

Browse files
committed
QA: Test signals exist.
1 parent 5799ece commit 80442d3

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

tests/test_validate_data.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,27 @@
33

44
import pytest
55

6+
chip_cache = {}
67

7-
def validate_alt_mode(data):
8-
# name = data["name"]
9-
mode_type = data.get("type", "")
108

11-
assert mode_type != ""
12-
assert not mode_type.endswith("?")
9+
def chip_path(chip):
10+
return f"chips/{chip}.json"
11+
12+
13+
def get_chip(chip):
14+
if chip not in chip_cache:
15+
chip_cache[chip] = json.load(open(chip_path(chip)))
16+
17+
return chip_cache[chip]
1318

1419

1520
def validate_pin(data):
16-
alt_modes = data.get("alt_modes", [])
21+
chip = get_chip(data["chip"])
22+
path = chip_path(data["chip"])
23+
signal = data["signal"]
1724

18-
for alt_mode in alt_modes:
19-
validate_alt_mode(alt_mode)
25+
if signal not in chip["signals"]:
26+
raise AssertionError(f"Signal {signal} not found in {path}")
2027

2128

2229
def validate_header(data):
@@ -32,7 +39,7 @@ def validate_header(data):
3239
validate_pin(pin)
3340

3441

35-
@pytest.mark.parametrize('board_file', glob.glob("boards/*.json"))
42+
@pytest.mark.parametrize("board_file", glob.glob("boards/*.json"))
3643
def test_validate_board_json_files(board_file):
3744
data = json.load(open(board_file, "r"))
3845

tests/test_validate_json.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
import pytest
55
from jsonschema import validate
66

7-
from schema import board
7+
from schema.board import board
8+
from schema.chip import chip
89

910

10-
@pytest.mark.parametrize('board_file', glob.glob("boards/*.json"))
11+
@pytest.mark.parametrize("board_file", glob.glob("boards/*.json"))
1112
def test_validate_board_json_schema(board_file):
1213
validate(instance=json.load(open(board_file, "r")), schema=board)
14+
15+
16+
@pytest.mark.parametrize("chip_file", glob.glob("chips/*.json"))
17+
def test_validate_chip_json_schema(chip_file):
18+
validate(instance=json.load(open(chip_file, "r")), schema=chip)

0 commit comments

Comments
 (0)