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

Fix nondeterministic test failure #255

Merged
merged 2 commits into from
May 30, 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
16 changes: 14 additions & 2 deletions buildingmotif/dataclasses/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,20 @@ def reason(self) -> str:
@cached_property
def _result_uri(self) -> Node:
"""Return the 'name' of the ValidationReport to make failed_shape/failed_component
easier to express"""
return next(self.validation_result.subjects())
easier to express. We compute this by taking advantage of the fact that the validation
result graph is actually a tree with a single root. We can find the root by finding
all URIs which appear as subjects in the validation_result graph that do *not* appear
as objects; this should be exactly one URI which is the 'root' of the validation result
graph
"""
possible_uris: Set[Node] = set(self.validation_result.subjects())
objects: Set[Node] = set(self.validation_result.objects())
sub_not_obj = possible_uris - objects
if len(sub_not_obj) != 1:
raise Exception(
"Validation result has more than one 'root' node, which should not happen. Please raise an issue on https://github.com/NREL/BuildingMOTIF"
)
return sub_not_obj.pop()

@cached_property
def failed_shape(self) -> Optional[URIRef]:
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/dataclasses/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ def test_validate_model_with_failure(bm: BuildingMOTIF):
assert not ctx.valid
assert len(ctx.diffset) == 1
diff = ctx.diffset.pop()
assert isinstance(diff.failed_shape, BNode)
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 Down