Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example checker #38

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading