[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30349] branches/soc-2010-leifandersen/ tests/render/run.py: 1.
Leif Andersen
leif.a.andersen at gmail.com
Wed Jul 14 23:01:21 CEST 2010
Revision: 30349
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30349
Author: leifandersen
Date: 2010-07-14 23:01:21 +0200 (Wed, 14 Jul 2010)
Log Message:
-----------
1. Added a --good-blender-bin flag to set the good blender bin.
2. Fixed the problem of --with-animations causing the whole app to crash, but --with-animations still has a few new problems.
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-14 20:52:23 UTC (rev 30348)
+++ branches/soc-2010-leifandersen/tests/render/run.py 2010-07-14 21:01:21 UTC (rev 30349)
@@ -12,7 +12,6 @@
from optparse import OptionParser
BLENDER_BIN = 'blender'
-GOOD_BLENDER_BIN = 'blender'
VERBOSE = False
class ImageTestCase:
@@ -31,9 +30,6 @@
bad_pixels = None
pixel_count = None
diff_sum = None
- good_image = None
- test_image = None
- diff_image = None
pixel_range = None
difference = None
good_hash = None
@@ -65,12 +61,6 @@
self.good_path = good_path
self.test_path = test_path
self.mode = 'Image'
- try:
- self.good_image = Image.open(good_path)
- except IOError:
- self.passed = False
- self.good_image = None
- self.messaged = 'Failed to find good image'
def generate_hash(self, image):
hash = 0
@@ -80,6 +70,16 @@
hash+= p[0] + p[1] + p[2]
return hash
+ def get_images(self):
+ try:
+ good_image = Image.open(self.good_path)
+ test_image = Image.open(self.test_path)
+ diff_image = ImageChops.difference(good_image, test_image)
+ except IOError:
+ good_image = test_image = diff_image = None
+ finally:
+ return (good_image, test_image, diff_image)
+
def format_frame(self, num):
frame_num = str(num)
while len(frame_num) < 4:
@@ -98,31 +98,18 @@
p.wait()
self.test_path += '_0001.png'
- try:
- self.test_image = Image.open(self.test_path)
- self.test_hash = self.generate_hash(self.test_image)
- except IOError:
- self.test_image = None
- self.passed = False
- self.pixel_range = 0
- self.bad_pixels = 0
- self.pixel_count = 0
- self.diff_sum = 0
- self.difference = 0
- self.message = "Failed to render"
def image_test(self):
'''Runs the test, filling in all of the usefull fields'''
- if self.good_image != None and self.test_image != None:
+ try:
+ (good_image, test_image, diff_image) = self.get_images()
self.diff_sum = 0
- self.diff_image = ImageChops.difference(self.good_image, self.test_image)
- self.generate_hash(self.diff_image)
self.bad_pixels = 0
- self.pixel_range = len(self.diff_image.histogram())
- self.pixel_count = self.diff_image.size[0] * self.diff_image.size[1]
- for i in range(0,self.diff_image.size[0]):
- for j in range(0, self.diff_image.size[1]):
- p = self.diff_image.getpixel((i,j))
+ self.pixel_range = len(diff_image.histogram())
+ self.pixel_count = diff_image.size[0] * diff_image.size[1]
+ for i in range(0,diff_image.size[0]):
+ for j in range(0, diff_image.size[1]):
+ p = diff_image.getpixel((i,j))
self.diff_sum+= p[0] + p[1] + p[2]
if p[0] + p[1] + p[2] > 10:
self.bad_pixels+=1
@@ -131,26 +118,41 @@
self.passed = True
else:
self.passed = False
+ except TypeError:
+ self.passed = False
+ self.diff_sum = -1
+ self.bad_pixels = -1
+ self.pixel_count = -1
+ self.pixel_range = -1
+ self.message = 'An error Occurred'
+ except AttributeError:
+ self.passed = False
+ self.diff_sum = -1
+ self.bad_pixels = -1
+ self.pixel_count = -1
+ self.pixel_range = -1
+ self.message = 'An error Occurred'
+ finally:
return self.passed
def hash_test(self):
- if self.test_image == None:
+ if test_image == None:
try:
- self.test_image = Image.open(self.test_path)
+ test_image = Image.open(self.test_path)
except IOError:
self.passed = False
- if self.test_image != None:
+ if test_image != None:
if self.good_hash == None:
- if self.good_image != None:
- self.good_hash = self.generate_hash(self.good_image)
+ if good_image != None:
+ self.good_hash = self.generate_hash(good_image)
else:
self.message = 'No Good Hash given, or Good Image given'
self.passed = False
return
if self.test_hash == None:
- self.test_hash = self.generate_hash(self.test_image)
+ self.test_hash = self.generate_hash(test_image)
if self.pixel_count == None:
- self.pixel_count = self.test_image.size[0] * self.test_image.size[1]
+ self.pixel_count = test_image.size[0] * test_image.size[1]
self.diff_hash = abs(self.test_hash - self.good_hash)
if self.diff_hash < self.pixel_count/10:
self.passed = True
@@ -159,9 +161,10 @@
def save_diff(self, output_path):
'''Saves the diff image to output_path'''
- if self.diff_image != None:
+ (good_image, test_image, diff_image) = self.get_images()
+ if diff_image != None:
self.diff_path = output_path
- self.diff_image.save(output_path)
+ diff_image.save(output_path)
class AnimationTestCase(ImageTestCase):
''''''
@@ -173,9 +176,6 @@
bad_pixels_arr = []
pixel_count_arr = []
diff_sum_arr = []
- good_animation = []
- test_animation = []
- diff_animation = []
pixel_range_arr = []
diffference_arr = []
@@ -192,9 +192,6 @@
self.bad_pixels_arr = []
self.pixel_count_arr = []
self.diff_sum_arr = []
- self.good_animation = []
- self.test_animation = []
- self.diff_animation = []
self.pixel_range_arr = []
self.diffference_arr = []
self.ID = 'Animation'
@@ -218,42 +215,50 @@
def setup_image(self, blend_path, good_path, test_path):
''''''
+ self.name = os.path.split(blend_path)[1]
+ self.blend_path = blend_path
+ for imagename in os.listdir(good_path):
+ if imagename.find('.png') != -1:
+ self.good_path_arr.append(os.path.join(good_path, imagename))
+ self.good_path_arr.sort()
+ self.mode = 'Image'
+ for imagename in self.good_path_arr:
+ (imagepath, blendname) = os.path.split(imagename)
+ self.test_path_arr.append(os.path.join(self.test_path, blendname))
+ if len(self.good_path) > 0:
+ self.good_path = self.good_path_arr[0]
+ self.test_path = self.test_path_arr[0]
+
+ def generate_hash_animation(self, animation):
+ hash = 0
+ for image in animation:
+ frame_hash = self.generate_hash(image)
+ hash+=frame_hash
+ return hash
+
+ def get_animations(self):
try:
- self.name = os.path.split(blend_path)[1]
- self.blend_path = blend_path
- for imagename in os.listdir(good_path):
- if imagename.find('.png') != -1:
- self.good_path_arr.append(os.path.join(good_path, imagename))
- self.good_path_arr.sort()
- self.mode = 'Image'
+ good_animation = []
+ test_animation = []
+ diff_animation = []
i=1
for imagename in self.good_path_arr:
(imagepath, blendname) = os.path.split(imagename)
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))
+ good_animation.append(im)
i+=1
-
- self.good_path = self.good_path_arr[0]
- self.good_image = self.good_animation[0]
- self.test_path = self.test_path_arr[0]
+
+ for imagename in self.test_path_arr:
+ im = Image.open(imagename)
+ test_animation.append(im)
except IOError:
- self.mode = 'Fail'
- self.good_image = None
- 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.test_path = os.path.join(test_path, string.replace(self.name, '.blend', '_0001.png'))
+ good_animation=test_animation_diff_animation = None
+ except IOError:
+ good_animation=test_animation=diff_animation = None
+ finally:
+ return (good_animation, test_animation, diff_animation)
- def generate_hash_animation(self, animation):
- hash = 0
- for image in animation:
- frame_hash = self.generate_hash(image)
- hash+=frame_hash
- return hash
-
def render_test(self):
''''''
if VERBOSE:
@@ -262,36 +267,19 @@
else:
p = Popen([BLENDER_BIN, '-b', self.blend_path, '-o', string.replace(self.test_path, '_0001.png', '_####'), '-F', 'PNG', '-x', '1', '-a'], stdout=None, stderr=None, stdin=None)
p.wait()
- try:
- for imagename in self.test_path_arr:
- im = Image.open(imagename)
- self.test_animation.append(im)
- if len(self.test_animation) > 0:
- self.test_image = self.test_animation[0]
- except IOError:
- self.mdoe = 'Fail'
- self.test_image = None
- self.passed = False
- self.pixel_range = 0
- self.bad_pixels = 0
- self.pixel_count = 0
- self.diff_sum = 0
- self.difference = 0
- self.message = "Failed to render"
- self.test_hash = None
-
+
def image_test(self):
''''''
- if self.test_image != None and len(self.good_animation) == len(self.test_animation):
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list