Chromium Code Reviews| Index: tools/tests/skimage_self_test.py |
| diff --git a/tools/tests/skimage_self_test.py b/tools/tests/skimage_self_test.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..42f744cfb291cac1a6f5e97cebc95a31ea14d6b4 |
| --- /dev/null |
| +++ b/tools/tests/skimage_self_test.py |
| @@ -0,0 +1,68 @@ |
| +#!/usr/bin/env python |
| +# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +# Self-test for skimage. |
| + |
| +import os |
| +import subprocess |
| +import sys |
| + |
| +# Find a path to the binary to use. Iterates through a list of possible |
| +# locations the binary may be. |
| +def PickBinaryPath(base_dir): |
| + POSSIBLE_BINARY_PATHS = [ |
| + 'out/Debug/skimage', |
| + 'out/Release/skimage', |
| + 'xcodebuild/Debug/skimage', |
| + 'xcodebuild/Release/skimage', |
| + ] |
| + for binary in POSSIBLE_BINARY_PATHS: |
| + binary_full_path = os.path.join(base_dir, binary) |
| + if (os.path.exists(binary_full_path)): |
| + return binary_full_path |
| + return None |
|
epoger
2013/05/09 19:19:39
This could raise an Exception, thus halting execut
scroggo
2013/05/13 15:43:26
Done.
|
| + |
| +def main(): |
| + # Use the directory of this file as the out directory |
| + file_dir = os.path.dirname(__file__) |
| + file_dir = os.path.abspath(file_dir) |
|
epoger
2013/05/09 19:19:39
how about just:
file_dir = os.path.abspath(os.pat
scroggo
2013/05/13 15:43:26
Done.
|
| + |
| + trunk_dir = os.path.normpath(os.path.join(file_dir, '../../')) |
| + |
| + # Find the binary |
| + skimage_binary = PickBinaryPath(trunk_dir) |
| + |
| + success = False; |
| + if (skimage_binary != None): |
| + try: |
| + print "Running " + skimage_binary |
| + # Run skimage twice, first to create an expectations file, and then |
| + # comparing to it. |
| + # Both commands will run the binary, reading from resources. |
| + cmd_line = [skimage_binary] |
| + resources_dir = os.path.join(trunk_dir, 'resources') |
| + cmd_line.extend(["-r", resources_dir]) |
| + # Create the expectations file |
| + results_dir = os.path.join(file_dir, "skimage") |
| + create_expectations_cmd = cmd_line + ["--createExpectationsPath", results_dir] |
| + subprocess.check_call(create_expectations_cmd) |
| + # Now read from the expectations file |
| + results_file = os.path.join(results_dir, "results.json") |
| + check_expectations_cmd = cmd_line + ["--readExpectationsPath", results_file] |
| + subprocess.check_call(check_expectations_cmd) |
| + success = True; |
| + except subprocess.CalledProcessError as e: |
|
epoger
2013/05/09 19:19:39
Do you need to catch CalledProcessError? What if
scroggo
2013/05/13 15:43:26
I do not. I caught the error to give a cleaner err
|
| + print skimage_binary + " failed with error code " + str(e.returncode) |
| + else: |
| + print "Could not find skimage binary!" |
| + print "Did you forget to build tools project?" |
| + |
| + if success: |
| + print "Self tests succeeded!" |
| + sys.exit(0) |
| + print "Self tests failed!" |
| + sys.exit(-1) |
| + |
| +main() |