test_feature - clean up .ifc.cache. files after test was executed

This commit is contained in:
Andrej730
2025-11-17 11:48:57 +05:00
parent fb902a04f5
commit 99ae768ddf
3 changed files with 46 additions and 21 deletions
-2
View File
@@ -78,8 +78,6 @@ src/bonsai/bonsai/translations.py
# bonsai test temp files # bonsai test temp files
src/bonsai/test/files/temp src/bonsai/test/files/temp
src/bonsai/test/files/basic.ifc.cache.blend
src/bonsai/test/files/basic.ifc.cache.sqlite
# bonsai data # bonsai data
src/bonsai/bonsai/bim/data/build/ src/bonsai/bonsai/bim/data/build/
+18 -18
View File
@@ -679,7 +679,7 @@ Scenario: Load project elements - all georeferencing coordinate situations with
Scenario: Link IFC Scenario: Link IFC
Given an empty IFC project Given an empty IFC project
When I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')" When I link IFC project from "{cwd}/test/files/basic.ifc"
Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_loaded" is "True" Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_loaded" is "True"
And the collection "IfcProject/basic.ifc" exists And the collection "IfcProject/basic.ifc" exists
And the object "Chunk" exists And the object "Chunk" exists
@@ -690,7 +690,7 @@ Scenario: Link IFC - disabled false origin mode
# Not currently possible via UI # Not currently possible via UI
And I set "scene.BIMProjectProperties.distance_limit" to "5" And I set "scene.BIMProjectProperties.distance_limit" to "5"
And I set "scene.BIMProjectProperties.false_origin_mode" to "DISABLED" And I set "scene.BIMProjectProperties.false_origin_mode" to "DISABLED"
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation.ifc', use_cache=False)" When I link IFC project from "{cwd}/test/files/geolocation.ifc"
Then the object "Chunk" exists Then the object "Chunk" exists
And the object "Chunk" has a vertex at "2,2,-1" And the object "Chunk" has a vertex at "2,2,-1"
And the object "Chunk" has a vertex at "9,-1,-1" 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,
# Not currently possible via UI # Not currently possible via UI
And I set "scene.BIMProjectProperties.distance_limit" to "5" And I set "scene.BIMProjectProperties.distance_limit" to "5"
And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC" And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC"
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation.ifc', use_cache=False)" When I link IFC project from "{cwd}/test/files/geolocation.ifc"
Then the object "Chunk" exists Then the object "Chunk" exists
And the object "Chunk" has a vertex at "2,2,-1" And the object "Chunk" has a vertex at "2,2,-1"
And the object "Chunk" has a vertex at "9,-1,-1" 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
# Not currently possible via UI # Not currently possible via UI
And I set "scene.BIMProjectProperties.distance_limit" to "5" And I set "scene.BIMProjectProperties.distance_limit" to "5"
And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC" And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC"
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation.ifc', use_cache=False)" When I link IFC project from "{cwd}/test/files/geolocation.ifc"
Then the object "Chunk" exists Then the object "Chunk" exists
And the object "Chunk" has a vertex at "-11,-2,0" And the object "Chunk" has a vertex at "-11,-2,0"
And the object "Chunk" has a vertex at "-4,-5,0" And the object "Chunk" has a vertex at "-4,-5,0"
@@ -724,7 +724,7 @@ Scenario: Link IFC - manual false origin mode
And I set "scene.BIMProjectProperties.distance_limit" to "5" And I set "scene.BIMProjectProperties.distance_limit" to "5"
And I set "scene.BIMProjectProperties.false_origin_mode" to "MANUAL" And I set "scene.BIMProjectProperties.false_origin_mode" to "MANUAL"
And I set "scene.BIMProjectProperties.false_origin" to "10000,0,0" And I set "scene.BIMProjectProperties.false_origin" to "10000,0,0"
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation.ifc', use_cache=False)" When I link IFC project from "{cwd}/test/files/geolocation.ifc"
Then the object "Chunk" exists Then the object "Chunk" exists
And the object "Chunk" has a vertex at "-8,2,-1" And the object "Chunk" has a vertex at "-8,2,-1"
And the object "Chunk" has a vertex at "-1,-1,-1" 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
# Not currently possible via UI # Not currently possible via UI
And I set "scene.BIMProjectProperties.distance_limit" to "5" And I set "scene.BIMProjectProperties.distance_limit" to "5"
And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC" And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC"
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation.ifc', use_cache=False)" When I link IFC project from "{cwd}/test/files/geolocation.ifc"
And I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation-mapconversion-angle.ifc', use_cache=False)" And I link IFC project from "{cwd}/test/files/geolocation-mapconversion-angle.ifc"
Then the object "Col:IfcProject/geolocation.ifc:Chunk" exists Then the object "Col:IfcProject/geolocation.ifc:Chunk" exists
And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" exists And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" exists
And the object "Col:IfcProject/geolocation.ifc:Chunk" has a vertex at "-11,-2,0" 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
# Not currently possible via UI # Not currently possible via UI
And I set "scene.BIMProjectProperties.distance_limit" to "5" And I set "scene.BIMProjectProperties.distance_limit" to "5"
And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC" And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC"
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation-mapconversion-angle.ifc', use_cache=False)" When I link IFC project from "{cwd}/test/files/geolocation-mapconversion-angle.ifc"
And I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation.ifc', use_cache=False)" And I link IFC project from "{cwd}/test/files/geolocation.ifc"
Then the object "Col:IfcProject/geolocation.ifc:Chunk" exists Then the object "Col:IfcProject/geolocation.ifc:Chunk" exists
And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" exists And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" exists
And the object "Col:IfcProject/geolocation-mapconversion-angle.ifc:Chunk" has a vertex at "-11,-2,0" 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
# Not currently possible via UI # Not currently possible via UI
And I set "scene.BIMProjectProperties.distance_limit" to "5" And I set "scene.BIMProjectProperties.distance_limit" to "5"
And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC" And I set "scene.BIMProjectProperties.false_origin_mode" to "AUTOMATIC"
When I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation-unit1.ifc', use_cache=False)" When I link IFC project from "{cwd}/test/files/geolocation-unit1.ifc"
And I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation-unit2.ifc', use_cache=False)" And I link IFC project from "{cwd}/test/files/geolocation-unit2.ifc"
And I press "bim.link_ifc(filepath='{cwd}/test/files/geolocation-unit3.ifc', use_cache=False)" And I link IFC project from "{cwd}/test/files/geolocation-unit3.ifc"
Then the object "Col:IfcProject/geolocation-unit1.ifc:Chunk" exists Then the object "Col:IfcProject/geolocation-unit1.ifc:Chunk" exists
And the object "Col:IfcProject/geolocation-unit2.ifc:Chunk" exists And the object "Col:IfcProject/geolocation-unit2.ifc:Chunk" exists
And the object "Col:IfcProject/geolocation-unit3.ifc:Chunk" exists 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
Scenario: Toggle link visibility - wireframe mode Scenario: Toggle link visibility - wireframe mode
Given an empty IFC project Given an empty IFC project
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')" And I link IFC project from "{cwd}/test/files/basic.ifc"
When I press "bim.toggle_link_visibility(link='{cwd}/test/files/basic.ifc', mode='WIREFRAME')" When I press "bim.toggle_link_visibility(link='{cwd}/test/files/basic.ifc', mode='WIREFRAME')"
Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_wireframe" is "True" Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_wireframe" is "True"
And the object "Chunk" should display as "WIRE" And the object "Chunk" should display as "WIRE"
@@ -789,7 +789,7 @@ Scenario: Toggle link visibility - wireframe mode
Scenario: Toggle link selectability Scenario: Toggle link selectability
Given an empty IFC project Given an empty IFC project
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')" And I link IFC project from "{cwd}/test/files/basic.ifc"
When I press "bim.toggle_link_selectability(link='{cwd}/test/files/basic.ifc')" When I press "bim.toggle_link_selectability(link='{cwd}/test/files/basic.ifc')"
Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_selectable" is "False" Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_selectable" is "False"
And the collection "IfcProject/basic.ifc" is unselectable And the collection "IfcProject/basic.ifc" is unselectable
@@ -799,7 +799,7 @@ Scenario: Toggle link selectability
Scenario: Toggle link visibility - visible mode Scenario: Toggle link visibility - visible mode
Given an empty IFC project Given an empty IFC project
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')" And I link IFC project from "{cwd}/test/files/basic.ifc"
When I press "bim.toggle_link_visibility(link='{cwd}/test/files/basic.ifc', mode='VISIBLE')" When I press "bim.toggle_link_visibility(link='{cwd}/test/files/basic.ifc', mode='VISIBLE')"
Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_hidden" is "True" Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_hidden" is "True"
And the object "IfcProject/basic.ifc" is not visible And the object "IfcProject/basic.ifc" is not visible
@@ -809,14 +809,14 @@ Scenario: Toggle link visibility - visible mode
Scenario: Unload link Scenario: Unload link
Given an empty Blender session Given an empty Blender session
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')" And I link IFC project from "{cwd}/test/files/basic.ifc"
When I press "bim.unload_link(filepath='{cwd}/test/files/basic.ifc')" When I press "bim.unload_link(filepath='{cwd}/test/files/basic.ifc')"
Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_loaded" is "False" Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_loaded" is "False"
And the collection "IfcProject/basic.ifc" does not exist And the collection "IfcProject/basic.ifc" does not exist
Scenario: Load link Scenario: Load link
Given an empty Blender session Given an empty Blender session
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')" And I link IFC project from "{cwd}/test/files/basic.ifc"
And I press "bim.unload_link(filepath='{cwd}/test/files/basic.ifc')" And I press "bim.unload_link(filepath='{cwd}/test/files/basic.ifc')"
When I press "bim.load_link(filepath='{cwd}/test/files/basic.ifc')" When I press "bim.load_link(filepath='{cwd}/test/files/basic.ifc')"
Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_loaded" is "True" Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_loaded" is "True"
@@ -824,7 +824,7 @@ Scenario: Load link
Scenario: Unlink IFC Scenario: Unlink IFC
Given an empty Blender session Given an empty Blender session
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')" And I link IFC project from "{cwd}/test/files/basic.ifc"
And I press "bim.unload_link(filepath='{cwd}/test/files/basic.ifc')" And I press "bim.unload_link(filepath='{cwd}/test/files/basic.ifc')"
When I press "bim.unlink_ifc(filepath='{cwd}/test/files/basic.ifc')" When I press "bim.unlink_ifc(filepath='{cwd}/test/files/basic.ifc')"
Then "scene.BIMProjectProperties.links.get('{cwd}/test/files/basic.ifc')" is "None" Then "scene.BIMProjectProperties.links.get('{cwd}/test/files/basic.ifc')" is "None"
+28 -1
View File
@@ -32,6 +32,7 @@ import ifcopenshell.util.element
import ifcopenshell.util.representation import ifcopenshell.util.representation
import bonsai.tool as tool import bonsai.tool as tool
import bonsai.bim.handler import bonsai.bim.handler
from collections.abc import Generator
from bonsai.bim.ifc import IfcStore from bonsai.bim.ifc import IfcStore
from bonsai.tool.brick import BrickStore from bonsai.tool.brick import BrickStore
from bonsai.bim.module.model.data import AuthoringData from bonsai.bim.module.model.data import AuthoringData
@@ -66,7 +67,10 @@ Can be useful for debugging, but has caveats - can't use ``wm.read_homefile``
as resets the ``bpy.context`` and some it's members become `None`. as resets the ``bpy.context`` and some it's members become `None`.
""" """
TMP = Path(f"{variables['cwd']}/test/files/temp") TMP = Path.cwd() / "test/files/temp"
TEST_FILES_DIR = Path.cwd() / "test/files"
CLEAN_LINKED_FILES_CACHE = False
class PanelSpy: class PanelSpy:
@@ -292,6 +296,19 @@ def vectors_are_equal(v1, v2):
return all(is_x(v1[i], v2[i]) for i in range(len(v1))) return all(is_x(v1[i], v2[i]) for i in range(len(v1)))
@pytest.fixture(scope="function", autouse=True)
def run_for_each_test() -> Generator[None]:
# Code before this runs before each test
yield
# Code after this runs after each test
global CLEAN_LINKED_FILES_CACHE
if CLEAN_LINKED_FILES_CACHE:
for filepath in TEST_FILES_DIR.glob("*.ifc.cache.*"):
filepath.unlink()
CLEAN_LINKED_FILES_CACHE = False
@given("an untestable scenario") @given("an untestable scenario")
def an_untestable_scenario(): def an_untestable_scenario():
pass pass
@@ -346,6 +363,16 @@ def saving_ifc_project() -> None:
tool.Project.save_test_project() tool.Project.save_test_project()
@given(parsers.parse('I link IFC project from "{filepath}"'))
@when(parsers.parse('I link IFC project from "{filepath}"'))
@then(parsers.parse('I link IFC project from "{filepath}"'))
def i_link_ifc_project_from_filepath(filepath: str) -> None:
global CLEAN_LINKED_FILES_CACHE
filepath = replace_variables(filepath)
CLEAN_LINKED_FILES_CACHE = True
bpy.ops.bim.link_ifc(filepath=filepath, use_cache=False)
@given("the Brickschema is stubbed") @given("the Brickschema is stubbed")
def the_brickschema_is_stubbed(): def the_brickschema_is_stubbed():
# This makes things run faster since we don't need to load the entire brick schema # This makes things run faster since we don't need to load the entire brick schema