[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30477] branches/soc-2010-leifandersen/ tests/render/run.py: Changed the scrips so now it works on animations longer than ~500 frames ( varies by OS, computer, etc.).

Leif Andersen leif.a.andersen at gmail.com
Sun Jul 18 23:11:43 CEST 2010


Revision: 30477
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30477
Author:   leifandersen
Date:     2010-07-18 23:11:43 +0200 (Sun, 18 Jul 2010)

Log Message:
-----------
Changed the scrips so now it works on animations longer than ~500 frames (varies by OS, computer, etc.).  Although loading the resulting webpage of that animation can be a very bad idea...

Modified Paths:
--------------
    branches/soc-2010-leifandersen/tests/render/run.py

Modified: branches/soc-2010-leifandersen/tests/render/run.py
===================================================================
--- branches/soc-2010-leifandersen/tests/render/run.py	2010-07-18 20:26:13 UTC (rev 30476)
+++ branches/soc-2010-leifandersen/tests/render/run.py	2010-07-18 21:11:43 UTC (rev 30477)
@@ -34,9 +34,6 @@
 from subprocess import Popen, PIPE
 from optparse import OptionParser
 
-BLENDER_BIN = 'blender'
-VERBOSE = False
-
 class ImageTestCase:
     '''A Render Test Case only for use with images.  It can either be used to directly
        compare images, or if there is no good image, but a stored hashcode, it can compare the hashcode.'''
@@ -122,18 +119,18 @@
             frame_num = '0' + frame_num
         return frame_num
 
-    def render_test(self):
+    def render_test(self, blender_bin, verbose):
         '''Renders the test image based on the given image path in the setup methods.
            Assumes there is a global VERBOSE and BLENDER_BIN variable to be used.
            Will only render the first frame of the image using the default settings (saving as a PNG though)
            Changes the animation paths to the actual paths (from the given path)'''
 
         # Render Based on whether or not it's verbose
-        if VERBOSE:
-            command = BLENDER_BIN + ' -b ' + self.blend_path + ' -o ' + self.test_path + '_#### -F PNG -x 1 -f 1'
+        if verbose:
+            command = blender_bin + ' -b ' + self.blend_path + ' -o ' + self.test_path + '_#### -F PNG -x 1 -f 1'
             os.system(command)
         else:
-            p = Popen([BLENDER_BIN, '-b', self.blend_path, '-o', self.test_path + '_####', '-F', 'PNG', '-x', '1', '-f', '1'], stdout=PIPE, stderr=PIPE, stdin=PIPE)
+            p = Popen([blender_bin, '-b', self.blend_path, '-o', self.test_path + '_####', '-F', 'PNG', '-x', '1', '-f', '1'], stdout=PIPE, stderr=PIPE, stdin=PIPE)
             p.wait()
 
         # Modify the test path as needed
@@ -300,45 +297,34 @@
             hash+=frame_hash
         return hash
 
-    def get_animations(self):
-        '''Gets the good animaiton, and test animation (which assumes it's rendered), based on their
-           paths.  Then creates a diff animation out of the two other animations.  If the animations
+    def get_image_frame(self, frame_num):
+        '''Gets a good image, and a test image (which assumes it's rendered) from the animation, based on their
+           paths, and the given frame number.  Then creates a diff image out of the two other animations.  If the animations
            cannot be found, null is returned
+           frame_num: The frame of the animation to be retrieved
            returns:  A tuplet (good_animation, test_animation, diff_animaiton), or (null, null, null) if the animations can't be found'''
         try:
-            good_animation = []
-            test_animation = []
-            diff_animation = []
-            
-            for imagename in self.good_path_arr:
-                im = Image.open(imagename)
-                good_animation.append(im)
-            for imagename in self.test_path_arr:
-                im = Image.open(imagename)
-                test_animation.append(im)
-            i = 0
-            for diff_image in good_animation:
-                im = ImageChops.difference(good_animation[i], test_animation[i])
-                diff_animation.append(im)
-                i+=1
-            return (good_animation, test_animation, diff_animation)
+            good_image = Image.open(self.good_path_arr[frame_num])
+            test_image = Image.open(self.test_path_arr[frame_num])
+            diff_image = ImageChops.difference(good_image, test_image)
+            return (good_image, test_image, diff_image)
         except (IOError, OSError):
-            good_animation=test_animation=diff_animation=None
+            good_image=test_image=diff_image=None
             self.passed = False
-            return (good_animation, test_animation, diff_animation)
+            return (good_image, test_image, diff_image)
 
-    def render_test(self):
+    def render_test(self, blender_bin, verbose):
         '''Renders the test animation based on the given animation path in the setup methods.
            Assumes there is a global VERBOSE and BLENDER_BIN variable to be used.
            Will only render the first frame of the image using the default settings (saving as a PNG though)
            Changes the animation paths to the actual paths (from the given path)'''
            
         # Render depending on the verbosity needed
-        if VERBOSE:
-            command = BLENDER_BIN + ' -b ' + self.blend_path + " -o " + os.path.join(self.test_path,string.replace(self.name,'.blend','_####')) + ' -F PNG -x 1 -a'
+        if verbose:
+            command = blender_bin + ' -b ' + self.blend_path + " -o " + os.path.join(self.test_path,string.replace(self.name,'.blend','_####')) + ' -F PNG -x 1 -a'
             os.system(command)
         else:
-            p = Popen([BLENDER_BIN, '-b', self.blend_path, '-o', os.path.join(self.test_path,string.replace(self.name,'.blend','_####')), '-F', 'PNG', '-x', '1', '-a'], stdout=None, stderr=None, stdin=None)
+            p = Popen([blender_bin, '-b', self.blend_path, '-o', os.path.join(self.test_path,string.replace(self.name,'.blend','_####')), '-F', 'PNG', '-x', '1', '-a'], stdout=None, stderr=None, stdin=None)
             p.wait()
             
         # Modify self.test_path for later use
@@ -350,13 +336,8 @@
            of the test, the status of if the test passed or failed can be found in the passed field <testCaseName>.passed
            returns: Whether or not the test passed'''
         try:
-            
-            # Setup Variables
-            (good_animation, test_animation, diff_animation) = self.get_animations()   
-            diff_image = diff_animation[0]
-            
-            for diff_image in diff_animation:
-                
+            for frame_num in range(0, len(self.good_path_arr)):
+                (good_image, test_image, diff_image) = self.get_image_frame(frame_num)
                 # Setup more variables
                 diff_sum = 0
                 bad_pixels = 0
@@ -465,14 +446,13 @@
            The status of the test passing can be found in the passed field.
            This method changes the value of the diff paths to the actual diff paths.
            returns:  Whether or not the test passed'''
-        (good_animation, test_animation, diff_animation) = self.get_animations()
-        if diff_animation != None:
+        (good_image, test_image, diff_image) = self.get_image_frame(0)
+        if diff_image != None:
             (diff_directory, diff_file) = os.path.split(output_path)
-            i = 1
-            for image in diff_animation:
-                self.diff_path_arr.append(output_path + '_diff_' + self.format_frame(i) + '.png')
-                image.save(self.diff_path_arr[i-1])
-                i+=1
+            for frame_num in range(0, len(self.good_path_arr)):
+                (good_image, test_image, diff_image) = self.get_image_frame(frame_num)
+                self.diff_path_arr.append(output_path + '_diff_' + self.format_frame(frame_num + 1) + '.png')
+                diff_image.save(self.diff_path_arr[frame_num])
         else:
             # Fill up the diff_path with emptie strings...for later use in HTML
             for image in self.good_path_arr:
@@ -838,7 +818,7 @@
     # Run cases
     for test_case in cases:
         print test_case.name + '...',
-        test_case.render_test()
+        test_case.render_test(BLENDER_BIN, VERBOSE)
         if not False:
             test_case.image_test()
             test_case.save_diff(os.path.join(HTML_OUTPUT, 'output', string.replace(test_case.name, '.blend', '_diff.png')))





More information about the Bf-blender-cvs mailing list