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

Leif Andersen leif.a.andersen at gmail.com
Thu Jul 8 02:01:17 CEST 2010


Revision: 30097
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30097
Author:   leifandersen
Date:     2010-07-08 02:01:16 +0200 (Thu, 08 Jul 2010)

Log Message:
-----------
1.  Made the final changes so that ImageTestCase and AnimationTestCase can both work as ImageTestCases (like an interface in java, image a duck, and a duck (ImageTestCase), and a duck plus super powers (animation test case)).

2.  Set up the AnimationTestCase to be ran with the images.

3.  Fixed all of the bugs in the AnimationTestCase class (I think, at least it works fine when I ran it), note that the rendered HTML pages still needs work.

4.  Because Popen seems to get stuck when doing animations, I went back to os.system(), which means the output is back to being displayed (regardless of -v), note that this is only for animations.  I think it has something to do with PIPE becoming full, but supposedly p.communicaate() was supposed to take care of that.

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

Modified: branches/soc-2010-leifandersen/release/scripts/op/tests_render.py
===================================================================
--- branches/soc-2010-leifandersen/release/scripts/op/tests_render.py	2010-07-07 22:55:57 UTC (rev 30096)
+++ branches/soc-2010-leifandersen/release/scripts/op/tests_render.py	2010-07-08 00:01:16 UTC (rev 30097)
@@ -4,15 +4,9 @@
 from bpy.props import *
 
 BLENDER_BIN = sys.argv[0]
-BLENDER_FLAG = "--blender-intern"
 PYTHON_BIN = "python"
 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) + " " + BLENDER_FLAG + " " + image1 + " " + image2
-    print(os.system(command))
-
 def render(path):
     (directory, filename) = os.path.split(path)
     command = BLENDER_BIN + " -b " + path + " -o " + os.path.join(directory, "output", (filename + "_####")) + " -F PNG -x 1 -f 1"
@@ -41,7 +35,8 @@
         (directory, filename) = os.path.split(self.properties.filepath)
         image1 = os.path.join(directory,"render",(filename + ".png"))
         image2 = render(self.properties.filepath)
-        compare_image(image1, image2, directory)
+        command = PYTHON_BIN + " " + os.path.join(directory, PILTEST_PY) + " --image " + self.properties.filepath
+        print(os.system(command))
         return {'FINISHED'}
 
     def invoke(self, context, event):

Modified: branches/soc-2010-leifandersen/tests/render/run.py
===================================================================
--- branches/soc-2010-leifandersen/tests/render/run.py	2010-07-07 22:55:57 UTC (rev 30096)
+++ branches/soc-2010-leifandersen/tests/render/run.py	2010-07-08 00:01:16 UTC (rev 30097)
@@ -40,6 +40,7 @@
     pixel_range = None
     difference = None
     message = ""
+    ID = 'Image'
 
     def __init__(self, blend_path, good_path, test_path):
         '''Sets up a test case, with the blend_path, the known good path, and the test path
@@ -54,7 +55,7 @@
     def format_frame(self, num):
         frame_num = str(num)
         while len(frame_num) < 4:
-            frame_num+='0'
+            frame_num = '0' + frame_num
         return frame_num
 
     def render_test(self):
@@ -116,61 +117,73 @@
 
     name = None
     passed = None
-    passed_arr = None
+    passed_arr = []
     good_path = None
+    good_path_arr = []
     blend_path = None
     test_path = None
+    test_path_arr = []
     diff_path = None
+    diff_path_arr = []
     bad_pixels = None
+    bad_pixels_arr = []
     pixel_count = None
+    pixel_count_arr = []
     diff_sum = None
+    diff_sum_arr = []
     good_image = None
+    good_image_arr = []
     test_image = None
+    test_image_arr = []
     diff_image = None
+    diff_image_arr = []
     pixel_range = None
+    pixel_range_arr = []
     difference = None
+    diffference_arr = []
     message = ""
+    ID = 'Animation'
 
     def __init__(self, blend_path, good_path, test_path):
         ''''''
         self.name = os.path.split(blend_path)[1]
+        i=1
+        for imagename in os.listdir(good_path):
+            if imagename.find('.png') != -1:
+                self.good_path_arr.append(os.path.join(good_path, imagename))
+                im = Image.open(self.good_path_arr[i-1])
+                self.good_image_arr.append(im)
+                self.test_path_arr.append(os.path.join(test_path, string.replace(self.name, '.blend', '_' + self.format_frame(i) + '.png')))
+                i+=1
+
         self.blend_path = blend_path
-        self.good_path = []
-        self.good_image = []
-        self.test_path = []
+        self.good_path = self.good_path_arr[0]
+        self.good_image = self.good_image_arr[0]
+        self.test_path = self.test_path_arr[0]
 
-        (good_directory, good_file) = os.path.split(blend_path)
-        (test_directroy, test_file) = os.path.split(blend_path)
-        i=1
-        for imagename in os.listdir(good_directory):
-            self.good_path.append(os.path.join(good_directory, string.replace(self.name, '.blend', '_' + self.format_frame(i) + '.png')))
-            im = Image.open(imagename)
-            self.good_image.append(im)
-            self.test_path.append(os.path.join(test_directory, string.replace(self.name, '.blend', '_' + self.format_frame(i) + '.png')))
-            i+=1
-
     def format_frame(self, num):
         frame_num = str(num)
         while len(frame_num) < 4:
-            frame_num+='0'
+            frame_num = '0' + frame_num
         return frame_num
 
     def render_test(self):
         ''''''
-        # The old way, TODO, remove when certain Popen() works.
-        # command = BLENDER_BIN + " -b " + self.blend_path + " -o " + string.replace(self.test_path[0], '_0001.png', '') + "_#### -F PNG -x 1 -a"
-        # os.system(command)
+        #The old way, TODO, remove when certain Popen() works.
+        command = BLENDER_BIN + " -b " + self.blend_path + " -o " + string.replace(self.test_path, '_0001.png', '') + "_#### -F PNG -x 1 -a"
+        os.system(command)
 
-        p = Popen([BLENDER_BIN, '-b', self.blend_path, '-o', string.replace(self.test_path[0], '_0001.png', '') + '_####', '-F', 'PNG', '-x', '1', '-a'], stdout=PIPE, stderr=PIPE, stdin=PIPE)
-        p.wait()
-        if VERBOSE:
-            print p.communicate()[0]
+        # TODO, for some reason, this seems to kill the whole program (I think PIPE is getting full, will replace
+        #p = Popen([BLENDER_BIN, '-b', self.blend_path, '-o', string.replace(self.test_path, '_0001.png', '') + '_####', '-F', 'PNG', '-x', '1', '-a'], stdout=PIPE, stderr=PIPE, stdin=PIPE)
+        #p.wait()
+        #if VERBOSE:
+        #    print p.communicate()[0]
 
         try:
-            self.test_image = []
-            for imagename in self.test_path:
+            for imagename in self.test_path_arr:
                 im = Image.open(imagename)
-                self.test_image.append(im)
+                self.test_image_arr.append(im)
+            self.test_image = self.test_image_arr[0]
         except IOError:
             self.test_image = None
             self.passed = False
@@ -184,16 +197,12 @@
     def setup_test(self):
         ''''''
         if self.test_image != None:
-            self.passed_arr = []
-            self.diff_sum = []
-            self.bad_pixels = []
-            self.diff_image = []
-            self.pixel_range = []
 
-            for diff_image in self.good_image:
-                self.diff_image.append(ImageChops.difference(self.good_image, self.test_image))
+            for diff_image in self.good_image_arr:
+                self.diff_image_arr.append(ImageChops.difference(self.good_image, self.test_image))
+            self.diff_image = self.diff_image_arr
 
-            for diff_image in self.diff_image:
+            for diff_image in self.diff_image_arr:
                 diff_sum = 0
                 bad_pixels = 0
                 pixel_range = len(diff_image.histogram())
@@ -209,14 +218,19 @@
                     self.passed_arr.append(True)
                 else:
                     self.passed_arr.append(False)
-                self.diff_sum.append(diff_sum)
-                self.bad_pixels.append(bad_pixels)
-                self.pixel_range.append(pixel_range)
-                self.pixel_count.append(pixel_count)
+                self.diff_sum_arr.append(diff_sum)
+                self.bad_pixels_arr.append(bad_pixels)
+                self.pixel_range_arr.append(pixel_range)
+                self.pixel_count_arr.append(pixel_count)
+
+            self.diff_sum = self.diff_sum_arr[0]
+            self.bad_pixels = self.bad_pixels_arr[0]
+            self.pixel_range = self.pixel_range_arr[0]
+            self.pixel_count = self.pixel_count_arr[0]
             
             self.passed = True
             fail_count = 0
-            frames = len(self.passed)
+            frames = len(self.passed_arr)
             for passed in self.passed_arr:
                 if passed == False:
                     fail_count+=1
@@ -226,28 +240,48 @@
     def save_diff(self, output_path):
         ''''''
         if self.diff_image != None:
-            self.diff_path = []
             (diff_directory, diff_file) = os.path.split(output_path)
             i = 1
-            for image in self.diff_image:
-                self.diff_image.save(output_path + '_diff_' + i + '.png')
+            for image in self.diff_image_arr:
+                self.diff_path_arr.append(output_path + '_diff_' + self.format_frame(i) + '.png')
+                image.save(self.diff_path_arr[i-1])
                 i+=1
+            self.diff_path = self.diff_path_arr[0]
 
-
 def get_cases(folder):
     '''Returns all of the blend files in the folder'''
     cases = []
     print ''
     for filename in os.listdir(sys.path[0]):
         if filename.find('.blend') != -1:
-            blend_path = os.path.join(sys.path[0],filename)
+            blend_path = os.path.join(sys.path[0], filename)
             good_path = os.path.join(sys.path[0], 'render', string.replace(filename, '.blend', '.png'))
             test_path = os.path.join(sys.path[0], 'output', string.replace(filename, '.blend', ''))
             test_case = ImageTestCase(blend_path, good_path, test_path)
             cases.append(test_case)
+    for filename in os.listdir(os.path.join(sys.path[0], 'anim')):
+        if filename.find('.blend') != -1:
+            blend_path = os.path.join(sys.path[0], 'anim', filename)
+            good_path = os.path.join(sys.path[0], 'anim', string.replace(filename, '.blend', ''))
+            test_path = os.path.join(sys.path[0], 'output', string.replace(filename, '.blend', ''))
+            test_case = AnimationTestCase(blend_path, good_path, test_path)
+            cases.append(test_case)
     return cases
 
+def get_image_cases(folder):
+    '''Returns all of the image blend files in the folder'''
+    cases = []
+    print ''
+    for filename in os.listdir(sys.path[0]):
+        if filename.find('.blend') != -1:
+            blend_path = os.path.join(sys.path[0], filename)
+            good_path = os.path.join(sys.path[0], 'render', string.replace(filename, '.blend', '.png'))
+            test_path = os.path.join(sys.path[0], 'output', string.replace(filename, '.blend', ''))
+            test_case = ImageTestCase(blend_path, good_path, test_path)
+            cases.append(test_case)
+    return cases
 
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list