Skip to content

Commit

Permalink
update tests; test both pyshacl and topquadrant
Browse files Browse the repository at this point in the history
  • Loading branch information
gtfierro committed Mar 14, 2024
1 parent 936e830 commit 7a1a786
Show file tree
Hide file tree
Showing 6 changed files with 671 additions and 3,050 deletions.
4 changes: 2 additions & 2 deletions tests/unit/api/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def test_create_model_bad_name(client, building_motif):
assert len(building_motif.table_connection.get_all_db_models()) == 0


def test_validate_model(client, building_motif):
def test_validate_model(client, building_motif, shacl_engine):
# Set up
library_1 = Library.load(ontology_graph="tests/unit/fixtures/shapes/shape1.ttl")
assert library_1 is not None
Expand All @@ -268,7 +268,7 @@ def test_validate_model(client, building_motif):
results = client.post(
f"/models/{model.id}/validate",
headers={"Content-Type": "application/json"},
json={"library_ids": [library_1.id, library_2.id]},
json={"library_ids": [library_1.id, library_2.id], "shacl_engine": shacl_engine},
)

# Assert
Expand Down
17 changes: 8 additions & 9 deletions tests/unit/dataclasses/test_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from rdflib import BNode, Graph, Literal, Namespace, URIRef
from rdflib.compare import isomorphic
from rdflib import Graph, Literal, Namespace, URIRef
from rdflib.compare import isomorphic, graph_diff, to_isomorphic
from rdflib.namespace import FOAF

from buildingmotif import BuildingMOTIF
Expand Down Expand Up @@ -189,10 +189,6 @@ def test_validate_model_with_failure(bm: BuildingMOTIF, shacl_engine):
assert not ctx.valid
assert len(ctx.diffset) == 1
diff = next(iter(ctx.diffset.values())).pop()
assert isinstance(diff.failed_shape, BNode), (
diff.failed_shape,
type(diff.failed_shape),
)
assert diff.failed_component == SH.MinCountConstraintComponent

model.add_triples((bindings["name"], RDFS.label, Literal("hvac zone 1")))
Expand All @@ -202,7 +198,7 @@ def test_validate_model_with_failure(bm: BuildingMOTIF, shacl_engine):
assert ctx.valid


def test_model_compile(bm: BuildingMOTIF):
def test_model_compile(bm: BuildingMOTIF, shacl_engine):
"""Test that model compilation gives expected results"""
small_office_model = Model.create("http://example.org/building/")
small_office_model.graph.parse(
Expand All @@ -211,13 +207,16 @@ def test_model_compile(bm: BuildingMOTIF):

brick = Library.load(ontology_graph="libraries/brick/Brick-full.ttl")

compiled_model = small_office_model.compile([brick.get_shape_collection()])
compiled_model = small_office_model.compile([brick.get_shape_collection()], engine=shacl_engine)

precompiled_model = Graph().parse(
"tests/unit/fixtures/smallOffice_brick_compiled.ttl", format="ttl"
)

assert isomorphic(compiled_model, precompiled_model)
# returns in_both, in_first, in_second
_, in_first, _ = graph_diff(to_isomorphic(precompiled_model), to_isomorphic(compiled_model))
# passes if everything from precompiled_model is in compiled_model
assert len(in_first) == 0


def test_get_manifest(clean_building_motif):
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/fixtures/shapes/shape2.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
sh:path brick:hasPoint ;
sh:qualifiedValueShape [ sh:class brick:Air_Flow_Sensor ] ;
sh:qualifiedMinCount 1 ;
sh:message "VAV must have at least one air flow sensor" ;
sh:minCount 1;
] ;
.
Expand All @@ -24,6 +25,7 @@
sh:path brick:hasPoint ;
sh:qualifiedValueShape [ sh:class brick:Temperature_Sensor ] ;
sh:qualifiedMinCount 1 ;
sh:message "Terminal Unit must have at least one temperature sensor" ;
sh:minCount 1;
] ;
.
Expand Down
Loading

0 comments on commit 7a1a786

Please sign in to comment.