[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30009] branches/soc-2010-leifandersen/ tests/render/run.py: 1.
Leif Andersen
leif.a.andersen at gmail.com
Tue Jul 6 02:48:05 CEST 2010
Revision: 30009
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30009
Author: leifandersen
Date: 2010-07-06 02:48:05 +0200 (Tue, 06 Jul 2010)
Log Message:
-----------
1. Initial work for creating animation tests done. (Case stores an ID, which tells it if it's an image, or an animation).
2. Work done on parsing arguements, arguements now accepted are:
-V -v --verbose, (currently doesn't work), suppresses blender's output, making it easier to see as tests are running.
--Image, run just a single image, rather than all images in the folder.
3. --Animation, run an animation, rather than the images in the folder.
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-06 00:40:54 UTC (rev 30008)
+++ branches/soc-2010-leifandersen/tests/render/run.py 2010-07-06 00:48:05 UTC (rev 30009)
@@ -10,9 +10,12 @@
# BLENDER_BIN = "/home/leif/blender-svn/blender-build/bin/blender"
BLENDER_BIN = "blender"
+RUN_ANIMATIONS = False
+RUN_IMAGES = True
+VERBOSE = False
+SAVEOUT = sys.stdout
+LOG = None
-
-
class RenderTestCase:
'''A Render Test Case. Steps must be run in order:
1. Constructer
@@ -35,22 +38,32 @@
pixel_range = None
difference = None
message = ""
+ ID = None
- def __init__(self, blend_path, good_path, test_path):
+ def __init__(self, ID, blend_path, good_path, test_path):
+ '''Sets up a test case, with the blend_path, the known good path, and the test path
+ For images, the known good path is a file,
+ for animations, it's a folder containing all of the frames'''
+ if ID == 'Image' or ID == 'Animation':
+ self.ID = ID
+ else:
+ self.ID = 'FAIL'
self.blend_path = blend_path
self.good_path = good_path
self.name = os.path.split(blend_path)[1]
self.good_image = Image.open(good_path)
self.test_path = test_path
-
def render_image(self):
+ '''Renders a single image of the first frame of the blend file.
+ Also changes output_path slightly'''
command = BLENDER_BIN + " -b " + self.blend_path + " -o " + self.test_path + "_#### -F PNG -x 1 -f 1"
os.system(command)
self.test_path += '_0001.png'
try:
self.test_image = Image.open(self.test_path)
except IOError:
+ self.ID = 'Fail'
self.test_image = None
self.passed = False
self.pixel_range = 0
@@ -60,8 +73,24 @@
self.difference = 0
self.message = "Failed to render"
+ def render_anim(self):
+ command = BLENDER_BIN + " -b " + self.blend_path + " -o " + self.test_path + "_#### -F PNG -x 1 -a"
+ os.system(command)
+ try:
+ self.test_image = Image.open(self.test_path)
+ 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 setup_test(self):
+ '''Runs the test, filling in all of the usefull fields'''
if self.test_image != None:
self.diff_sum = 0
self.diff_image = ImageChops.difference(self.good_image, self.test_image)
@@ -81,14 +110,20 @@
self.passed = False
return self.passed
-
def save_diff(self, output_path):
+ '''Saves the diff image to output_path'''
if self.diff_image != None:
- self.diff_path = output_path
- self.diff_image.save(output_path)
+ if self.ID == 'Image':
+ self.diff_path = output_path
+ self.diff_image.save(output_path)
+ if self.ID == 'Animation':
+ self.diff_path = output_path
+ i = 1
+ for image in self.diff_image:
+ self.diff_image.save(output_path + '_diff_' + i + '.png')
+ i+=1
-
def get_cases(folder):
'''Returns all of the blend files in the folder'''
cases = []
@@ -97,12 +132,13 @@
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 = RenderTestCase(blend_path, good_path, test_path)
+ test_case = RenderTestCase('Image', blend_path, good_path, test_path)
cases.append(test_case)
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 = []
for test_case in cases:
if test_case.passed == False:
@@ -116,6 +152,7 @@
print "All tests passed"
def generate_output(images):
+ ''''''
file = open(os.path.join(sys.path[0],"index.html"), "w")
file.write('<html><head>\n')
file.write('<link rel="stylesheet" href="_static/default.css" type="text/css" />\n')
@@ -137,9 +174,9 @@
if image.passed == False:
file.write('<tr>\n')
file.write('<td>' + image.name + '</td>\n')
- file.write('<td><img src="' + os.path.join('render', string.replace(image.name, '.blend', '.png')) + '" alt="Good Image" width="200" height="150"></td>\n')
- file.write('<td><img src="' + os.path.join('output', string.replace(image.name, '.blend', '_0001.png')) + '" alt="Latest Render" width="200" height="150"></td>\n')
- file.write('<td><img src="' + os.path.join('output', string.replace(image.name, '.blend', '_diff.png')) + '" alt="Image Diff" width="200" height="150"></td>\n')
+ file.write('<td><a href="' + os.path.join('render', string.replace(image.name, '.blend', '.png')) + '"><img src="' + os.path.join('render', string.replace(image.name, '.blend', '.png')) + '" alt="Good Image" width="200" height="150"></a></td>\n')
+ file.write('<td><a href="' + os.path.join('output', string.replace(image.name, '.blend', '_0001.png')) + '"><img src="' + os.path.join('output', string.replace(image.name, '.blend', '_0001.png')) + '" alt="Latest Render" width="200" height="150"></a></td>\n')
+ file.write('<td><a href="' + os.path.join('output', string.replace(image.name, '.blend', '_diff.png')) + '"><img src="' + os.path.join('output', string.replace(image.name, '.blend', '_diff.png')) + '" alt="Image Diff" width="200" height="150"></a></td>\n')
file.write('<td>')
if image.passed:
file.write('<font color="ooffoo">OK</font>: ' + str(image.bad_pixels) + ' of ' + str(image.pixel_count) + ' pixels different, ' + str(image.difference) + '% different.')
@@ -164,9 +201,9 @@
if image.passed == True:
file.write('<tr>\n')
file.write('<td>' + image.name + '</td>\n')
- file.write('<td><img src="' + os.path.join('render', string.replace(image.name, '.blend', '.png')) + '" alt="Good Image" width="200" height="150"></td>\n')
- file.write('<td><img src="' + os.path.join('output', string.replace(image.name, '.blend', '_0001.png')) + '" alt="Latest Render" width="200" height="150"></td>\n')
- file.write('<td><img src="' + os.path.join('output', string.replace(image.name, '.blend', '_diff.png')) + '" alt="Image Diff" width="200" height="150"></td>\n')
+ file.write('<td><a href="' + os.path.join('render', string.replace(image.name, '.blend', '.png')) + '"><img src="' + os.path.join('render', string.replace(image.name, '.blend', '.png')) + '" alt="Good Image" width="200" height="150"></a></td>\n')
+ file.write('<td><a href="' + os.path.join('output', string.replace(image.name, '.blend', '_0001.png')) + '"><img src="' + os.path.join('output', string.replace(image.name, '.blend', '_0001.png')) + '" alt="Latest Render" width="200" height="150"></a></td>\n')
+ file.write('<td><a href="' + os.path.join('output', string.replace(image.name, '.blend', '_diff.png')) + '"><img src="' + os.path.join('output', string.replace(image.name, '.blend', '_diff.png')) + '" alt="Image Diff" width="200" height="150"></a></td>\n')
file.write('<td>')
if image.passed:
file.write('<font color="ooffoo">OK</font>: ' + str(image.bad_pixels) + ' of ' + str(image.pixel_count) + ' pixels different, ' + str(image.difference) + '% different.')
@@ -181,28 +218,71 @@
file.close()
-def anim_output(animation, location):
- file = open(location, 'w')
+def anim_output(animation, output_location):
+ file = open(output_location, 'w')
file.write('<html>\n<head><title>' + animation.name + '</title></head>\n')
- file.write('<body>\n<table border="1"')
+ file.write('<body>\n')
+ file.write('<h1>' + animation.name + '</h1>')
+ file.write('<table border="1"\n')
+ file.write('<tr>\n')
+ file.write('<th>Frame Number</th>\n')
+ file.write('<th>Good Image</th>\n')
+ file.write('<th>Latest Render</th>\n')
+ file.write('<th>Diff</th>\n')
+ file.write('<th>Match?</th>\n')
+ file.write('</tr>\n')
+ i = 1
+ for frame in animation.test_image:
+ file.write('<tr>\n')
+ file.write('<td>' + i + '</td>\n')
+ file.write('<td><a href="' + os.path.join('render', string.replace(image.name, '.blend', '.png')) + '"><img src="' + os.path.join('render', string.replace(image.name, '.blend', '.png')) + '" alt="Good Image" width="200" height="150"></a></td>\n')
+ file.write('<td><a href="' + os.path.join('output', string.replace(image.name, '.blend', '_0001.png')) + '"><img src="' + os.path.join('output', string.replace(image.name, '.blend', '_0001.png')) + '" alt="Latest Render" width="200" height="150"></a></td>\n')
+ file.write('<td><a href="' + os.path.join('output', string.replace(image.name, '.blend', '_diff.png')) + '"><img src="' + os.path.join('output', string.replace(image.name, '.blend', '_diff.png')) + '" alt="Image Diff" width="200" height="150"></a></td>\n')
+
+ file.write('</tr>\n')
+ i+=1
file.write('</table>\n</body>\n</html>')
if __name__ == "__main__":
- if len(sys.argv) > 2:
- if sys.argv[1] == '--blender-bin':
- BLENDER_BIN = sys.argv[2]
+ # Case list, can contain both image cases, and animation cases
+ cases = []
- cases = get_cases(sys.path[0])
- cases.sort(key=lambda case: case.name)
+ # Parse the arguements
+ argv_i = 0
+ for arg in sys.argv:
+ if arg == '--blender-bin' and len(sys.argv) > argv_i:
+ BLENDER_BIN = sys.argv[argv_i + 1]
+ if arg == '--animations':
+ RUN_ANIMATIONS = True
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list