Skip to content

Commit 99ae768

Browse files
committed
test_feature - clean up .ifc.cache. files after test was executed
1 parent fb902a0 commit 99ae768

File tree

3 files changed

+46
-21
lines changed

3 files changed

+46
-21
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ src/bonsai/bonsai/translations.py
7878

7979
# bonsai test temp files
8080
src/bonsai/test/files/temp
81-
src/bonsai/test/files/basic.ifc.cache.blend
82-
src/bonsai/test/files/basic.ifc.cache.sqlite
8381

8482
# bonsai data
8583
src/bonsai/bonsai/bim/data/build/

src/bonsai/test/bim/feature/project.feature

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ Scenario: Load project elements - all georeferencing coordinate situations with
679679

680680
Scenario: Link IFC
681681
Given an empty IFC project
682-
When I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')"
682+
When I link IFC project from "{cwd}/test/files/basic.ifc"
683683
Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_loaded" is "True"
684684
And the collection "IfcProject/basic.ifc" exists
685685
And the object "Chunk" exists
@@ -690,7 +690,7 @@ Scenario: Link IFC - disabled false origin mode
690690
# Not currently possible via UI
691691
And I set "scene.BIMProjectProperties.distance_limit" to "5"
692692
And I set "scene.BIMProjectProperties.false_origin_mode" to "DISABLED"
693-
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation.ifc', use_cache=False)"
693+
When I link IFC project from "{cwd}/test/files/geolocation.ifc"
694694
Then the object "Chunk" exists
695695
And the object "Chunk" has a vertex at "2,2,-1"
696696
And the object "Chunk" has a vertex at "9,-1,-1"
@@ -701,7 +701,7 @@ Scenario: Link IFC - from an empty IFC project - automatic false origin mode (0,
701701
# Not currently possible via UI
702702
And I set "scene.BIMProjectProperties.distance_limit" to "5"
703703
And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC"
704-
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation.ifc', use_cache=False)"
704+
When I link IFC project from "{cwd}/test/files/geolocation.ifc"
705705
Then the object "Chunk" exists
706706
And the object "Chunk" has a vertex at "2,2,-1"
707707
And the object "Chunk" has a vertex at "9,-1,-1"
@@ -712,7 +712,7 @@ Scenario: Link IFC - from an empty Blender session - automatic false origin mode
712712
# Not currently possible via UI
713713
And I set "scene.BIMProjectProperties.distance_limit" to "5"
714714
And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC"
715-
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation.ifc', use_cache=False)"
715+
When I link IFC project from "{cwd}/test/files/geolocation.ifc"
716716
Then the object "Chunk" exists
717717
And the object "Chunk" has a vertex at "-11,-2,0"
718718
And the object "Chunk" has a vertex at "-4,-5,0"
@@ -724,7 +724,7 @@ Scenario: Link IFC - manual false origin mode
724724
And I set "scene.BIMProjectProperties.distance_limit" to "5"
725725
And I set "scene.BIMProjectProperties.false_origin_mode" to "MANUAL"
726726
And I set "scene.BIMProjectProperties.false_origin" to "10000,0,0"
727-
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation.ifc', use_cache=False)"
727+
When I link IFC project from "{cwd}/test/files/geolocation.ifc"
728728
Then the object "Chunk" exists
729729
And the object "Chunk" has a vertex at "-8,2,-1"
730730
And the object "Chunk" has a vertex at "-1,-1,-1"
@@ -735,8 +735,8 @@ Scenario: Link IFC - automatic false origin mode - two different false origins a
735735
# Not currently possible via UI
736736
And I set "scene.BIMProjectProperties.distance_limit" to "5"
737737
And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC"
738-
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation.ifc', use_cache=False)"
739-
And I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation-mapconversion-angle.ifc', use_cache=False)"
738+
When I link IFC project from "{cwd}/test/files/geolocation.ifc"
739+
And I link IFC project from "{cwd}/test/files/geolocation-mapconversion-angle.ifc"
740740
Then the object "Col:IfcProject/geolocation.ifc:Chunk" exists
741741
And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" exists
742742
And the object "Col:IfcProject/geolocation.ifc:Chunk" has a vertex at "-11,-2,0"
@@ -751,8 +751,8 @@ Scenario: Link IFC - automatic false origin mode - two different false origins a
751751
# Not currently possible via UI
752752
And I set "scene.BIMProjectProperties.distance_limit" to "5"
753753
And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC"
754-
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation-mapconversion-angle.ifc', use_cache=False)"
755-
And I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation.ifc', use_cache=False)"
754+
When I link IFC project from "{cwd}/test/files/geolocation-mapconversion-angle.ifc"
755+
And I link IFC project from "{cwd}/test/files/geolocation.ifc"
756756
Then the object "Col:IfcProject/geolocation.ifc:Chunk" exists
757757
And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" exists
758758
And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" has a vertex at "-11,-2,0"
@@ -767,9 +767,9 @@ Scenario: Link IFC - automatic false origin mode - three identical false origins
767767
# Not currently possible via UI
768768
And I set "scene.BIMProjectProperties.distance_limit" to "5"
769769
And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC"
770-
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation-unit1.ifc', use_cache=False)"
771-
And I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation-unit2.ifc', use_cache=False)"
772-
And I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation-unit3.ifc', use_cache=False)"
770+
When I link IFC project from "{cwd}/test/files/geolocation-unit1.ifc"
771+
And I link IFC project from "{cwd}/test/files/geolocation-unit2.ifc"
772+
And I link IFC project from "{cwd}/test/files/geolocation-unit3.ifc"
773773
Then the object "Col:IfcProject/geolocation-unit1.ifc:Chunk" exists
774774
And the object "Col:IfcProject/geolocation-unit2.ifc:Chunk" exists
775775
And the object "Col:IfcProject/geolocation-unit3.ifc:Chunk" exists
@@ -779,7 +779,7 @@ Scenario: Link IFC - automatic false origin mode - three identical false origins
779779

780780
Scenario: Toggle link visibility - wireframe mode
781781
Given an empty IFC project
782-
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')"
782+
And I link IFC project from "{cwd}/test/files/basic.ifc"
783783
When I press "bim.toggle_link_visibility(link='{cwd}/test/files/basic.ifc', mode='WIREFRAME')"
784784
Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_wireframe" is "True"
785785
And the object "Chunk" should display as "WIRE"
@@ -789,7 +789,7 @@ Scenario: Toggle link visibility - wireframe mode
789789

790790
Scenario: Toggle link selectability
791791
Given an empty IFC project
792-
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')"
792+
And I link IFC project from "{cwd}/test/files/basic.ifc"
793793
When I press "bim.toggle_link_selectability(link='{cwd}/test/files/basic.ifc')"
794794
Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_selectable" is "False"
795795
And the collection "IfcProject/basic.ifc" is unselectable
@@ -799,7 +799,7 @@ Scenario: Toggle link selectability
799799

800800
Scenario: Toggle link visibility - visible mode
801801
Given an empty IFC project
802-
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')"
802+
And I link IFC project from "{cwd}/test/files/basic.ifc"
803803
When I press "bim.toggle_link_visibility(link='{cwd}/test/files/basic.ifc', mode='VISIBLE')"
804804
Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_hidden" is "True"
805805
And the object "IfcProject/basic.ifc" is not visible
@@ -809,22 +809,22 @@ Scenario: Toggle link visibility - visible mode
809809

810810
Scenario: Unload link
811811
Given an empty Blender session
812-
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')"
812+
And I link IFC project from "{cwd}/test/files/basic.ifc"
813813
When I press "bim.unload_link(filepath='{cwd}/test/files/basic.ifc')"
814814
Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_loaded" is "False"
815815
And the collection "IfcProject/basic.ifc" does not exist
816816

817817
Scenario: Load link
818818
Given an empty Blender session
819-
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')"
819+
And I link IFC project from "{cwd}/test/files/basic.ifc"
820820
And I press "bim.unload_link(filepath='{cwd}/test/files/basic.ifc')"
821821
When I press "bim.load_link(filepath='{cwd}/test/files/basic.ifc')"
822822
Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_loaded" is "True"
823823
And the object "IfcProject/basic.ifc" exists
824824

825825
Scenario: Unlink IFC
826826
Given an empty Blender session
827-
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')"
827+
And I link IFC project from "{cwd}/test/files/basic.ifc"
828828
And I press "bim.unload_link(filepath='{cwd}/test/files/basic.ifc')"
829829
When I press "bim.unlink_ifc(filepath='{cwd}/test/files/basic.ifc')"
830830
Then "scene.BIMProjectProperties.links.get('{cwd}/test/files/basic.ifc')" is "None"

src/bonsai/test/bim/test_feature.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import ifcopenshell.util.representation
3333
import bonsai.tool as tool
3434
import bonsai.bim.handler
35+
from collections.abc import Generator
3536
from bonsai.bim.ifc import IfcStore
3637
from bonsai.tool.brick import BrickStore
3738
from bonsai.bim.module.model.data import AuthoringData
@@ -66,7 +67,10 @@
6667
as resets the ``bpy.context`` and some it's members become `None`.
6768
"""
6869

69-
TMP = Path(f"{variables['cwd']}/test/files/temp")
70+
TMP = Path.cwd() / "test/files/temp"
71+
TEST_FILES_DIR = Path.cwd() / "test/files"
72+
73+
CLEAN_LINKED_FILES_CACHE = False
7074

7175

7276
class PanelSpy:
@@ -292,6 +296,19 @@ def vectors_are_equal(v1, v2):
292296
return all(is_x(v1[i], v2[i]) for i in range(len(v1)))
293297

294298

299+
@pytest.fixture(scope="function", autouse=True)
300+
def run_for_each_test() -> Generator[None]:
301+
# Code before this runs before each test
302+
yield
303+
# Code after this runs after each test
304+
305+
global CLEAN_LINKED_FILES_CACHE
306+
if CLEAN_LINKED_FILES_CACHE:
307+
for filepath in TEST_FILES_DIR.glob("*.ifc.cache.*"):
308+
filepath.unlink()
309+
CLEAN_LINKED_FILES_CACHE = False
310+
311+
295312
@given("an untestable scenario")
296313
def an_untestable_scenario():
297314
pass
@@ -346,6 +363,16 @@ def saving_ifc_project() -> None:
346363
tool.Project.save_test_project()
347364

348365

366+
@given(parsers.parse('I link IFC project from "{filepath}"'))
367+
@when(parsers.parse('I link IFC project from "{filepath}"'))
368+
@then(parsers.parse('I link IFC project from "{filepath}"'))
369+
def i_link_ifc_project_from_filepath(filepath: str) -> None:
370+
global CLEAN_LINKED_FILES_CACHE
371+
filepath = replace_variables(filepath)
372+
CLEAN_LINKED_FILES_CACHE = True
373+
bpy.ops.bim.link_ifc(filepath=filepath, use_cache=False)
374+
375+
349376
@given("the Brickschema is stubbed")
350377
def the_brickschema_is_stubbed():
351378
# This makes things run faster since we don't need to load the entire brick schema

0 commit comments

Comments
 (0)