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

Leif Andersen leif.a.andersen at gmail.com
Sat Jul 10 00:06:32 CEST 2010


Revision: 30163
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30163
Author:   leifandersen
Date:     2010-07-10 00:06:32 +0200 (Sat, 10 Jul 2010)

Log Message:
-----------
1.  I added the ability to generate tests.

2.  Removed the built in tests (will add again momentarily, again, svn is requiring me to commit before I add again).

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

Removed Paths:
-------------
    branches/soc-2010-leifandersen/tests/render/render/

Modified: branches/soc-2010-leifandersen/tests/render/run.py
===================================================================
--- branches/soc-2010-leifandersen/tests/render/run.py	2010-07-09 21:27:29 UTC (rev 30162)
+++ branches/soc-2010-leifandersen/tests/render/run.py	2010-07-09 22:06:32 UTC (rev 30163)
@@ -10,14 +10,24 @@
 from subprocess import Popen, PIPE
 
 
-BLENDER_BIN = "blender"
+BLENDER_BIN = 'blender'
 RUN_ANIMATIONS = False
 RUN_IMAGES = True
+RUN_IMAGES_AND_ANIMATIONS = False
 VERBOSE = False
 SAVEOUT = sys.stdout
-LOG = None
+BLEND_FILE_FOLDER = os.path.join(sys.path[0])
+ANIM_BLEND_FOLDER = os.path.join(sys.path[0], 'anim')
+GOOD_FOLDER = os.path.join(sys.path[0], 'render')
+ANIM_GOOD_FOLDER = os.path.join(sys.path[0], 'anim')
+OUTPUT_FOLDER = os.path.join(sys.path[0], 'output')
+ANIM_OUTPUT_FOLDER = os.path.join(sys.path[0], 'output')
 HTML_OUTPUT = sys.path[0]
+GOOD_BLENDER_BIN = 'blender'
+BUILDING_TESTS = False
 
+HELP = '''Help to come'''
+
 class ImageTestCase:
     '''A Render Test Case.  Steps must be run in order:
     1. Constructer
@@ -59,11 +69,15 @@
             For images, the known good path is a file, 
             for animations, it's a folder containing all of the frames'''
         self.name = os.path.split(blend_path)[1]
-        self.good_image = Image.open(good_path)
         self.blend_path = blend_path
         self.good_path = good_path
         self.test_path = test_path
-        self.good_hash = self.generate_hash(self.good_image)
+        try:
+            self.good_image = Image.open(good_path)
+            self.good_hash = self.generate_hash(self.good_image)
+        except IOError:
+            self.good_image = None
+            self.good_hash = -1
 
     def generate_hash(self, image):
         hash = 0
@@ -334,34 +348,34 @@
                 i+=1
             self.diff_path = self.diff_path_arr[0]
 
-def get_cases(folder):
+def get_cases(blend_file_folder, good_folder, output_folder):
     '''Returns all of the blend files in the folder'''
     cases = []
-    cases+=get_image_cases(folder)
-    cases+=get_animation_cases(os.path.join(folder, 'anim'))
+    cases+=get_image_cases(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 get_image_cases(folder):
+def get_image_cases(blend_file_folder, good_folder, output_folder):
     '''Returns all of the image blend files in the folder'''
     cases = []
-    for filename in os.listdir(folder):
+    for filename in os.listdir(blend_file_folder):
         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', ''))
+            blend_path = os.path.join(blend_file_folder, filename)
+            good_path = os.path.join(good_folder, string.replace(filename, '.blend', '_0001.png'))
+            test_path = os.path.join(output_folder, string.replace(filename, '.blend', ''))
             test_case = ImageTestCase()
             test_case.setup_image(blend_path, good_path, test_path)
             cases.append(test_case)
     return cases
 
-def get_animation_cases(folder):
+def get_animation_cases(blend_file_folder, good_folder, output_folder):
     '''Returns all of the animation blend files in the folder'''
     cases = []
     for filename in os.listdir(folder):
         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', ''))
+            blend_path = os.path.join(blend_file_folder, filename)
+            good_path = os.path.join(good_folder, string.replace(filename, '.blend', ''))
+            test_path = os.path.join(output_folder, string.replace(filename, '.blend', ''))
             test_case = AnimationTestCase()
             test_case.setup_hash(blend_path, good_path, test_path)
             cases.append(test_case)
@@ -372,16 +386,20 @@
     '''Displays the final output to the console.  The output that will be shown if the -v flag isn't used'''
     failed = []
     print ''
-    for test_case in cases:
-        if test_case.passed == False:
-            failed.append(test_case)
+    if not BUILDING_TESTS:
+        for test_case in cases:
+            if test_case.passed == False:
+                failed.append(test_case)
     
     if len(failed) > 0:
         print "The following tesets failed:"
         for test_case in failed:
             print test_case.name
+    elif BUILDING_TESTS:
+        print "Tests built successfully"
     else:
         print "All tests passed"
+    print 'Check index.html for more information'
 
 def generate_output(images, output_file):
     ''''''
@@ -507,28 +525,43 @@
             HTML_OUTPUT =  argv_directory
         if arg == '-v' or arg == '-V' or arg == '--verbose':
             VERBOSE = True
+        if arg == '--build-tests':
+            BLENDER_BIN = GOOD_BLENDER_BIN
+            OUTPUT_FOLDER = GOOD_FOLDER
+            ANIM_OUTPUT_FOLDER = ANIM_GOOD_FOLDER
+            GOOD_FOLDER = ''
+            ANIM_GOOD_FOLDER = ''
+            BUILDING_TESTS = True
+        if arg == '-h' or arg == '-H' or arg == '--help' or arg == '--Help':
+            print HELP
+            sys.exit()
+ 
         argv_i += 1
     
     # Get cases, unless told not to.
     if RUN_IMAGES:
-        cases = get_image_cases(sys.path[0])
+        cases = get_image_cases(BLEND_FILE_FOLDER, GOOD_FOLDER, OUTPUT_FOLDER)
         cases.sort(key=lambda case: case.name)
 
+    if RUN_IMAGES_AND_ANIMATIONS:
+        cases = get_cases(sys.path[0])
+        cases.sort(key=lambda case: case.name)
+
     # Run cases
     for test_case in cases:
         print test_case.name + '...',
         test_case.render_test()
         test_case.setup_test()
         test_case.save_diff(os.path.join(HTML_OUTPUT, 'output', string.replace(test_case.name, '.blend', '_diff.png')))
-        if test_case.passed:
+        if test_case.passed or BUILDING_TESTS:
             print 'OK'
         else:
             print 'FAILED'
 
     # Output Result
-    print 'Generating Output'
-    generate_css(os.path.join(HTML_OUTPUT, 'style.css'))
-    generate_output(cases, os.path.join(HTML_OUTPUT, 'index.html'))
+    if not BUILDING_TESTS:
+        print 'Generating Output'
+        generate_css(os.path.join(HTML_OUTPUT, 'style.css'))
+        generate_output(cases, os.path.join(HTML_OUTPUT, 'index.html'))
     console_output(cases)
-    print 'Check index.html for more information'
 





More information about the Bf-blender-cvs mailing list