From 24dbacb231f588a7c2fa0dca75536bdc95b875db Mon Sep 17 00:00:00 2001 From: Bobbe Date: Wed, 17 May 2023 13:30:25 +0200 Subject: [PATCH] Test if materials are still working after reloading blend file --- tests/test_importer.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/test_importer.py b/tests/test_importer.py index d6cc82a..9ff69bc 100644 --- a/tests/test_importer.py +++ b/tests/test_importer.py @@ -2,10 +2,11 @@ from itertools import product, chain from pathlib import Path +from tempfile import gettempdir import pytest -test_filepaths = (Path(__file__).parent / "test_pcbs").resolve().glob("**/*.pcb3d") +test_filepaths = list((Path(__file__).parent / "test_pcbs").resolve().glob("**/*.pcb3d")) kwargs_test_permutations = { "import_components": (True, False), @@ -41,3 +42,21 @@ def test_importer(path, kwargs): assert result == {"FINISHED"} assert len(bpy.context.view_layer.objects) > 0 assert bpy.context.object != None + +def test_load_file(): + test_path = str(Path(gettempdir()) / "pcb2blender_test.blend") + + bpy.ops.wm.read_homefile(use_empty=True) + bpy.ops.pcb2blender.import_pcb3d(filepath=str(test_filepaths[0])) + bpy.ops.wm.save_mainfile(filepath=test_path) + + assert not has_undefined_nodes() + + bpy.ops.wm.read_homefile(use_empty=True) + bpy.ops.wm.open_mainfile(filepath=test_path) + + assert not has_undefined_nodes() + +def has_undefined_nodes(): + node_groups = (group for group in bpy.data.node_groups if group.type == "SHADER") + return "NodeUndefined" in (node.bl_idname for group in node_groups for node in group.nodes)