OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 # Self-test for skimage. | |
7 | |
8 import os | |
9 import subprocess | |
10 import sys | |
11 | |
12 # Find a path to the binary to use. Iterates through a list of possible | |
13 # locations the binary may be. | |
14 def PickBinaryPath(base_dir): | |
15 POSSIBLE_BINARY_PATHS = [ | |
16 'out/Debug/skimage', | |
17 'out/Release/skimage', | |
18 'xcodebuild/Debug/skimage', | |
19 'xcodebuild/Release/skimage', | |
20 ] | |
21 for binary in POSSIBLE_BINARY_PATHS: | |
22 binary_full_path = os.path.join(base_dir, binary) | |
23 if (os.path.exists(binary_full_path)): | |
24 return binary_full_path | |
25 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.
| |
26 | |
27 def main(): | |
28 # Use the directory of this file as the out directory | |
29 file_dir = os.path.dirname(__file__) | |
30 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.
| |
31 | |
32 trunk_dir = os.path.normpath(os.path.join(file_dir, '../../')) | |
33 | |
34 # Find the binary | |
35 skimage_binary = PickBinaryPath(trunk_dir) | |
36 | |
37 success = False; | |
38 if (skimage_binary != None): | |
39 try: | |
40 print "Running " + skimage_binary | |
41 # Run skimage twice, first to create an expectations file, and then | |
42 # comparing to it. | |
43 # Both commands will run the binary, reading from resources. | |
44 cmd_line = [skimage_binary] | |
45 resources_dir = os.path.join(trunk_dir, 'resources') | |
46 cmd_line.extend(["-r", resources_dir]) | |
47 # Create the expectations file | |
48 results_dir = os.path.join(file_dir, "skimage") | |
49 create_expectations_cmd = cmd_line + ["--createExpectationsPath", re sults_dir] | |
50 subprocess.check_call(create_expectations_cmd) | |
51 # Now read from the expectations file | |
52 results_file = os.path.join(results_dir, "results.json") | |
53 check_expectations_cmd = cmd_line + ["--readExpectationsPath", resul ts_file] | |
54 subprocess.check_call(check_expectations_cmd) | |
55 success = True; | |
56 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
| |
57 print skimage_binary + " failed with error code " + str(e.returncode ) | |
58 else: | |
59 print "Could not find skimage binary!" | |
60 print "Did you forget to build tools project?" | |
61 | |
62 if success: | |
63 print "Self tests succeeded!" | |
64 sys.exit(0) | |
65 print "Self tests failed!" | |
66 sys.exit(-1) | |
67 | |
68 main() | |
OLD | NEW |