[Bf-blender-cvs] [0c5014aaef8] master: Cleanup: Deduplicate some code in new blenfile io/linking tests.

Bastien Montagne noreply at git.blender.org
Fri Feb 14 12:18:26 CET 2020


Commit: 0c5014aaef854bba096bdaab7d6807fcfd45d7d0
Author: Bastien Montagne
Date:   Fri Feb 14 11:02:22 2020 +0100
Branches: master
https://developer.blender.org/rB0c5014aaef854bba096bdaab7d6807fcfd45d7d0

Cleanup: Deduplicate some code in new blenfile io/linking tests.

===================================================================

M	tests/python/CMakeLists.txt
M	tests/python/bl_blendfile_io.py
M	tests/python/bl_blendfile_liblink.py
A	tests/python/bl_blendfile_utils.py

===================================================================

diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt
index cf4438a8544..5a3eeb6d14e 100644
--- a/tests/python/CMakeLists.txt
+++ b/tests/python/CMakeLists.txt
@@ -28,6 +28,7 @@ set(TEST_OUT_DIR ${CMAKE_BINARY_DIR}/tests)
 # ugh, any better way to do this on testing only?
 file(MAKE_DIRECTORY ${TEST_OUT_DIR})
 file(MAKE_DIRECTORY ${TEST_OUT_DIR}/io_tests)
+file(MAKE_DIRECTORY ${TEST_OUT_DIR}/blendfile_io)
 
 # if(NOT IS_DIRECTORY ${TEST_SRC_DIR})
 #   message(FATAL_ERROR "CMake test directory not found!")
diff --git a/tests/python/bl_blendfile_io.py b/tests/python/bl_blendfile_io.py
index 493b16b4ab3..0b055b9d46a 100644
--- a/tests/python/bl_blendfile_io.py
+++ b/tests/python/bl_blendfile_io.py
@@ -3,35 +3,10 @@
 # ./blender.bin --background -noaudio --python tests/python/bl_blendfile_io.py
 import bpy
 import os
-import pprint
+import sys
 
-
-class 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()
+sys.path.append(os.path.dirname(os.path.realpath(__file__)))
+from bl_blendfile_utils import TestHelper
 
 
 class TestBlendFileSaveLoadBasic(TestHelper):
@@ -47,25 +22,25 @@ class TestBlendFileSaveLoadBasic(TestHelper):
         self.ensure_path(output_dir)
         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.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.
         assert(orig_data != read_data)
 
         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.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)
 
 
diff --git a/tests/python/bl_blendfile_liblink.py b/tests/python/bl_blendfile_liblink.py
index 51dd989ece1..7d93d7c8455 100644
--- a/tests/python/bl_blendfile_liblink.py
+++ b/tests/python/bl_blendfile_liblink.py
@@ -3,35 +3,10 @@
 # ./blender.bin --background -noaudio --python tests/python/bl_blendfile_liblink.py
 import bpy
 import os
-import pprint
+import sys
 
-
-class 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()
+sys.path.append(os.path.dirname(os.path.realpath(__file__)))
+from bl_blendfile_utils import TestHelper
 
 
 class TestBlendLibLinkSaveLoadBasic(TestHelper):
@@ -56,14 +31,14 @@ class TestBlendLibLinkSaveLoadBasic(TestHelper):
         link_dir = os.path.join(output_path, "Mesh")
         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")
         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)
 
-        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)
 
 
diff --git a/tests/python/bl_blendfile_utils.py b/tests/python/bl_blendfile_utils.py
new file mode 100644
index 00000000000..48e24cd0684
--- /dev/null
+++ b/tests/python/bl_blendfile_utils.py
@@ -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()



More information about the Bf-blender-cvs mailing list