From 4c5998ee0bc2d2f763f977893656fc51ca7002bc Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 26 May 2023 18:37:22 +0200 Subject: [PATCH] Unittest: Add very basic 'old file loading' test. Use existing `lib/tests/libraries_and_linking/library_test_scene.blend` essentially as 'file loads without error' test. Also does very basic proxy -> liboverrides conversion check. This test could be extended a lot, but just opening this file already allowed to identify three bugs in current 3.6/main code, and an issue in an upcoming refactor of the readfile code... --- tests/python/CMakeLists.txt | 1 + .../python/bl_blendfile_library_overrides.py | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt index 109cea6214f..e3799e14612 100644 --- a/tests/python/CMakeLists.txt +++ b/tests/python/CMakeLists.txt @@ -168,6 +168,7 @@ add_blender_test( blendfile_library_overrides --python ${CMAKE_CURRENT_LIST_DIR}/bl_blendfile_library_overrides.py -- --output-dir ${TEST_OUT_DIR}/blendfile_io/ + --test-dir "${TEST_SRC_DIR}/libraries_and_linking" ) # ------------------------------------------------------------------------------ diff --git a/tests/python/bl_blendfile_library_overrides.py b/tests/python/bl_blendfile_library_overrides.py index 6890bb1e660..840e12f6dba 100644 --- a/tests/python/bl_blendfile_library_overrides.py +++ b/tests/python/bl_blendfile_library_overrides.py @@ -296,10 +296,37 @@ class TestLibraryOverridesResync(TestHelper, unittest.TestCase): assert obj_armature.constraints[0].target == obj_ctrl2 +class TestLibraryOverridesFromProxies(TestHelper, unittest.TestCase): + # Very basic test, could be improved/extended. + # NOTE: Tests way more than only liboverride proxy conversion actually, since this is a fairly old .blend file. + + MAIN_BLEND_FILE = "library_test_scene.blend" + + def __init__(self, args): + self.args = args + + self.test_dir = pathlib.Path(self.args.test_dir) + self.assertTrue(self.test_dir.exists(), + 'Test dir {0} should exist'.format(self.test_dir)) + + bpy.ops.wm.read_homefile(use_empty=True, use_factory_startup=True) + + def test_open_linked_proxy_file(self): + bpy.ops.wm.open_mainfile(filepath=str(self.test_dir / self.MAIN_BLEND_FILE)) + + # Check stability of 'same name' fixing for IDs. + direct_linked_A = bpy.data.libraries["lib.002"] + assert direct_linked_A.filepath == "//libraries/direct_linked_A.blend" + + assert bpy.data.objects['HairCubeArmatureGroup_proxy'].library == direct_linked_A + assert bpy.data.objects['HairCubeArmatureGroup_proxy'].override_library != None + + TESTS = ( TestLibraryOverrides, TestLibraryTemplate, TestLibraryOverridesResync, + TestLibraryOverridesFromProxies, ) @@ -316,6 +343,13 @@ def argparse_create(): help="Where to output temp saved blendfiles", required=False, ) + parser.add_argument( + "--test-dir", + dest="test_dir", + default=".", + help="Where are the test blendfiles", + required=False, + ) return parser