Skip to content

Commit

Permalink
Add example checker (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt authored Oct 12, 2023
1 parent 1cae09e commit bbb378c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ where = src
tests =
pytest
coverage
jsonschema
docs =
sphinx
sphinx-rtd-theme
Expand Down
8 changes: 8 additions & 0 deletions src/acsets/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Schemas and examples."""

from pathlib import Path

HERE = Path(__file__).parent.resolve()
CATLAB = HERE.joinpath("catlab")
JSONSCHEMA = HERE.joinpath("jsonschema")
EXAMPLES = HERE.joinpath("examples")
3 changes: 3 additions & 0 deletions src/acsets/schemas/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Examples

This repository contains examples corresponding to the JSON schemata.
23 changes: 23 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Test that the examples are valid."""

import json
import unittest

import jsonschema
from acsets.schemas import EXAMPLES, CATLAB, JSONSCHEMA


class TestExamples(unittest.TestCase):
"""Test all examples are valid wrt their related schema."""

def test_examples_valid(self):
"""Test examples."""
for example in EXAMPLES.glob("*.json"):
with self.subTest(example=example.name):
jsonschema_path = JSONSCHEMA.joinpath(example.name)
self.assertTrue(
jsonschema_path.is_file(), msg="No corresponding JSON schema for example"
)
jsonschema_obj = json.loads(jsonschema_path.read_text())
example_obj = json.loads(example.read_text())
jsonschema.validate(instance=example_obj, schema=jsonschema_obj)

0 comments on commit bbb378c

Please sign in to comment.