Skip to content

Commit

Permalink
parameterize testing of templates for 223p
Browse files Browse the repository at this point in the history
  • Loading branch information
gtfierro committed Apr 10, 2024
1 parent 81d0205 commit eb3d28b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 16 deletions.
21 changes: 20 additions & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

from buildingmotif import BuildingMOTIF
from buildingmotif.dataclasses import Library


def pytest_generate_tests(metafunc):
Expand All @@ -23,12 +24,30 @@ def pytest_generate_tests(metafunc):

metafunc.parametrize("notebook", notebook_files)

libraries = ["libraries/ashrae/223p/nrel-templates"]
# validates 223P libraries
if "library_path_223p" in metafunc.fixturenames:
libraries = ["libraries/ashrae/223p/nrel-templates"]

metafunc.parametrize("library_path_223p", libraries)

if (
"library_path_223p" in metafunc.fixturenames
and "template_223p" in metafunc.fixturenames
):
bm = BuildingMOTIF("sqlite://")
bm.setup_tables()

templates = []
# load library
for library_path in libraries:
lib = Library.load(directory=library_path)
bm.session.commit()

for templ in lib.get_templates():
templates.append(templ.name)

metafunc.parametrize("template_223p", templates)


@pytest.fixture
def bm():
Expand Down
53 changes: 38 additions & 15 deletions tests/integration/test_library_validity.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,45 @@ def plug_223_connection_points(g: Graph):

@pytest.mark.integration
def test_223p_library(bm, library_path_223p: Path):
Library.load(ontology_graph="libraries/ashrae/223p/ontology/223p.ttl")
Library.load(directory=str(library_path_223p))
bm.session.commit()

# MODEL = Namespace("urn:ex/")
# for templ in lib.get_templates():
# print(templ.name)
# if templ.name in S223_SKIP_TEMPLATES:
# print(" ...skipping")
# continue
# m = Model.create(MODEL)
# _, g = templ.inline_dependencies().fill(MODEL, include_optional=False)
# assert isinstance(g, Graph), "was not a graph"
# bind_prefixes(g)
# plug_223_connection_points(g)
# m.add_graph(g)
# m.graph.serialize("/tmp/model.ttl")
# ctx = m.validate([ont_223p.get_shape_collection()], engine="topquadrant")
# ctx.report.serialize("/tmp/report.ttl")
# assert ctx.valid, ctx.report_string
# bm.session.rollback()


@pytest.mark.integration
def test_223p_template(bm, library_path_223p, template_223p):
ont_223p = Library.load(ontology_graph="libraries/ashrae/223p/ontology/223p.ttl")

lib = Library.load(directory=str(library_path_223p))
bm.session.commit()

template_223p = lib.get_template_by_name(template_223p)

MODEL = Namespace("urn:ex/")
for templ in lib.get_templates():
print(templ.name)
if templ.name in S223_SKIP_TEMPLATES:
print(" ...skipping")
continue
m = Model.create(MODEL)
_, g = templ.inline_dependencies().fill(MODEL, include_optional=False)
assert isinstance(g, Graph), "was not a graph"
bind_prefixes(g)
plug_223_connection_points(g)
m.add_graph(g)
ctx = m.validate([ont_223p.get_shape_collection()], engine="topquadrant")
assert ctx.valid, ctx.report_string
bm.session.rollback()
m = Model.create(MODEL)
_, g = template_223p.inline_dependencies().fill(MODEL, include_optional=False)
assert isinstance(g, Graph), "was not a graph"
bind_prefixes(g)
plug_223_connection_points(g)
m.add_graph(g)
m.graph.serialize("/tmp/model.ttl")
ctx = m.validate([ont_223p.get_shape_collection()], engine="topquadrant")
ctx.report.serialize("/tmp/report.ttl")
assert ctx.valid, ctx.report_string

0 comments on commit eb3d28b

Please sign in to comment.