[Bf-blender-cvs] [a6fcfba] cycles_ctests: Add BLENDER_VERBOSE env var check to cycles test

Campbell Barton noreply at git.blender.org
Thu Jan 22 10:25:07 CET 2015


Commit: a6fcfbacf024b8ac6496886fc67936fa5ce3a373
Author: Campbell Barton
Date:   Thu Jan 22 20:24:01 2015 +1100
Branches: cycles_ctests
https://developer.blender.org/rBa6fcfbacf024b8ac6496886fc67936fa5ce3a373

Add BLENDER_VERBOSE env var check to cycles test

This means you can see Blender's output if you want.
also minor style edits

===================================================================

M	tests/python/cycles/render_tests.py

===================================================================

diff --git a/tests/python/cycles/render_tests.py b/tests/python/cycles/render_tests.py
index ee80a0b..036166a 100755
--- a/tests/python/cycles/render_tests.py
+++ b/tests/python/cycles/render_tests.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python3
+# Apache License, Version 2.0
 
 import argparse
 import os
@@ -6,35 +7,22 @@ import subprocess
 import sys
 import tempfile
 
-parser = argparse.ArgumentParser()
-parser.add_argument('-blender', nargs='+')
-parser.add_argument('-testdir', nargs=1)
-parser.add_argument('-idiff', nargs=1)
-args = parser.parse_args()
-
-BLENDER = args.blender[0]
-ROOT = args.testdir[0]
-IDIFF = args.idiff[0]
-
-TEMP = tempfile.mkdtemp()
-TEMP_FILE_MASK = os.path.join(TEMP, "test")
-TEMP_FILE = TEMP_FILE_MASK + '0001.png'
-
-TEST_SCRIPT = os.path.join(os.path.dirname(__file__), 'runtime_check.py')
-
 
 def render_file(filepath):
-    command = [BLENDER,
-               '--background',
-               '-noaudio',
-               '--factory-startup',
-               filepath,
-               '--python', TEST_SCRIPT,
-               '-o', TEMP_FILE_MASK,
-               '-f', '1',
-               ]
+    command = (
+        BLENDER,
+        "--background",
+        "-noaudio",
+        "--factory-startup",
+        filepath,
+        "--python", TEST_SCRIPT,
+        "-o", TEMP_FILE_MASK,
+        "-f", "1",
+        )
     try:
-        subprocess.check_output(command)
+        output = subprocess.check_output(command)
+        if VERBOSE:
+            print(output.decode("utf-8"))
         return None if os.path.exists(TEMP_FILE) else "NOT_FOUND"
     except subprocess.CalledProcessError as grepexc:
         return "NO_CYCLES" if grepexc.returncode == 128 else "CRASH"
@@ -52,16 +40,17 @@ def test_get_name(filepath):
 def verify_output(filepath):
     testname = test_get_name(filepath)
     dirpath = os.path.dirname(filepath)
-    reference_dirpath = os.path.join(dirpath, 'reference_renders')
-    reference_image = os.path.join(reference_dirpath, testname + '.png')
+    reference_dirpath = os.path.join(dirpath, "reference_renders")
+    reference_image = os.path.join(reference_dirpath, testname + ".png")
     if not os.path.exists(reference_image):
         return False
-    command = [IDIFF,
-               '-fail', '0.01',
-               '-failpercent', '1',
-               reference_image,
-               TEMP_FILE,
-              ]
+    command = (
+        IDIFF,
+        "-fail", "0.01",
+        "-failpercent", "1",
+        reference_image,
+        TEMP_FILE,
+        )
     try:
         subprocess.check_output(command)
         return True
@@ -72,14 +61,14 @@ def verify_output(filepath):
 def run_test(filepath):
     testname = test_get_name(filepath)
     spacer = "." * (32 - len(testname))
-    print(testname, spacer, end='')
+    print(testname, spacer, end="")
     sys.stdout.flush()
     error = render_file(filepath)
     if not error:
         if verify_output(filepath):
-            print('PAS')
+            print("PASS")
         else:
-            error = 'VERIFY'
+            error = "VERIFY"
     if error:
         print("FAIL", error)
     return error
@@ -100,8 +89,8 @@ def run_all_tests(dirpath):
     for filepath in all_files:
         error = run_test(filepath)
         if error:
-            if error == 'NO_CYCLES':
-                print('Can not perform tests because Cycles can''t be loaed')
+            if error == "NO_CYCLES":
+                print("Can't perform tests because Cycles failed to load!")
                 return False
             testname = test_get_name(filepath)
             failed_tests.append(testname)
@@ -109,15 +98,48 @@ def run_all_tests(dirpath):
         failed_tests.sort()
         print("\n\nFAILED tests:")
         for test in failed_tests:
-            print("    " + test)
+            print("   ", test)
         return False
     return True
 
-ok = run_all_tests(ROOT)
 
-# Cleanup temp files and folders
-if os.path.exists(TEMP_FILE):
-    os.remove(TEMP_FILE)
-os.rmdir(TEMP)
+def create_argparse():
+    parser = argparse.ArgumentParser()
+    parser.add_argument("-blender", nargs="+")
+    parser.add_argument("-testdir", nargs=1)
+    parser.add_argument("-idiff", nargs=1)
+    return parser
+
+
+def main():
+    parser = create_argparse()
+    args = parser.parse_args()
+
+    global BLENDER, ROOT, IDIFF
+    global TEMP_FILE, TEMP_FILE_MASK, TEST_SCRIPT
+    global VERBOSE
+
+    BLENDER = args.blender[0]
+    ROOT = args.testdir[0]
+    IDIFF = args.idiff[0]
+
+    TEMP = tempfile.mkdtemp()
+    TEMP_FILE_MASK = os.path.join(TEMP, "test")
+    TEMP_FILE = TEMP_FILE_MASK + "0001.png"
+
+    TEST_SCRIPT = os.path.join(os.path.dirname(__file__), "runtime_check.py")
+
+    VERBOSE = os.environ.get("BLENDER_VERBOSE") is not None
+
+    ok = run_all_tests(ROOT)
+
+    # Cleanup temp files and folders
+    if os.path.exists(TEMP_FILE):
+        os.remove(TEMP_FILE)
+    os.rmdir(TEMP)
+
+    sys.exit(not ok)
+
 
-sys.exit(0 if ok else 1)
+if __name__ == "__main__":
+    main()




More information about the Bf-blender-cvs mailing list