Skip to content

Commit 06cd44f

Browse files
authored
Optimizations to Improve testing speed (#373)
* Use graph subtraction instead of canonicalization to improve performance * Make notebook tets use topquadrant * run unit and integration tests in parallel * organize tests in lists instead of sets for reproducability across threads * Make library tests multi threaded * make library tests run sparingly again
1 parent 2f80d77 commit 06cd44f

File tree

10 files changed

+43
-40
lines changed

10 files changed

+43
-40
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ jobs:
6262
virtualenvs-path: ~/.virtualenvs
6363
- name: poetry install
6464
run: poetry install --all-extras
65+
- name: install pytest-xdist for parallel tests
66+
run: poetry run pip install pytest-xdist
6567
- name: lint
6668
run: poetry run flake8 buildingmotif
6769
- name: type check
6870
run: poetry run mypy --ignore-missing-imports
6971
- name: unit tests
70-
run: poetry run pytest tests/unit --cov=./ --cov-report=xml
72+
run: poetry run pytest -n auto tests/unit --cov=./ --cov-report=xml
7173
- name: build tests
7274
run: poetry build
7375

@@ -101,8 +103,10 @@ jobs:
101103
virtualenvs-path: ~/.virtualenvs
102104
- name: poetry install
103105
run: poetry install --all-extras
106+
- name: install pytest-xdist for parallel tests
107+
run: poetry run pip install pytest-xdist
104108
- name: integration tests
105-
run: poetry run pytest tests/integration
109+
run: poetry run pytest -n auto tests/integration
106110
- name: bacnet tests
107111
run: |
108112
cd tests/integration/fixtures/bacnet
@@ -139,8 +143,10 @@ jobs:
139143
virtualenvs-path: ~/.virtualenvs
140144
- name: poetry install
141145
run: poetry install --all-extras
146+
- name: install pytest-xdist for parallel tests
147+
run: poetry run pip install pytest-xdist
142148
- name: library tests
143-
run: poetry run pytest tests/library
149+
run: poetry run pytest -n auto tests/library
144150

145151
coverage:
146152
needs: testing

notebooks/GabeDemo.ipynb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
{
4343
"cell_type": "code",
44-
"execution_count": 2,
44+
"execution_count": null,
4545
"id": "81f0cddb-f98d-412a-85b8-a3b99b3a8c63",
4646
"metadata": {
4747
"execution": {
@@ -57,7 +57,7 @@
5757
},
5858
"outputs": [],
5959
"source": [
60-
"bm = BuildingMOTIF(\"sqlite://\") # in-memory"
60+
"bm = BuildingMOTIF(\"sqlite://\", \"topquadrant\") # in-memory"
6161
]
6262
},
6363
{
@@ -2922,7 +2922,7 @@
29222922
"metadata": {
29232923
"celltoolbar": "Slideshow",
29242924
"kernelspec": {
2925-
"display_name": "Python 3 (ipykernel)",
2925+
"display_name": ".venv",
29262926
"language": "python",
29272927
"name": "python3"
29282928
},
@@ -2936,12 +2936,7 @@
29362936
"name": "python",
29372937
"nbconvert_exporter": "python",
29382938
"pygments_lexer": "ipython3",
2939-
"version": "3.11.9"
2940-
},
2941-
"vscode": {
2942-
"interpreter": {
2943-
"hash": "15fae041f31e3c236ca4e007ba84180412c78f76afbcc47bd25b3db75fd5ecba"
2944-
}
2939+
"version": "3.10.16"
29452940
}
29462941
},
29472942
"nbformat": 4,

notebooks/Ingress-Tutorial-CSV.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
{
2525
"cell_type": "code",
26-
"execution_count": 2,
26+
"execution_count": null,
2727
"id": "4ab8e1ee-ff06-4357-8c9f-5b62c898fb8a",
2828
"metadata": {
2929
"execution": {
@@ -35,7 +35,7 @@
3535
},
3636
"outputs": [],
3737
"source": [
38-
"bm = BuildingMOTIF(\"sqlite://\") # in-memory"
38+
"bm = BuildingMOTIF(\"sqlite://\", \"topquadrant\") # in-memory"
3939
]
4040
},
4141
{
@@ -427,7 +427,7 @@
427427
],
428428
"metadata": {
429429
"kernelspec": {
430-
"display_name": "Python 3 (ipykernel)",
430+
"display_name": ".venv",
431431
"language": "python",
432432
"name": "python3"
433433
},
@@ -441,7 +441,7 @@
441441
"name": "python",
442442
"nbconvert_exporter": "python",
443443
"pygments_lexer": "ipython3",
444-
"version": "3.11.9"
444+
"version": "3.10.16"
445445
}
446446
},
447447
"nbformat": 4,

notebooks/Ingress-Tutorial-XLSX-Multiple-Sheets.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
{
2626
"cell_type": "code",
27-
"execution_count": 2,
27+
"execution_count": null,
2828
"id": "4ab8e1ee-ff06-4357-8c9f-5b62c898fb8a",
2929
"metadata": {
3030
"execution": {
@@ -36,7 +36,7 @@
3636
},
3737
"outputs": [],
3838
"source": [
39-
"bm = BuildingMOTIF(\"sqlite://\") # in-memory"
39+
"bm = BuildingMOTIF(\"sqlite://\", \"topquadrant\") # in-memory"
4040
]
4141
},
4242
{
@@ -454,7 +454,7 @@
454454
],
455455
"metadata": {
456456
"kernelspec": {
457-
"display_name": "Python 3 (ipykernel)",
457+
"display_name": ".venv",
458458
"language": "python",
459459
"name": "python3"
460460
},
@@ -468,7 +468,7 @@
468468
"name": "python",
469469
"nbconvert_exporter": "python",
470470
"pygments_lexer": "ipython3",
471-
"version": "3.11.9"
471+
"version": "3.10.16"
472472
}
473473
},
474474
"nbformat": 4,

notebooks/Ingress-Tutorial-XLSX.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
{
2626
"cell_type": "code",
27-
"execution_count": 2,
27+
"execution_count": null,
2828
"id": "4ab8e1ee-ff06-4357-8c9f-5b62c898fb8a",
2929
"metadata": {
3030
"execution": {
@@ -36,7 +36,7 @@
3636
},
3737
"outputs": [],
3838
"source": [
39-
"bm = BuildingMOTIF(\"sqlite://\") # in-memory"
39+
"bm = BuildingMOTIF(\"sqlite://\", \"topquadrant\") # in-memory"
4040
]
4141
},
4242
{
@@ -426,7 +426,7 @@
426426
],
427427
"metadata": {
428428
"kernelspec": {
429-
"display_name": "Python 3 (ipykernel)",
429+
"display_name": ".venv",
430430
"language": "python",
431431
"name": "python3"
432432
},
@@ -440,7 +440,7 @@
440440
"name": "python",
441441
"nbconvert_exporter": "python",
442442
"pygments_lexer": "ipython3",
443-
"version": "3.11.9"
443+
"version": "3.10.16"
444444
}
445445
},
446446
"nbformat": 4,

notebooks/Template-Usage.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
},
5757
{
5858
"cell_type": "code",
59-
"execution_count": 3,
59+
"execution_count": null,
6060
"id": "dfefe386-b5a5-4933-b43e-554e09a51bd1",
6161
"metadata": {
6262
"execution": {
@@ -68,7 +68,7 @@
6868
},
6969
"outputs": [],
7070
"source": [
71-
"bm = BuildingMOTIF(\"sqlite://\")\n",
71+
"bm = BuildingMOTIF(\"sqlite://\", \"topquadrant\")\n",
7272
"bldg = Model.create(\"https://example.com\")"
7373
]
7474
},
@@ -1041,7 +1041,7 @@
10411041
],
10421042
"metadata": {
10431043
"kernelspec": {
1044-
"display_name": "Python 3 (ipykernel)",
1044+
"display_name": ".venv",
10451045
"language": "python",
10461046
"name": "python3"
10471047
},
@@ -1055,7 +1055,7 @@
10551055
"name": "python",
10561056
"nbconvert_exporter": "python",
10571057
"pygments_lexer": "ipython3",
1058-
"version": "3.11.9"
1058+
"version": "3.10.16"
10591059
}
10601060
},
10611061
"nbformat": 4,

tests/library/test_223p_templates.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ def pytest_generate_tests(metafunc):
102102
run_shacl_inference=False,
103103
infer_templates=False,
104104
)
105-
templates = library.get_templates()
105+
templates = templates = sorted(
106+
library.get_templates(), key=lambda t: t.name
107+
)
106108
params.extend([(bm, s223, library, template) for template in templates])
107109

108110
# remove all templates in 'to skip'

tests/library/test_brick_templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def pytest_generate_tests(metafunc):
7777
ids = []
7878
for library_name in libraries:
7979
library = Library.load(directory=library_name, run_shacl_inference=False)
80-
templates = library.get_templates()
80+
templates = sorted(library.get_templates(), key=lambda t: t.name)
8181
params.extend([(bm, brick, library, template) for template in templates])
8282
ids.extend([f"{library.name}-{template.name}" for template in templates])
8383
metafunc.parametrize("bm,brick,library,template", params, ids=ids)

tests/unit/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,18 @@ def pytest_generate_tests(metafunc):
8989
if "library" in metafunc.fixturenames:
9090
libdir = pathlib.Path("libraries")
9191
libraries_files = libdir.rglob("*.yml")
92-
libraries = {str(lib.parent) for lib in libraries_files}
92+
libraries = [str(lib.parent) for lib in libraries_files]
9393

9494
metafunc.parametrize("library", libraries)
9595

9696
if "builtin_library" in metafunc.fixturenames:
97-
builtin_library = {"brick", "constraints"}
97+
builtin_library = ["brick", "constraints"]
9898
metafunc.parametrize("builtin_library", builtin_library)
9999

100100
if "builtin_ontology" in metafunc.fixturenames:
101-
builtin_ontology = {"brick/Brick.ttl", "constraints/constraints.ttl"}
101+
builtin_ontology = ["brick/Brick.ttl", "constraints/constraints.ttl"]
102102
metafunc.parametrize("builtin_ontology", builtin_ontology)
103103

104104
if "shacl_engine" in metafunc.fixturenames:
105-
shacl_engine = {"pyshacl", "topquadrant"}
105+
shacl_engine = ["pyshacl", "topquadrant"]
106106
metafunc.parametrize("shacl_engine", shacl_engine)

tests/unit/dataclasses/test_model.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
from rdflib import Graph, Literal, Namespace, URIRef
3-
from rdflib.compare import graph_diff, isomorphic, to_isomorphic
3+
from rdflib.compare import isomorphic
44
from rdflib.exceptions import ParserError
55
from rdflib.namespace import FOAF
66

@@ -260,18 +260,18 @@ def test_model_compile(bm: BuildingMOTIF, shacl_engine):
260260
"tests/unit/fixtures/smallOffice_brick.ttl", format="ttl"
261261
)
262262

263-
brick = Library.load(ontology_graph="libraries/brick/Brick-full.ttl")
263+
brick = Library.load(
264+
ontology_graph="libraries/brick/Brick-full.ttl", infer_templates=False
265+
)
264266

265267
compiled_model = small_office_model.compile([brick.get_shape_collection()])
266268

267269
precompiled_model = Graph().parse(
268270
"tests/unit/fixtures/smallOffice_brick_compiled.ttl", format="ttl"
269271
)
270272

271-
# returns in_both, in_first, in_second
272-
_, in_first, _ = graph_diff(
273-
to_isomorphic(precompiled_model), to_isomorphic(compiled_model.graph)
274-
)
273+
in_first = precompiled_model - compiled_model.graph
274+
275275
# passes if everything from precompiled_model is in compiled_model
276276
assert len(in_first) == 0
277277

0 commit comments

Comments
 (0)