Skip to content

Commit a626ac5

Browse files
committed
working on tests
1 parent ae075d1 commit a626ac5

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

tests/conftest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import pytest
2+
from ontoenv import OntoEnv, Config
3+
import brickschema
4+
from rdflib import RDF, RDFS, BRICK, OWL, Namespace
5+
6+
QUDT = Namespace("http://qudt.org/schema/qudt/")
27

38
# using code from https://docs.pytest.org/en/latest/example/simple.html
49

@@ -31,3 +36,19 @@ def pytest_generate_tests(metafunc):
3136
# validates that example files pass validation
3237
if "inference_backend" in metafunc.fixturenames:
3338
metafunc.parametrize("inference_backend", ["owlrl", "allegro", "reasonable"])
39+
40+
41+
@pytest.fixture()
42+
def brick_with_imports():
43+
cfg = Config([], strict=False, offline=False, temporary=True)
44+
env = OntoEnv(cfg)
45+
# TODO: need to add rdflib graph to the environment directly
46+
g = brickschema.Graph(load_brick=True)
47+
g.bind("qudt", QUDT)
48+
g.bind("rdf", RDF)
49+
g.bind("rdfs", RDFS)
50+
g.bind("brick", BRICK)
51+
imported = env.import_dependencies(g, fetch_missing=True, recursion_depth=1)
52+
print(f"Imported {len(imported)} dependencies into the Brick graph.: {imported}")
53+
g.serialize("/tmp/brick_with_imports.ttl", format="turtle")
54+
return g

tests/test_validate.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import brickschema
2-
from rdflib import Graph
2+
from ontoenv import OntoEnv, Config
3+
from rdflib import Graph, OWL
34
import pytest
45
import os
56
import sys
@@ -20,24 +21,24 @@ def loadGraph(resource) -> brickschema.Graph:
2021
# can have impact, too.
2122

2223

23-
def test_validate_bad():
24+
def test_validate_bad(brick_with_imports):
2425
dataG = loadGraph("data/badBuilding.ttl")
25-
brickG = brickschema.Graph(load_brick=True)
26-
conforms, _, _ = dataG.validate(shape_graphs=[brickG], engine="topquadrant")
26+
# remove imports from the Brick graph
27+
conforms, _, _ = dataG.validate(shape_graphs=[brick_with_imports], engine="topquadrant")
2728
assert not conforms, "expect constraint violations in badBuilding.ttl"
2829

2930

30-
def test_validate_ok():
31+
def test_validate_ok(brick_with_imports):
3132
dataG = loadGraph("data/goodBuilding.ttl")
32-
brickG = brickschema.Graph(load_brick=True)
33-
conforms, _, report_str = dataG.validate(shape_graphs=[brickG], engine="topquadrant")
33+
conforms, _, report_str = dataG.validate(shape_graphs=[brick_with_imports], engine="topquadrant")
3434
assert conforms, f"expect no constraint violations in goodBuilding.ttl {report_str}"
3535

3636

3737
def test_useOnlyExtraShapeGraph():
3838
dataG = loadGraph("data/badBuilding.ttl")
3939
shapeG = loadGraph("data/extraShapes.ttl")
4040
brickG = brickschema.Graph(load_brick=True)
41+
brickG.remove((None, OWL.imports, None))
4142
conforms, _, _ = dataG.validate(shape_graphs=[shapeG, brickG], engine="topquadrant")
4243
assert not conforms, "expect constraint violations in badBuilding.ttl"
4344

@@ -46,6 +47,7 @@ def test_useExtraShapeGraph():
4647
dataG = loadGraph("data/badBuilding.ttl")
4748
shapeG = loadGraph("data/extraShapes.ttl")
4849
brickG = brickschema.Graph(load_brick=True)
50+
brickG.remove((None, OWL.imports, None))
4951
conforms, _, _ = dataG.validate(shape_graphs=[shapeG, brickG], engine="topquadrant")
5052
assert not conforms, "expect constraint violations in badBuilding.ttl"
5153

@@ -55,6 +57,7 @@ def test_useExtraOntGraphShapeGraph():
5557
ontG1 = loadGraph("data/extraOntology1.ttl")
5658
ontG2 = loadGraph("data/extraOntology2.ttl")
5759
brickG = brickschema.Graph(load_brick=True)
60+
brickG.remove((None, OWL.imports, None))
5861

5962
# Without extra shapes for the extra ontology files
6063
# we shouldn't see more violations

0 commit comments

Comments
 (0)