-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update .gitignore * Create requirements.txt * Add Github action * format with isort and black * set up basic test * fix small GHA issue * added pytest as a requirement * fix file path * Update conftest.py * fix file paths * add tests * fix tests
- Loading branch information
Showing
11 changed files
with
132 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Test schema | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
pytest: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
|
||
- name: Install packages | ||
run: | | ||
python -m pip install --upgrade pip wheel setuptools | ||
python -m pip install -r requirements.txt | ||
python -m pip list | ||
- name: Test schema | ||
run: | | ||
# run test suite | ||
pytest --color=yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fastjsonschema | ||
pytest | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import json | ||
|
||
import pytest | ||
import requests | ||
|
||
schema_location = "https://raw.githubusercontent.com/pszufe/HIF_validators/main/schemas/hif_schema_v0.1.0.json" | ||
json_dir = "tests/test_files" | ||
|
||
|
||
@pytest.fixture | ||
def schema(): | ||
r = requests.get(schema_location) | ||
|
||
if r.ok: | ||
return r.json() | ||
|
||
|
||
@pytest.fixture | ||
def empty(): | ||
return json.load(open(f"{json_dir}/empty.json", "r")) | ||
|
||
|
||
@pytest.fixture | ||
def bad_top_level_field(): | ||
return json.load(open(f"{json_dir}/bad_top_level_field.json", "r")) | ||
|
||
|
||
@pytest.fixture | ||
def metadata_as_list(): | ||
return json.load(open(f"{json_dir}/metadata_as_list.json", "r")) | ||
|
||
|
||
@pytest.fixture | ||
def empty_hypergraph(): | ||
return json.load(open(f"{json_dir}/empty_hypergraph.json", "r")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"test": {"prop1": "test"}, "incidences": []} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"incidences": []} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"metadata": [0, 1, 2], "incidences": []} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import fastjsonschema | ||
import pytest | ||
|
||
|
||
def test_empty(schema, empty): | ||
validator = fastjsonschema.compile(schema) | ||
with pytest.raises(ValueError): | ||
validator(empty) | ||
|
||
|
||
def test_bad_top_level_field(schema, bad_top_level_field): | ||
validator = fastjsonschema.compile(schema) | ||
with pytest.raises(ValueError): | ||
validator(bad_top_level_field) | ||
|
||
|
||
def test_metadata_as_list(schema, metadata_as_list): | ||
validator = fastjsonschema.compile(schema) | ||
with pytest.raises(ValueError): | ||
validator(metadata_as_list) | ||
|
||
|
||
def test_empty_hypergraph(schema, empty_hypergraph): | ||
validator = fastjsonschema.compile(schema) | ||
validator(empty_hypergraph) |