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

Leif Andersen leif.a.andersen at gmail.com
Wed Jul 14 06:43:04 CEST 2010


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

Log Message:
-----------
1.  Replaced a bunch of the old parameter parsing with optparse methods.  Although this currently restricts functionality, it has so far proven to make much cleaner code.

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 03:19:19 UTC (rev 30290)
+++ branches/soc-2010-leifandersen/tests/render/run.py	2010-07-14 04:43:03 UTC (rev 30291)
@@ -9,12 +9,12 @@
 import optparse
 
 from subprocess import Popen, PIPE
+from optparse import OptionParser
 
-
 BLENDER_BIN = 'blender'
 RUN_ANIMATIONS = False
 RUN_IMAGES = True
-RUN_IMAGES_AND_ANIMATIONS = False
+RUN_ANIMATIONS = False
 VERBOSE = False
 SAVEOUT = sys.stdout
 BLEND_FILE_FOLDER = os.path.join(sys.path[0])
@@ -479,6 +479,9 @@
             print test_case.name
     else:
         print "All tests passed"
+    if len(failed) == len(cases):
+        print "Please build tests by running: python run.py --build-tests"
+        print "Or python --build-tests --with-animations to also build animation tests"
     print 'Check index.html for more information'
 
 def generate_output(images, output_path):
@@ -618,58 +621,37 @@
     cases = []
 
     # 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 == '--animation' and len(sys.argv) > argv_i:
-            RUN_IMAGES = False
-            argv_path = sys.argv[argv_i + 1]
-            (argv_directory, argv_file) = os.path.split(argv_path)
-            case = AnimationTestCase()
-            OPTIONAL_CASES.append((case, argv_path, os.path.join(argv_directory, string.replace(argv_file, '.blend', '')), os.path.join(argv_directory, 'output', string.replace(argv_file, '.blend', ''))))
-        if arg == '--with-animations':
-            RUN_IMAGES_AND_ANIMATIONS = True
-            RUN_IMAGES = False
-        if arg == '--image' and len(sys.argv) > argv_i:
-            RUN_IMAGES = False
-            argv_path = sys.argv[argv_i + 1]
-            (argv_directory, argv_file) = os.path.split(argv_path)
-            case = ImageTestCase()
-            OPTIONAL_CASES.append((case, argv_path, os.path.join(argv_directory, 'render', string.replace(argv_file, '.blend', '.png')), os.path.join(argv_directory, 'output', string.replace(argv_file, '.blend', ''))))
-            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 == '--hashcode' and len(sys.argv) > argv_i:
-            HASHCODE_TEST = True
-            RUN_IMAGES = False
-            HASHCODE_FILE = sys.argv[argv_i+1]
-        if arg == '--hashcode-test':
-            HASHCODE_TEST = True
-            RUN_IMAGES = False
-        if arg == '--get-hashcodes':
-            GET_HASHCODES = True
-        if arg == '-h' or arg == '-H' or arg == '--help' or arg == '--Help':
-            print HELP
-            sys.exit()
- 
-        argv_i += 1
+    parser = OptionParser()
+    parser.add_option('--build-tests', action='store_true', dest='build_tests', default=False,
+                      help="Render the images for the tests")
+    parser.add_option('--blender-bin', type='string', dest='blender_bin', default='blender',
+                      help="Location of the blender binary if not in your path.")
+    parser.add_option('-i', '--image', type='string', dest='image', default = '',
+                      help="Run an image test outside of the current folder")
+    parser.add_option('-a', '--animation', type='string', dest='animation', default = '',
+                      help="Run an animation test outside of the current folder")
+    parser.add_option('--with-animations', action='store_true', dest='run_animations', default=False,
+                      help="Run the animation tests as well as the image ones.")
+    parser.add_option('-v', '-V', '--verbose', action='store_true', dest='verbose',  default=False,
+                      help="Sets the output to be verbose")
+    (options, args) = parser.parse_args()
+    cases = []
+
+    BLENDER_BIN = options.blender_bin
+    VERBOSE = options.verbose
+    RUN_ANIMATIONS = options.run_animations
     
+    for arg in args:
+        (argv_directory, argv_file) = os.path.split(arg)
+        case = ImageTestCase()
+        OPTIONAL_CASES.append((case, arg, os.path.join(argv_directory, 'render', string.replace(argv_file, '.blend', '.png')), os.path.join(argv_directory, 'output', string.replace(argv_file, '.blend', ''))))
+ 
     # Get cases, unless told not to.
-    if RUN_IMAGES and HASHCODE_TEST == False and len(OPTIONAL_CASES) == 0:
+    if len(args) == 0:
         cases += get_image_cases(BLEND_FILE_FOLDER, GOOD_FOLDER, OUTPUT_FOLDER)
+        if RUN_ANIMATIONS:
+            cases += get_animation_cases(ANIM_BLEND_FILE_FOLDER, ANIM_GOOD_FOLDER, ANIM_OUTPUT_FOLDER)
 
-    if RUN_IMAGES_AND_ANIMATIONS and HASHCODE_TEST == False and len(OPTIONAL_CASES) == 0:
-        cases += get_image_cases(BLEND_FILE_FOLDER, GOOD_FOLDER, OUTPUT_FOLDER)
-        cases += get_animation_cases(ANIM_BLEND_FILE_FOLDER, ANIM_GOOD_FOLDER, ANIM_OUTPUT_FOLDER)
-
     if HASHCODE_TEST == True and len(OPTIONAL_CASES) == 0:
         cases += get_hash_cases(BLEND_FILE_FOLDER, HASHCODE_FILE, OUTPUT_FOLDER)
         if RUN_IMAGES_AND_ANIMATIONS:





More information about the Bf-blender-cvs mailing list