[Bf-blender-cvs] [0f23f618f36] master: Tests: split off render report test code from Cycles tests.

Brecht Van Lommel noreply at git.blender.org
Fri Feb 16 13:37:44 CET 2018


Commit: 0f23f618f36a7472d1c67b36344ef87a31eb586c
Author: Brecht Van Lommel
Date:   Wed Feb 14 17:33:06 2018 +0100
Branches: master
https://developer.blender.org/rB0f23f618f36a7472d1c67b36344ef87a31eb586c

Tests: split off render report test code from Cycles tests.

This renames test environment variables from CYCLESTEST_* to BLENDER_TEST_*.

Differential Revision: https://developer.blender.org/D3064

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

M	tests/python/cycles_render_tests.py
A	tests/python/modules/render_report.py

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

diff --git a/tests/python/cycles_render_tests.py b/tests/python/cycles_render_tests.py
index 731996df8ef..a01a6f74e15 100755
--- a/tests/python/cycles_render_tests.py
+++ b/tests/python/cycles_render_tests.py
@@ -2,55 +2,14 @@
 # Apache License, Version 2.0
 
 import argparse
-import glob
 import os
-import pathlib
 import shlex
 import shutil
 import subprocess
 import sys
-import time
-import tempfile
 
 
-class COLORS_ANSI:
-    RED = '\033[00;31m'
-    GREEN = '\033[00;32m'
-    ENDC = '\033[0m'
-
-
-class COLORS_DUMMY:
-    RED = ''
-    GREEN = ''
-    ENDC = ''
-
-COLORS = COLORS_DUMMY
-
-
-def print_message(message, type=None, status=''):
-    if type == 'SUCCESS':
-        print(COLORS.GREEN, end="")
-    elif type == 'FAILURE':
-        print(COLORS.RED, end="")
-    status_text = ...
-    if status == 'RUN':
-        status_text = " RUN      "
-    elif status == 'OK':
-        status_text = "       OK "
-    elif status == 'PASSED':
-        status_text = "  PASSED  "
-    elif status == 'FAILED':
-        status_text = "  FAILED  "
-    else:
-        status_text = status
-    if status_text:
-        print("[{}]" . format(status_text), end="")
-    print(COLORS.ENDC, end="")
-    print(" {}" . format(message))
-    sys.stdout.flush()
-
-
-def render_file(filepath):
+def render_file(filepath, output_filepath):
     dirname = os.path.dirname(filepath)
     basedir = os.path.dirname(dirname)
     subject = os.path.basename(dirname)
@@ -62,6 +21,8 @@ def render_file(filepath):
     # custom_args += ["--python-expr", "import bpy; bpy.context.scene.cycles.shading_system = True"]
     # custom_args += ["--python-expr", "import bpy; bpy.context.scene.cycles.device = 'GPU'"]
 
+    frame_filepath = output_filepath + '0001.png'
+
     if subject == 'opengl':
         command = [
             BLENDER,
@@ -73,7 +34,7 @@ def render_file(filepath):
             "-E", "CYCLES"]
         command += custom_args
         command += [
-            "-o", TEMP_FILE_MASK,
+            "-o", output_filepath,
             "-F", "PNG",
             '--python', os.path.join(basedir,
                                      "util",
@@ -89,7 +50,7 @@ def render_file(filepath):
             "-E", "CYCLES"]
         command += custom_args
         command += [
-            "-o", TEMP_FILE_MASK,
+            "-o", output_filepath,
             "-F", "PNG",
             '--python', os.path.join(basedir,
                                      "util",
@@ -105,321 +66,39 @@ def render_file(filepath):
             "-E", "CYCLES"]
         command += custom_args
         command += [
-            "-o", TEMP_FILE_MASK,
+            "-o", output_filepath,
             "-F", "PNG",
             "-f", "1"]
+
     try:
+        # Success
         output = subprocess.check_output(command)
+        if os.path.exists(frame_filepath):
+            shutil.copy(frame_filepath, output_filepath)
+            os.remove(frame_filepath)
         if VERBOSE:
             print(output.decode("utf-8"))
         return None
     except subprocess.CalledProcessError as e:
-        if os.path.exists(TEMP_FILE):
-            os.remove(TEMP_FILE)
+        # Error
+        if os.path.exists(frame_filepath):
+            os.remove(frame_filepath)
         if VERBOSE:
             print(e.output.decode("utf-8"))
         if b"Error: engine not found" in e.output:
-            return "NO_CYCLES"
+            return "NO_ENGINE"
         elif b"blender probably wont start" in e.output:
             return "NO_START"
         return "CRASH"
     except BaseException as e:
-        if os.path.exists(TEMP_FILE):
-            os.remove(TEMP_FILE)
+        # Crash
+        if os.path.exists(frame_filepath):
+            os.remove(frame_filepath)
         if VERBOSE:
             print(e)
         return "CRASH"
 
 
-def test_get_name(filepath):
-    filename = os.path.basename(filepath)
-    return os.path.splitext(filename)[0]
-
-def test_get_images(filepath):
-    testname = test_get_name(filepath)
-    dirpath = os.path.dirname(filepath)
-
-    old_dirpath = os.path.join(dirpath, "reference_renders")
-    old_img = os.path.join(old_dirpath, testname + ".png")
-
-    ref_dirpath = os.path.join(OUTDIR, os.path.basename(dirpath), "ref")
-    ref_img = os.path.join(ref_dirpath, testname + ".png")
-    if not os.path.exists(ref_dirpath):
-        os.makedirs(ref_dirpath)
-    if os.path.exists(old_img):
-        shutil.copy(old_img, ref_img)
-
-    new_dirpath = os.path.join(OUTDIR, os.path.basename(dirpath))
-    if not os.path.exists(new_dirpath):
-        os.makedirs(new_dirpath)
-    new_img = os.path.join(new_dirpath, testname + ".png")
-
-    diff_dirpath = os.path.join(OUTDIR, os.path.basename(dirpath), "diff")
-    if not os.path.exists(diff_dirpath):
-        os.makedirs(diff_dirpath)
-    diff_img = os.path.join(diff_dirpath, testname + ".diff.png")
-
-    return old_img, ref_img, new_img, diff_img
-
-
-class Report:
-    def __init__(self, testname):
-        self.failed_tests = ""
-        self.passed_tests = ""
-        self.testname = testname
-
-    def output(self):
-        # write intermediate data for single test
-        outdir = os.path.join(OUTDIR, self.testname)
-        if not os.path.exists(outdir):
-            os.makedirs(outdir)
-
-        filepath = os.path.join(outdir, "failed.data")
-        pathlib.Path(filepath).write_text(self.failed_tests)
-
-        filepath = os.path.join(outdir, "passed.data")
-        pathlib.Path(filepath).write_text(self.passed_tests)
-
-        # gather intermediate data for all tests
-        failed_data = sorted(glob.glob(os.path.join(OUTDIR, "*/failed.data")))
-        passed_data = sorted(glob.glob(os.path.join(OUTDIR, "*/passed.data")))
-
-        failed_tests = ""
-        passed_tests = ""
-
-        for filename in failed_data:
-            filepath = os.path.join(OUTDIR, filename)
-            failed_tests += pathlib.Path(filepath).read_text()
-        for filename in passed_data:
-            filepath = os.path.join(OUTDIR, filename)
-            passed_tests += pathlib.Path(filepath).read_text()
-
-        # write html for all tests
-        self.html = """
-<html>
-<head>
-    <title>Cycles Test Report</title>
-    <style>
-        img {{ image-rendering: pixelated; width: 256px; background-color: #000; }}
-        img.render {{
-            background-color: #fff;
-            background-image:
-              -moz-linear-gradient(45deg, #eee 25%, transparent 25%),
-              -moz-linear-gradient(-45deg, #eee 25%, transparent 25%),
-              -moz-linear-gradient(45deg, transparent 75%, #eee 75%),
-              -moz-linear-gradient(-45deg, transparent 75%, #eee 75%);
-            background-image:
-              -webkit-gradient(linear, 0 100%, 100% 0, color-stop(.25, #eee), color-stop(.25, transparent)),
-              -webkit-gradient(linear, 0 0, 100% 100%, color-stop(.25, #eee), color-stop(.25, transparent)),
-              -webkit-gradient(linear, 0 100%, 100% 0, color-stop(.75, transparent), color-stop(.75, #eee)),
-              -webkit-gradient(linear, 0 0, 100% 100%, color-stop(.75, transparent), color-stop(.75, #eee));
-
-            -moz-background-size:50px 50px;
-            background-size:50px 50px;
-            -webkit-background-size:50px 51px; /* override value for shitty webkit */
-
-            background-position:0 0, 25px 0, 25px -25px, 0px 25px;
-        }}
-        table td:first-child {{ width: 256px; }}
-    </style>
-    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
-</head>
-<body>
-    <div class="container">
-        <br/>
-        <h1>Cycles Test Report</h1>
-        <br/>
-        <table class="table table-striped">
-            <thead class="thead-default">
-                <tr><th>Name</th><th>New</th><th>Reference</th><th>Diff</th>
-            </thead>
-            {}{}
-        </table>
-        <br/>
-    </div>
-</body>
-</html>
-            """ . format(failed_tests, passed_tests)
-
-        filepath = os.path.join(OUTDIR, "report.html")
-        pathlib.Path(filepath).write_text(self.html)
-
-        print_message("Report saved to: " + pathlib.Path(filepath).as_uri())
-
-    def relative_url(self, filepath):
-        relpath = os.path.relpath(filepath, OUTDIR)
-        return pathlib.Path(relpath).as_posix()
-
-    def add_test(self, filepath, error):
-        name = test_get_name(filepath)
-        name = name.replace('_', ' ')
-
-        old_img, ref_img, new_img, diff_img = test_get_images(filepath)
-
-        status = error if error else ""
-        style = """ style="background-color: #f99;" """ if error else ""
-
-        new_url = self.relative_url(new_img)
-        ref_url = self.relative_url(ref_img)
-        diff_url = self.relative_url(diff_img)
-
-        test_html = """
-            <tr{}>
-                <td><b>{}</b><br/>{}<br/>{}</td>
-                <td><img src="{}" onmouseover="this.src='{}';" onmouseout="this.src='{}';" class="render"></td>
-                <td><img src="{}" onmouseover="this.src='{}';" onmouseout="this.src='{}';" class="render"></td>
-                <td><img src="{}"></td>
-            </tr>""" . format(style, name, self.testname, status,
-                              new_url, ref_url, new_url,
-                              ref_url, new_url, ref_url,
-                              diff_url)
-
-        if error:
-            self.failed_tests += test_html
-        else:
-            self.passed_tests += test_html
-
-
-def verify_output(report, filepath):
-    old_img, ref_img, new_img, diff_img = test_get_images(filepath)
-
-    # copy new image
-    if os.path.exists(new_img):
-        os.remove(new_img)
-    if os.path.exists(TEMP_FILE):
-        shutil.copy(TEMP_FILE, new_img)
-
-    update = os.getenv('CYCLESTEST_UPDATE')
-
-    if os.path.exists(ref_img):
-        # diff test with threshold
-        command = (
-            IDIFF,
-            "-fail", "0.016",
-            "-failpercent", "1",
-            ref_img,
-            TEMP_FILE,
-            )
-        try:
-            subprocess.check_output(command)
-            failed = False
-        except subprocess.CalledProcess

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list