diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 406479cb3..f84dc4d19 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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: @@ -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 @@ -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 diff --git a/buildingmotif/dataclasses/model.py b/buildingmotif/dataclasses/model.py index 4d9dc6549..812d832e9 100644 --- a/buildingmotif/dataclasses/model.py +++ b/buildingmotif/dataclasses/model.py @@ -253,28 +253,26 @@ def test_model_against_shapes( results = {} + targets = model_graph.query( + f""" + PREFIX rdf: + PREFIX rdfs: + 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: - PREFIX rdfs: - 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 ) diff --git a/notebooks/Existing-model-validation-example.ipynb b/notebooks/Existing-model-validation-example.ipynb index 73c846c76..e4955352e 100644 --- a/notebooks/Existing-model-validation-example.ipynb +++ b/notebooks/Existing-model-validation-example.ipynb @@ -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]" ] }, {