Cleanup: Deduplicate some code in new blenfile io/linking tests.
This commit is contained in:
@@ -28,6 +28,7 @@ set(TEST_OUT_DIR ${CMAKE_BINARY_DIR}/tests)
|
|||||||
# ugh, any better way to do this on testing only?
|
# ugh, any better way to do this on testing only?
|
||||||
file(MAKE_DIRECTORY ${TEST_OUT_DIR})
|
file(MAKE_DIRECTORY ${TEST_OUT_DIR})
|
||||||
file(MAKE_DIRECTORY ${TEST_OUT_DIR}/io_tests)
|
file(MAKE_DIRECTORY ${TEST_OUT_DIR}/io_tests)
|
||||||
|
file(MAKE_DIRECTORY ${TEST_OUT_DIR}/blendfile_io)
|
||||||
|
|
||||||
# if(NOT IS_DIRECTORY ${TEST_SRC_DIR})
|
# if(NOT IS_DIRECTORY ${TEST_SRC_DIR})
|
||||||
# message(FATAL_ERROR "CMake test directory not found!")
|
# message(FATAL_ERROR "CMake test directory not found!")
|
||||||
|
@@ -3,35 +3,10 @@
|
|||||||
# ./blender.bin --background -noaudio --python tests/python/bl_blendfile_io.py
|
# ./blender.bin --background -noaudio --python tests/python/bl_blendfile_io.py
|
||||||
import bpy
|
import bpy
|
||||||
import os
|
import os
|
||||||
import pprint
|
import sys
|
||||||
|
|
||||||
|
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
|
||||||
class TestHelper:
|
from bl_blendfile_utils import TestHelper
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def id_to_uid(id_data):
|
|
||||||
return (type(id_data).__name__,
|
|
||||||
id_data.name,
|
|
||||||
id_data.users,
|
|
||||||
id_data.library.filepath if id_data.library else None)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def blender_data_to_tuple(cls, bdata):
|
|
||||||
return sorted(tuple((cls.id_to_uid(k), sorted(tuple(cls.id_to_uid(vv) for vv in v)))
|
|
||||||
for k, v in bdata.user_map().items()))
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def ensure_path(path):
|
|
||||||
if not os.path.exists(path):
|
|
||||||
os.makedirs(path)
|
|
||||||
|
|
||||||
def run_all_tests(self):
|
|
||||||
for inst_attr_id in dir(self):
|
|
||||||
if not inst_attr_id.startswith("test_"):
|
|
||||||
continue
|
|
||||||
inst_attr = getattr(self, inst_attr_id)
|
|
||||||
if callable(inst_attr):
|
|
||||||
inst_attr()
|
|
||||||
|
|
||||||
|
|
||||||
class TestBlendFileSaveLoadBasic(TestHelper):
|
class TestBlendFileSaveLoadBasic(TestHelper):
|
||||||
@@ -47,25 +22,25 @@ class TestBlendFileSaveLoadBasic(TestHelper):
|
|||||||
self.ensure_path(output_dir)
|
self.ensure_path(output_dir)
|
||||||
output_path = os.path.join(output_dir, "blendfile.blend")
|
output_path = os.path.join(output_dir, "blendfile.blend")
|
||||||
|
|
||||||
orig_data = self.blender_data_to_tuple(bpy.data)
|
orig_data = self.blender_data_to_tuple(bpy.data, "orig_data 1")
|
||||||
|
|
||||||
bpy.ops.wm.save_as_mainfile(filepath=output_path, check_existing=False, compress=False)
|
bpy.ops.wm.save_as_mainfile(filepath=output_path, check_existing=False, compress=False)
|
||||||
bpy.ops.wm.open_mainfile(filepath=output_path, load_ui=False)
|
bpy.ops.wm.open_mainfile(filepath=output_path, load_ui=False)
|
||||||
|
|
||||||
read_data = self.blender_data_to_tuple(bpy.data)
|
read_data = self.blender_data_to_tuple(bpy.data, "read_data 1")
|
||||||
|
|
||||||
# We have orphaned data, which should be removed by file reading, so there should not be equality here.
|
# We have orphaned data, which should be removed by file reading, so there should not be equality here.
|
||||||
assert(orig_data != read_data)
|
assert(orig_data != read_data)
|
||||||
|
|
||||||
bpy.data.orphans_purge()
|
bpy.data.orphans_purge()
|
||||||
|
|
||||||
orig_data = self.blender_data_to_tuple(bpy.data)
|
orig_data = self.blender_data_to_tuple(bpy.data, "orig_data 2")
|
||||||
|
|
||||||
bpy.ops.wm.save_as_mainfile(filepath=output_path, check_existing=False, compress=False)
|
bpy.ops.wm.save_as_mainfile(filepath=output_path, check_existing=False, compress=False)
|
||||||
bpy.ops.wm.open_mainfile(filepath=output_path, load_ui=False)
|
bpy.ops.wm.open_mainfile(filepath=output_path, load_ui=False)
|
||||||
|
|
||||||
read_data = self.blender_data_to_tuple(bpy.data)
|
read_data = self.blender_data_to_tuple(bpy.data, "read_data 2")
|
||||||
|
|
||||||
assert(orig_data == read_data)
|
assert(orig_data == read_data)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -3,35 +3,10 @@
|
|||||||
# ./blender.bin --background -noaudio --python tests/python/bl_blendfile_liblink.py
|
# ./blender.bin --background -noaudio --python tests/python/bl_blendfile_liblink.py
|
||||||
import bpy
|
import bpy
|
||||||
import os
|
import os
|
||||||
import pprint
|
import sys
|
||||||
|
|
||||||
|
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
|
||||||
class TestHelper:
|
from bl_blendfile_utils import TestHelper
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def id_to_uid(id_data):
|
|
||||||
return (type(id_data).__name__,
|
|
||||||
id_data.name,
|
|
||||||
id_data.users,
|
|
||||||
id_data.library.filepath if id_data.library else None)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def blender_data_to_tuple(cls, bdata):
|
|
||||||
return sorted(tuple((cls.id_to_uid(k), sorted(tuple(cls.id_to_uid(vv) for vv in v)))
|
|
||||||
for k, v in bdata.user_map().items()))
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def ensure_path(path):
|
|
||||||
if not os.path.exists(path):
|
|
||||||
os.makedirs(path)
|
|
||||||
|
|
||||||
def run_all_tests(self):
|
|
||||||
for inst_attr_id in dir(self):
|
|
||||||
if not inst_attr_id.startswith("test_"):
|
|
||||||
continue
|
|
||||||
inst_attr = getattr(self, inst_attr_id)
|
|
||||||
if callable(inst_attr):
|
|
||||||
inst_attr()
|
|
||||||
|
|
||||||
|
|
||||||
class TestBlendLibLinkSaveLoadBasic(TestHelper):
|
class TestBlendLibLinkSaveLoadBasic(TestHelper):
|
||||||
@@ -56,14 +31,14 @@ class TestBlendLibLinkSaveLoadBasic(TestHelper):
|
|||||||
link_dir = os.path.join(output_path, "Mesh")
|
link_dir = os.path.join(output_path, "Mesh")
|
||||||
bpy.ops.wm.link(directory=link_dir, filename="LibMesh")
|
bpy.ops.wm.link(directory=link_dir, filename="LibMesh")
|
||||||
|
|
||||||
orig_data = self.blender_data_to_tuple(bpy.data)
|
orig_data = self.blender_data_to_tuple(bpy.data, "orig_data")
|
||||||
|
|
||||||
output_path = os.path.join(output_dir, "blendfile.blend")
|
output_path = os.path.join(output_dir, "blendfile.blend")
|
||||||
bpy.ops.wm.save_as_mainfile(filepath=output_path, check_existing=False, compress=False)
|
bpy.ops.wm.save_as_mainfile(filepath=output_path, check_existing=False, compress=False)
|
||||||
bpy.ops.wm.open_mainfile(filepath=output_path, load_ui=False)
|
bpy.ops.wm.open_mainfile(filepath=output_path, load_ui=False)
|
||||||
|
|
||||||
read_data = self.blender_data_to_tuple(bpy.data)
|
read_data = self.blender_data_to_tuple(bpy.data, "read_data")
|
||||||
|
|
||||||
assert(orig_data == read_data)
|
assert(orig_data == read_data)
|
||||||
|
|
||||||
|
|
||||||
|
35
tests/python/bl_blendfile_utils.py
Normal file
35
tests/python/bl_blendfile_utils.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# Apache License, Version 2.0
|
||||||
|
|
||||||
|
import os
|
||||||
|
import pprint
|
||||||
|
|
||||||
|
|
||||||
|
class TestHelper:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def id_to_uid(id_data):
|
||||||
|
return (type(id_data).__name__,
|
||||||
|
id_data.name_full,
|
||||||
|
id_data.users)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def blender_data_to_tuple(cls, bdata, pprint_name=None):
|
||||||
|
ret = sorted(tuple((cls.id_to_uid(k), sorted(tuple(cls.id_to_uid(vv) for vv in v)))
|
||||||
|
for k, v in bdata.user_map().items()))
|
||||||
|
if pprint_name is not None:
|
||||||
|
print("\n%s:" % pprint_name)
|
||||||
|
pprint.pprint(ret)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def ensure_path(path):
|
||||||
|
if not os.path.exists(path):
|
||||||
|
os.makedirs(path)
|
||||||
|
|
||||||
|
def run_all_tests(self):
|
||||||
|
for inst_attr_id in dir(self):
|
||||||
|
if not inst_attr_id.startswith("test_"):
|
||||||
|
continue
|
||||||
|
inst_attr = getattr(self, inst_attr_id)
|
||||||
|
if callable(inst_attr):
|
||||||
|
inst_attr()
|
Reference in New Issue
Block a user