Skip to content
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
76 changes: 71 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: continuous integration

on:
push
push:
pull_request_review:
types: [submitted]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -10,6 +12,7 @@ concurrency:
jobs:

styling:
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: checkout
Expand All @@ -31,7 +34,10 @@ jobs:
poetry run isort . --check
poetry run black . --check

# The "testing" job verifies the base SDK functionality across
# all supported Python versions.
testing:
if: github.event_name == 'push'
needs: styling
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -62,19 +68,79 @@ jobs:
run: poetry run mypy --ignore-missing-imports
- name: unit tests
run: poetry run pytest tests/unit --cov=./ --cov-report=xml
- name: build tests
run: poetry build

# We only run "integration" tests on the latest Python version.
# These tests detect if changes to ontologies, libraries, models and BuildingMOTIF
# affect correct operation of notebooks and BACnet scans. Library integration testing
# is a separate job
integration:
if: github.event_name == 'push'
needs: styling
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11']
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-java@v4 # for topquadrant shacl support
with:
distribution: 'temurin'
java-version: '21'
- name: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: install-poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0
virtualenvs-in-project: false
virtualenvs-path: ~/.virtualenvs
- name: poetry install
run: poetry install --all-extras
- name: integration tests
run: poetry run pytest tests/integration
- name: library tests
run: poetry run pytest tests/library
- name: bacnet tests
run: |
cd tests/integration/fixtures/bacnet
docker compose build device buildingmotif
docker compose run -d device
docker compose run buildingmotif poetry run pytest -m bacnet
docker compose down
- name: build tests
run: poetry build

# We only run "library" tests on the latest Python version.
# These tests detect if changes to ontologies, libraries, models and BuildingMOTIF
# affect correct operation of templates, shapes, and validation
libraries:
if: github.event.review.state == 'approved' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11']
steps:
- name: checkout
uses: actions/checkout@v4
- uses: actions/setup-java@v4 # for topquadrant shacl support
with:
distribution: 'temurin'
java-version: '21'
- name: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: install-poetry
uses: snok/install-poetry@v1
with:
version: 1.4.0
virtualenvs-in-project: false
virtualenvs-path: ~/.virtualenvs
- name: poetry install
run: poetry install --all-extras
- name: library tests
run: poetry run pytest tests/library

coverage:
needs: testing
Expand Down
32 changes: 15 additions & 17 deletions buildingmotif/dataclasses/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,28 +256,26 @@ def test_model_against_shapes(

results = {}

targets = model_graph.query(
f"""
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?target
WHERE {{
?target rdf:type/rdfs:subClassOf* <{target_class}>

}}
"""
)
# skolemize the shape graph so we have consistent identifiers across
# validation through the interpretation of the validation report
ontology_graph = ontology_graph.skolemize()

for shape_uri in shapes_to_test:
targets = model_graph.query(
f"""
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?target
WHERE {{
?target rdf:type/rdfs:subClassOf* <{target_class}>

}}
"""
)
temp_model_graph = copy_graph(model_graph)
for (s,) in targets:
temp_model_graph.add((URIRef(s), A, shape_uri))

temp_model_graph += ontology_graph.cbd(shape_uri)

# skolemize the shape graph so we have consistent identifiers across
# validation through the interpretation of the validation report
ontology_graph = ontology_graph.skolemize()

valid, report_g, report_str = shacl_validate(
temp_model_graph, ontology_graph, engine=self._bm.shacl_engine
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,8 @@
sh:qualifiedMinCount 1 ;
]
) ;
sh:property [
sh:path brick:hasPoint ;
sh:qualifiedValueShape [ sh:node :percent-oa-minimum ] ;
sh:qualifiedMinCount 1 ;
] .
# use subclassof to compose shapes
rdfs:subClassOf :percent-oa-minimum .

:percent-oa-fraction a sh:NodeShape, owl:Class ;
rdfs:label "%OA" ;
Expand Down
2 changes: 1 addition & 1 deletion notebooks/223P-Validation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"source": [
"# create a model to hold an example building from models.open223.info\n",
"lbnl_example_building = Model.create(Namespace(\"urn:lbnl\"))\n",
"lbnl_example_building.graph.parse(\"https://models.open223.info/compiled/lbnl-example.ttl\")"
"lbnl_example_building.graph.parse(\"https://models.open223.info/compiled/lbnl-bdg3-1.ttl\")"
]
},
{
Expand Down
4 changes: 3 additions & 1 deletion notebooks/Existing-model-validation-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,9 @@
"outputs": [],
"source": [
"shape_collections = [brick.get_shape_collection(), ashrae_g36.get_shape_collection()]\n",
"shapes_to_test = ashrae_g36.get_shape_collection().get_shapes_of_definition_type(BMOTIF[\"Analytics_Application\"])\n"
"shapes_to_test = ashrae_g36.get_shape_collection().get_shapes_of_definition_type(BMOTIF[\"Analytics_Application\"])\n",
"# choose the first 2 shapes to test; running them all can take a few minutes\n",
"shapes_to_test = shapes_to_test[:2]"
]
},
{
Expand Down