Skip to content

Commit

Permalink
QA/CI: Schema validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Jun 16, 2024
1 parent a0dd079 commit 0d86fbe
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Pinout.xyz - 2024

A ground-up rewrite of Pinout.xyz.
7 changes: 4 additions & 3 deletions boards/raspberry-pi-5.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "Raspberry Pi 5",
"headers": {
"j8": {
"headers": [
{
"name": "j8",
"width": 2,
"height": 20,
"orientation": 0,
Expand Down Expand Up @@ -328,5 +329,5 @@
]}
]
}
}
]
}
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ ruff
codespell
isort
tox
jsonschema
60 changes: 60 additions & 0 deletions schema/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
valid_alt_mode_types = ["I2C", "SPI", "DPI", "DSI", "UART", "PIO", "I2S", "GPCLOCK"]
valid_orientations = [0, 90, 180, 270]
valid_directions = ["alternating", "around"]
valid_pin_types = ["gpio", "power", "nc"]
valid_pin_subtypes = ["+5v", "+3v3", "ground"]

board = {
"type": "object",
"properties": {
"name": {"type": "string"},
"headers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"width": {"type": "number"},
"height": {"type": "number"},
"orientation": {"type": "number", "enum": valid_orientations},
"direction": {"type": "string", "enum": valid_directions},
"pins": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"type": {"type": "string", "enum": valid_pin_types},
"subtype": {"type": "string", "enum": valid_pin_subtypes},
"alt_modes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"type": {"type": "string", "enum": valid_alt_mode_types},
"used": {"type": "boolean"}
},
"required": [
"name"
]
}
}
},
"required": [
"name"
]
},
"unevaluatedItems": False
}
},
"required": [
"name",
"width",
"height"
]
},
"unevaluatedItems": False
}
}
}
3 changes: 2 additions & 1 deletion tests/test_validate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def validate_pin(data):


def validate_header(data):
# name = data["name"]
width = data["width"]
height = data["height"]
# orientation = data["orientation"]
Expand All @@ -35,5 +36,5 @@ def validate_header(data):
def test_validate_board_json_files(board_file):
data = json.load(open(board_file, "r"))

for name, header in data["headers"].items():
for header in data["headers"]:
validate_header(header)
12 changes: 12 additions & 0 deletions tests/test_validate_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import glob
import json

import pytest
from jsonschema import validate

from schema import board


@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)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ deps =
mock
pytest>=3.1
pytest-cov
build
jsonschema

[testenv:qa]
commands =
Expand Down

0 comments on commit 0d86fbe

Please sign in to comment.