Skip to content

Commit 48dd8b6

Browse files
committed
test: validate BIDS schema against metaschema with check-jsonschema
1 parent 280ac9a commit 48dd8b6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

tools/schemacode/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ render = [
3737
]
3838
tests = [
3939
"bidsschematools[expressions,render]",
40+
"check-jsonschema",
4041
"codecov",
4142
"coverage[toml]",
4243
"flake8",

tools/schemacode/src/bidsschematools/tests/test_schema.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"""Tests for the bidsschematools package."""
22

3+
import json
34
import os
5+
import subprocess
46
from collections.abc import Mapping
7+
from importlib.resources import files
58

69
import pytest
710
from jsonschema.exceptions import ValidationError
@@ -365,6 +368,38 @@ def test_valid_schema():
365368
schema.validate_schema(namespace)
366369

367370

371+
@pytest.mark.parametrize("regex_variant", ["default", "nonunicode", "python"])
372+
def test_valid_schema_with_check_json_schema(tmp_path, regex_variant):
373+
"""
374+
Test that the BIDS schema is valid against the metaschema when validation is done
375+
using the `check-jsonschema` CLI
376+
"""
377+
bids_schema = schema.load_schema().to_dict()
378+
metaschema_path = str(files("bidsschematools.data").joinpath("metaschema.json"))
379+
380+
# Save BIDS schema to a temporary file
381+
bids_schema_path = tmp_path / "bids_schema.json"
382+
bids_schema_path.write_text(json.dumps(bids_schema))
383+
384+
# Invoke the check-jsonschema to validate the BIDS schema
385+
try:
386+
subprocess.run(
387+
[
388+
"check-jsonschema",
389+
"--regex-variant",
390+
regex_variant,
391+
"--schemafile",
392+
metaschema_path,
393+
str(bids_schema_path),
394+
],
395+
capture_output=True,
396+
text=True,
397+
check=True,
398+
)
399+
except subprocess.CalledProcessError as e:
400+
pytest.fail(f"check-jsonschema failed with code {e.returncode}: {e.stderr}")
401+
402+
368403
def test_add_legal_field():
369404
"""Test that adding a legal field does not raise an error."""
370405
namespace = schema.load_schema()

0 commit comments

Comments
 (0)