[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29781] branches/soc-2010-leifandersen: 1.

Leif Andersen leif.a.andersen at gmail.com
Tue Jun 29 01:55:31 CEST 2010


Revision: 29781
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29781
Author:   leifandersen
Date:     2010-06-29 01:55:31 +0200 (Tue, 29 Jun 2010)

Log Message:
-----------
1.  Implemented the hash operator.  Although it currently doesn't take too much into account, clicking on Tests->Hash will print out (in the console), a unique hashcode for the current blend file.  (Again, this only takes a few things into account).

2.  Started splitting up the render test operator so it can be ran as a script independant of blender.  It should also be runnable as a seperate downloadable package.

Modified Paths:
--------------
    branches/soc-2010-leifandersen/release/scripts/op/tests_render.py
    branches/soc-2010-leifandersen/release/scripts/ui/space_tests.py
    branches/soc-2010-leifandersen/source/blender/editors/tests/tests_render.c
    branches/soc-2010-leifandersen/tests/CMakeLists.txt

Added Paths:
-----------
    branches/soc-2010-leifandersen/release/scripts/op/tests_hash.py
    branches/soc-2010-leifandersen/tests/render/run.py

Removed Paths:
-------------
    branches/soc-2010-leifandersen/tests/render/piltest.py

Copied: branches/soc-2010-leifandersen/release/scripts/op/tests_hash.py (from rev 29773, branches/soc-2010-leifandersen/release/scripts/op/tests_render.py)
===================================================================
--- branches/soc-2010-leifandersen/release/scripts/op/tests_hash.py	                        (rev 0)
+++ branches/soc-2010-leifandersen/release/scripts/op/tests_hash.py	2010-06-28 23:55:31 UTC (rev 29781)
@@ -0,0 +1,55 @@
+import bpy
+from bpy.props import *
+
+
+class TESTS_OT_hash(bpy.types.Operator):
+    '''Prints out a hash of the current blend file'''
+    bl_idname = "TESTS_OT_hash"
+    bl_label = "Hash Test"
+
+    # List of operator properties, the attributes will be assigned
+    # to the class instance from the operator settings before calling.
+
+    # Properties stored in properties (self.properties.filepath for example)
+
+    # filename = StringProperty(name="File Name", description="File name used", maxlen= 1024, default= "")
+    # filepath = StringProperty(name="File Path", description="Filepath used", maxlen= 1024, default= "")
+    # directory = StringProperty(name="File Directory", description="File Directory used", maxlen= 1024, default= "")
+    # check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, options={'HIDDEN'})
+
+    def poll(self, context):
+        return len(bpy.data.scenes) > 0
+
+    def execute(self, context):
+        hashcode = 0
+        for scene in bpy.data.scenes:
+            hashcode += hash(scene.name)
+            for ob in scene.objects:
+                hashcode += hash(ob.name)
+                for num in ob.rotation_euler:
+                    hashcode += hash(round(num, 6))
+                hashcode += hash(ob.type)
+                if ob.type == 'MESH':
+                    for vert in ob.data.verts:
+                        for co in vert.co:
+                            hashcode += hash(co)
+        print(hashcode)
+        return {'FINISHED'}
+
+#    def invoke(self, context, event):
+#        return {'RUNNING_MODAL'}
+
+classes = [
+    TESTS_OT_hash,
+]
+    
+def register():
+    for i in classes:
+        bpy.types.register(i)
+
+def unregister():
+    for i in classes:
+        bpy.types.unregister(i)
+
+if __name__ == "__main__":
+    register()

Modified: branches/soc-2010-leifandersen/release/scripts/op/tests_render.py
===================================================================
--- branches/soc-2010-leifandersen/release/scripts/op/tests_render.py	2010-06-28 23:08:47 UTC (rev 29780)
+++ branches/soc-2010-leifandersen/release/scripts/op/tests_render.py	2010-06-28 23:55:31 UTC (rev 29781)
@@ -4,12 +4,13 @@
 from bpy.props import *
 
 BLENDER_BIN = sys.argv[0]
+BLENDER_FLAG = "--blender-intern"
 PYTHON_BIN = "python"
-PILTEST_PY = "piltest.py"
+PILTEST_PY = "run.py"
 
 # Probably will be rewritten in C
 def compare_image(image1, image2, directory):
-    command = PYTHON_BIN + " " + os.path.join(directory, PILTEST_PY) + " " + image1 + " " + image2
+    command = PYTHON_BIN + " " + os.path.join(directory, PILTEST_PY) + " " + BLENDER_FLAG + " " + image1 + " " + image2
     print(os.system(command))
 
 def render(path):
@@ -87,4 +88,4 @@
         bpy.types.unregister(i)
 
 if __name__ == "__main__":
-    register()
\ No newline at end of file
+    register()

Modified: branches/soc-2010-leifandersen/release/scripts/ui/space_tests.py
===================================================================
--- branches/soc-2010-leifandersen/release/scripts/ui/space_tests.py	2010-06-28 23:08:47 UTC (rev 29780)
+++ branches/soc-2010-leifandersen/release/scripts/ui/space_tests.py	2010-06-28 23:55:31 UTC (rev 29781)
@@ -12,8 +12,9 @@
         layout.operator("TESTS_OT_render", text="Render Test")
         layout.operator("TESTS_OT_render_all", text="All Render Tests")
         layout.operator("RENDER_OT_render", text="Render")
+        layout.separator()
+        layout.operator("TESTS_OT_hash", text="File Hash")
 
-
 classes = [
     INFO_MT_tests,
 ]
@@ -32,4 +33,4 @@
         bpy.types.unregister(i)
 
 if __name__ == "__main__":
-    register()
\ No newline at end of file
+    register()

Modified: branches/soc-2010-leifandersen/source/blender/editors/tests/tests_render.c
===================================================================
--- branches/soc-2010-leifandersen/source/blender/editors/tests/tests_render.c	2010-06-28 23:08:47 UTC (rev 29780)
+++ branches/soc-2010-leifandersen/source/blender/editors/tests/tests_render.c	2010-06-28 23:55:31 UTC (rev 29781)
@@ -19,6 +19,8 @@
 #include "BKE_screen.h"
 #include "BKE_utildefines.h"
 
+#include "pthread.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 
@@ -27,7 +29,7 @@
 
 #include "wm_window.h"
 
-static int render_compare(bContext* C) {
+static int render_compare(bContext* C, wmOperatorType *ot) {
 	return OPERATOR_FINISHED;
 }
 

Modified: branches/soc-2010-leifandersen/tests/CMakeLists.txt
===================================================================
--- branches/soc-2010-leifandersen/tests/CMakeLists.txt	2010-06-28 23:08:47 UTC (rev 29780)
+++ branches/soc-2010-leifandersen/tests/CMakeLists.txt	2010-06-28 23:55:31 UTC (rev 29781)
@@ -26,3 +26,6 @@
 ENABLE_TESTING()
 ADD_SUBDIRECTORY(gtest)
 ADD_SUBDIRECTORY(pyunit)
+
+# A few more modifications needed for this script to work.
+# ADD_TEST(${Blender_BINARY_DIR}/bin/blender -b -P rennderdiff.py)

Deleted: branches/soc-2010-leifandersen/tests/render/piltest.py
===================================================================
--- branches/soc-2010-leifandersen/tests/render/piltest.py	2010-06-28 23:08:47 UTC (rev 29780)
+++ branches/soc-2010-leifandersen/tests/render/piltest.py	2010-06-28 23:55:31 UTC (rev 29781)
@@ -1,43 +0,0 @@
-import Image
-import unittest
-import sys
-
-class TestImage(unittest.TestCase):
-    def setUp(self):
-        pass
-
-    def test_image(self):
-        if len(sys.argv) < 3:
-            self.fail("Please don't use this script")
-        image_path1 = sys.argv[1]
-        image_path2 = sys.argv[2]
-        im1 = Image.open(image_path1)
-        im2 = Image.open(image_path2)
-
-        im1_red = im1_green = im1_blue = im2_red = im2_green = im2_blue = 0
-
-        self.assertEquals(im1.size, im2.size)
-        for i in range(0, im1.size[0]):
-            for j in range(0, im1.size[1]):
-                im1_red+=im1.getpixel((i,j))[0]
-                im1_green+=im1.getpixel((i,j))[1]
-                im1_blue+=im1.getpixel((i,j))[2]
-                im2_red+=im2.getpixel((i,j))[0]
-                im2_green+=im2.getpixel((i,j))[1]
-                im2_blue+=im2.getpixel((i,j))[2]
-
-        im_red = abs(im1_red-im2_red)
-        im_green = abs(im1_green-im2_green)
-        im_blue = abs(im1_blue-im2_blue)
-
-        if im_red > 100 or im_green > 100 or im_blue > 100:
-            self.fail("Images are too different")
-
-
-def suite():
-    return unittest.TestSuite([
-unittest.TestLoader().loadTestsFromTestCase(TestImage),
-])
-
-if __name__ == "__main__":
-    unittest.TextTestRunner(verbosity=2).run(suite())

Copied: branches/soc-2010-leifandersen/tests/render/run.py (from rev 29773, branches/soc-2010-leifandersen/tests/render/piltest.py)
===================================================================
--- branches/soc-2010-leifandersen/tests/render/run.py	                        (rev 0)
+++ branches/soc-2010-leifandersen/tests/render/run.py	2010-06-28 23:55:31 UTC (rev 29781)
@@ -0,0 +1,56 @@
+import Image
+import unittest
+import sys
+
+class TestImage(unittest.TestCase):
+    def setUp(self):
+        pass
+
+
+class TestImageOperator(unittest.TestCase):
+    def setUp(self):
+        pass
+
+    def test_image(self):
+        if len(sys.argv) < 3:
+            self.fail("Please don't use this script")
+        image_path1 = sys.argv[2]
+        image_path2 = sys.argv[3]
+        im1 = Image.open(image_path1)
+        im2 = Image.open(image_path2)
+
+        im1_red = im1_green = im1_blue = im2_red = im2_green = im2_blue = 0
+
+        self.assertEquals(im1.size, im2.size)
+        for i in range(0, im1.size[0]):
+            for j in range(0, im1.size[1]):
+                im1_red+=im1.getpixel((i,j))[0]
+                im1_green+=im1.getpixel((i,j))[1]
+                im1_blue+=im1.getpixel((i,j))[2]
+                im2_red+=im2.getpixel((i,j))[0]
+                im2_green+=im2.getpixel((i,j))[1]
+                im2_blue+=im2.getpixel((i,j))[2]
+
+        im_red = abs(im1_red-im2_red)
+        im_green = abs(im1_green-im2_green)
+        im_blue = abs(im1_blue-im2_blue)
+
+        if im_red > 100 or im_green > 100 or im_blue > 100:
+            self.fail("Images are too different")
+
+
+def suite():
+    return unittest.TestSuite([
+unittest.TestLoader().loadTestsFromTestCase(TestImage),
+])
+
+def operator_suite():
+    return unittest.TestSuite([
+unittest.TestLoader().loadTestsFromTestCase(TestImageOperator),
+])
+
+if __name__ == "__main__":
+    if sys.argv[1] == '--blender-intern':
+        unittest.TextTestRunner(verbosity=2).run(operator_suite())
+    else:
+        unittest.TextTestRunner(verbosity=2).run(suite())





More information about the Bf-blender-cvs mailing list