test_feature - add separate non-debug option to save ifc project

Also clean up temp folder before save (met issues when tests were using not updated shading_styles.json)
This commit is contained in:
Andrej730
2025-11-11 12:51:11 +05:00
parent af4851f03a
commit a4fae94be8
2 changed files with 36 additions and 22 deletions
+20 -6
View File
@@ -21,6 +21,7 @@ import os
import types
import bpy
import pytest
import shutil
import pprint
import traceback
import webbrowser
@@ -64,6 +65,8 @@ 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`.
"""
TMP = Path(f"{variables['cwd']}/test/files/temp")
class PanelSpy:
def __init__(self, blender_panel: type[bpy.types.Panel]):
@@ -325,6 +328,17 @@ def an_empty_ifc_2x3_project():
bpy.ops.bim.create_project()
@given(parsers.parse("I save IFC project"))
@when(parsers.parse("I save IFC project"))
@then(parsers.parse("I save IFC project"))
def saving_ifc_project() -> None:
# Remove old temp files to avoid conflicts with non-updated assets.
if TMP.exists():
shutil.rmtree(TMP)
filepath = TMP / "test_project.ifc"
bpy.ops.bim.save_project(filepath=filepath.__str__(), should_save_as=True)
@given("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
@@ -1761,19 +1775,19 @@ def i_fail():
@given(parsers.parse("I save sample test files"))
@when(parsers.parse("I save sample test files"))
@then(parsers.parse("I save sample test files"))
def saving_sample_test_files(and_open_in_blender=None):
filepath = f"{variables['cwd']}/test/files/temp/sample_test_file"
def saving_sample_test_files() -> None:
filepath = TMP / "sample_test_file"
print(f"Saved to {filepath}")
bpy.ops.bim.save_project(filepath=f"{filepath}.ifc", should_save_as=True)
bpy.ops.wm.save_as_mainfile(filepath=f"{filepath}.blend")
bpy.ops.bim.save_project(filepath=filepath.with_suffix(".ifc").__str__(), should_save_as=True)
bpy.ops.wm.save_as_mainfile(filepath=filepath.with_suffix(".blend").__str__())
@given(parsers.parse("I load test blend file"))
@when(parsers.parse("I load test blend file"))
@then(parsers.parse("I load test blend file"))
def opening_sample_test_files_in_blender():
filepath = f"{variables['cwd']}/test/files/temp/sample_test_file.blend"
bpy.ops.wm.open_mainfile(filepath=filepath, display_file_selector=False)
filepath = TMP / "sample_test_file.blend"
bpy.ops.wm.open_mainfile(filepath=filepath.__str__(), display_file_selector=False)
# TODO: merge to single fixture with `saving_sample_test_files`; add "and wait"