[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30289] branches/soc-2010-leifandersen/ tests/render/run.py: No new features, just some refactoring of code to make it cleaner, in order to hopefully make the parameter usage less of a hack (and thus, hopefully work better).

Leif Andersen leif.a.andersen at gmail.com
Wed Jul 14 03:48:35 CEST 2010


Revision: 30289
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30289
Author:   leifandersen
Date:     2010-07-14 03:48:34 +0200 (Wed, 14 Jul 2010)

Log Message:
-----------
No new features, just some refactoring of code to make it cleaner, in order to hopefully make the parameter usage less of a hack (and thus, hopefully work better).

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-13 23:51:21 UTC (rev 30288)
+++ branches/soc-2010-leifandersen/tests/render/run.py	2010-07-14 01:48:34 UTC (rev 30289)
@@ -6,6 +6,7 @@
 import sys
 import string
 import subprocess
+import optparse
 
 from subprocess import Popen, PIPE
 
@@ -84,13 +85,9 @@
         self.mode = 'Image'
         try:
             self.good_image = Image.open(good_path)
-            #self.good_hash = self.generate_hash(self.good_image)
         except IOError:
             self.mode = 'Fail'
             self.good_image = None
-            self.good_hash = -1
-            self.test_hash = -1
-            self.diff_hash = -1
 
     def generate_hash(self, image):
         hash = 0
@@ -131,9 +128,6 @@
             self.diff_sum = 0
             self.difference = 0
             self.message = "Failed to render"
-            self.good_hash = -1
-            self.test_hash = -1
-            self.diff_hash = -1
 
     def image_test(self):
         '''Runs the test, filling in all of the usefull fields'''
@@ -194,44 +188,21 @@
             self.diff_path = output_path
             self.diff_image.save(output_path)
 
-class AnimationTestCase():
+class AnimationTestCase(ImageTestCase):
     ''''''
 
-    name = None
-    passed = None
     passed_arr = []
-    good_path = ''
     good_path_arr = []
-    blend_path = ''
-    test_path = ''
     test_path_arr = []
-    diff_path = ''
     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_animation = []
-    test_image = None
     test_animation = []
-    diff_image = None
     diff_animation = []
-    pixel_range = None
     pixel_range_arr = []
-    difference = None
     diffference_arr = []
-    good_hash = None
-    good_hash_arr = []
-    test_hash = None
-    test_hash_arr = []
-    diff_hash = None
-    diff_hash_arr = []
-    message = ""
-    ID = 'Animation'
-    mode = ''
 
     def __init__(self):
         self.name = 'Uninitialized'
@@ -251,9 +222,6 @@
         self.diff_animation = []
         self.pixel_range_arr = []
         self.diffference_arr = []
-        self.good_hash_arr = []
-        self.test_hash_arr = []
-        self.diff_hash_arr = []
         self.ID = 'Animation'
         self.good_hash = -1
         self.test_hash = -1
@@ -264,7 +232,12 @@
         self.name = os.path.split(blend_path)[1]
         self.good_hash = good_hash
         self.blend_path = blend_path
-        self.test_path = os.path.join(test_path, string.replace(self.name, '.blend', '_0001.png'))
+        for imagename in self.test_path_arr:
+            if imagename.find('.png') != -1:
+                self.test_path_arr.append(os.path.join(test_path, imagename))
+        self.test_path_arr.sort()
+        if len(self.test_path_arr) > 0:
+            self.test_path = self.test_path_arr[0]
         self.test_path_arr.append(self.test_path)
         self.mode = 'Hash'
 
@@ -285,7 +258,6 @@
                 im = Image.open(self.good_path_arr[i-1])
                 self.good_animation.append(im)
                 self.test_path_arr.append(os.path.join(test_path, blendname))
-                # self.good_hash_arr.append(self.generate_hash_image(im)) TODO removed due to time contstraint
                 i+=1
         
             self.good_path = self.good_path_arr[0]
@@ -294,39 +266,19 @@
         except IOError:
             self.mode = 'Fail'
             self.good_image = None
-            self.good_hash = -1
-            self.test_hash = -1
-            self.diff_hash = -1
             self.test_path = os.path.join(test_path, string.replace(self.name, '.blend', '_0001.png'))
         except OSError:
             self.mode = 'Fail'
             self.good_image = None
-            self.good_hash = -1
-            self.test_hash = -1
-            self.diff_hash = -1
             self.test_path = os.path.join(test_path, string.replace(self.name, '.blend', '_0001.png'))
 
-    def generate_hash(self, animation):
+    def generate_hash_animation(self, animation):
         hash = 0
         for image in animation:
-            frame_hash = self.generate_hash_image(image)
+            frame_hash = self.generate_hash(image)
             hash+=frame_hash
         return hash
 
-    def generate_hash_image(self, image):
-        hash = 0
-        for i in range(0,image.size[0]):
-            for j in range(0, image.size[1]):
-                p = image.getpixel((i,j))
-                hash+= p[0] + p[1] + p[2]
-        return hash
-
-    def format_frame(self, num):
-        frame_num = str(num)
-        while len(frame_num) < 4:
-            frame_num = '0' + frame_num
-        return frame_num
-
     def render_test(self):
         ''''''
         if VERBOSE:
@@ -352,9 +304,6 @@
             self.difference = 0
             self.message = "Failed to render"
             self.test_hash = None
-            self.good_hash = -1
-            self.test_hash = -1
-            self.diff_hash = -1
 
     def image_test(self):
         ''''''
@@ -365,7 +314,6 @@
                 im = ImageChops.difference(self.good_animation[i], self.test_animation[i]   )
                 self.diff_animation.append(im)
                 i+=1
-#            self.diff_hash = self.generate_hash(self.good_animation)
             self.diff_image = self.diff_animation[0]
 
             for diff_image in self.diff_animation:
@@ -422,13 +370,13 @@
         if self.test_image != None:
             if self.good_hash == None:
                 if self.good_image != None:
-                    self.good_hash = self.generate_hash(self.good_animation)
+                    self.good_hash = self.generate_hash_anim(self.good_animation)
                 else:
                     self.passed = False
                     self.message = 'No Good Hash or Good Image provided'
                     return
             if self.test_hash == None:
-                self.generate_hash(self.test_animation)
+                self.generate_hash_anim(self.test_animation)
             if self.pixel_count == None:
                 self.pixel_count = 0
                 for image in self.test_animation:
@@ -509,13 +457,6 @@
     file.close()
     return cases
 
-def get_cases(blend_file_folder, good_folder, output_folder):
-    '''Returns all of the blend files in the folder'''
-    cases = []
-    cases+=get_image_cases(blend_file_folder, good_folder, output_folder)
-    cases+=get_animation_cases(os.path.join(blend_file_folder, 'anim'), os.path.join(blend_file_folder, 'anim'), output_folder)
-    return cases
-
 def console_output(cases):
     '''Displays the final output to the console.  The output that will be shown if the -v flag isn't used'''
     failed = []
@@ -625,7 +566,6 @@
     file.write('</div>\n</body>\n</html>')
     file.close()
 
-
 def anim_output(animation, output_path):
     file = open(output_path, "w")
     (output_directory, output_file) = os.path.split(output_path)
@@ -673,123 +613,6 @@
     file.write('</div>\n</body>\n</html>')
     file.close()
 
-def generate_css(filepath):
-    file = open(filepath, 'w')
-    file.write('''#navcontainer {height: 50px;margin: 0 auto;position: relative;width: 980px;}
-#navcontainer img {width: 140px;height: 50px;}
-#pageheader  {background-image:url("bg.png");height:80px;position:relative;}
-body {font-family: "Lucida Grande","Lucida Sans Unicode","Lucida Sans","Lucida",Verdana,sans-serif;font-size: 12px;line-height: 145%;background-color: #000000;color: #ffffff;min-width: 980px;margin: 0;padding: 0;}
-div.document {margin:20px auto 0;position:relative;text-align:left;width:980px;/*    background-color: #1c4e63;*/}
-div.documentwrapper {float: left;width: 100%;background-color: #232323;border-color: #363636;border-style:solid;border-width:0 1px;margin:0 auto;min-height:30em;padding:35px;/*    position:relative;*/text-align:left;width:908px;}
-div.bodywrapper {margin: 0 0 0 230px;}
-div.body {background-color: #232323;color: #ffffff;padding: 0;width: 640px;}
-div.bodywrapper {margin: 0 230px 0 0;}
-div.footer {background: #292929;border-left: 1px solid #363636;border-right: 1px solid #363636color: #ffffff;/*    width: 100%;*/margin: 0 auto;padding: 20px 20px 15px 35px;text-align: center;font-size: 75%;}
-div.footer+.round b {display: block;background: #292929;width: auto;}
-div.footer+.round #r1 {border-left: 1px solid #363636;border-right: 1px solid #363636;height: 2px;margin: 0 1px;}
-div.footer+.round #r2 {border-left: 1px solid #363636;border-right: 1px solid #363636;height: 1px;margin: 0 2px;}
-div.footer+.round #r3 {border-left: 1px solid #363636;border-right: 1px solid #363636;height: 1px;margin: 0 3px;}
-div.footer+.round #r4 {border-bottom: 1px solid #363636;height: 0px;margin: 0 5px;}
-div.footer a {color: #ffffff;text-decoration: underline;}
-.boxheader {background-color:#3E4D5E;}
-.subnav {height:auto !important;min-height:15px;padding:9px 0px 9px 37px;position:relative;}
-div.related {width:auto;font-size:100%;font-weight:400;background-color: #2C3845;line-height: 145%;color: #D3E0E9;}
-div.related li {font-size:0.9em;}
-div.related li.right {margin: 0;word-spacing: 3px;}
-div.subnav li {display:inline;list-style-type:none;margin:0;padding:0 7px 0 0;}
-div.subnav ul {display:inline;margin:0;padding:0;}
-.subnav a {font-weight: bold;color: #fff;}
-.subnav li.subnav-active a {color:#F39410;}
-div.related a {color: #D3E0E9;}
-div.related a:active {color: #f39410;}
-a {color: #97b9cf;text-decoration: none;}
-a:hover {text-decoration: underline;}
-div.body h2,
-div.body h3,
-div.body h4,
-div.body h5,
-div.body h6 {font-family: "Lucida Grande","Lucida Sans Unicode","Lucida Sans","Lucida",Verdana,sans-serif;background-color: #232323;font-weight: bold;color: #ffffff;/*    border-bottom: 1px solid #ccc;*/margin: 20px -20px 10px -20px;padding: 3px 0 3px 10px;}
-div.body h1 { margin-top: 0; font-size: 200%; color:#FFFAE0;font-family:"Helvetica","Arial",sans-serif;font-size:34px;font-weight:normal;left:32px;line-height:26px;margin-top:0;position:absolute;top:36px;}
-div.body h2 { font-size: 160%; }
-div.body h3 { font-size: 140%; }
-div.body h4 { font-size: 120%; }
-div.body h5 { font-size: 110%; }
-div.body h6 { font-size: 100%; }

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list