Skip to content

Commit

Permalink
conflicts Merge branch 'develop' into guideline36-section4
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewSteen committed Sep 16, 2024
2 parents 84c883e + 219c9c8 commit 3863a49
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 21 deletions.
74 changes: 71 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
name: continuous integration

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

jobs:

styling:
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: checkout
Expand All @@ -27,7 +30,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 @@ -58,6 +64,39 @@ 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: bacnet tests
Expand All @@ -67,8 +106,37 @@ jobs:
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 @@ -253,28 +253,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
)
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 @@ -321,7 +321,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

0 comments on commit 3863a49

Please sign in to comment.