Skip to content

Commit

Permalink
separating out testing
Browse files Browse the repository at this point in the history
  • Loading branch information
calmacx committed Mar 21, 2024
1 parent c186aaa commit 1ceef6e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 46 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ jobs:
- name: Run pytest
run: |
cd hdr_schemata/tests/
pytest
pytest test_gwdm.py
pytest test_hdruk.py
pytest test_schemaOrg.py
deploy:
runs-on: ubuntu-latest
needs: test
Expand Down
37 changes: 37 additions & 0 deletions hdr_schemata/tests/test_gwdm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from pydantic import ValidationError
import json

from hdr_schemata.models.GWDM import Gwdm10


def get_metadata(model, version):
metadata = json.load(open(f"../examples/{model}/{version}/example.json"))
return metadata


def get_schema(model, version):
metadata = json.load(open(f"../models/{model}/{version}/schema.json"))
return metadata


class TestGwdm10:
def __init__(self):
self.metadata = get_metadata("GWDM", "1.0")
self.json_schema = get_schema("GWDM", "1.0")

def test_validation(self):
assert Gwdm10(**self.metadata) != None

def test_json_schema(self):
schema = Gwdm10.model_json_schema()
expected_keys = [
"$defs",
"additionalProperties",
"properties",
"required",
"title",
"type",
]

assert list(schema.keys()) == expected_keys
assert schema == self.json_schema
34 changes: 34 additions & 0 deletions hdr_schemata/tests/test_hdruk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from pydantic import ValidationError
import json
from hdr_schemata.models.HDRUK import Hdruk212


def get_metadata(model, version):
metadata = json.load(open(f"../examples/{model}/{version}/example.json"))
return metadata


def get_schema(model, version):
metadata = json.load(open(f"../models/{model}/{version}/schema.json"))
return metadata


class TestHdruk212:
metadata = get_metadata("HDRUK", "2.1.2")
json_schema = get_schema("HDRUK", "2.1.2")

def test_validation(self):
assert Hdruk212(**self.metadata) != None

def test_json_schema(self):
schema = Hdruk212.model_json_schema()
expected_keys = [
"$defs",
"additionalProperties",
"properties",
"required",
"title",
"type",
]
assert list(schema.keys()) == expected_keys
assert schema == self.json_schema
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from pydantic import ValidationError
import json

from hdr_schemata.models.HDRUK import Hdruk212
from hdr_schemata.models.GWDM import Gwdm10
from hdr_schemata.models.SchemaOrg import GoogleRecommendedDataset
from hdr_schemata.models.SchemaOrg import BioSchema

Expand All @@ -17,49 +15,6 @@ def get_schema(model, version):
return metadata


class TestHdruk212:
metadata = get_metadata("HDRUK", "2.1.2")
json_schema = get_schema("HDRUK", "2.1.2")

def test_validation(self):
assert Hdruk212(**self.metadata) != None

def test_json_schema(self):
schema = Hdruk212.model_json_schema()
expected_keys = [
"$defs",
"additionalProperties",
"properties",
"required",
"title",
"type",
]
assert list(schema.keys()) == expected_keys
assert schema == self.json_schema


class TestGwdm10:
metadata = get_metadata("GWDM", "1.0")
json_schema = get_schema("GWDM", "1.0")

def test_validation(self):
assert Gwdm10(**self.metadata) != None

def test_json_schema(self):
schema = Gwdm10.model_json_schema()
expected_keys = [
"$defs",
"additionalProperties",
"properties",
"required",
"title",
"type",
]

assert list(schema.keys()) == expected_keys
assert schema == self.json_schema


class TestGoogleRecommended:
metadata = get_metadata("SchemaOrg", "GoogleRecommended")
json_schema = get_schema("SchemaOrg", "GoogleRecommended")
Expand Down

0 comments on commit 1ceef6e

Please sign in to comment.