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..978a126241fb3b119f9b18284bc114644e7d3253 |
| --- /dev/null |
| +++ b/tools/tests/skimage/self_test.py |
| @@ -0,0 +1,60 @@ |
| +#!/usr/bin/env python |
|
scroggo
2013/05/09 15:50:43
I noticed that gm's self test has a note that it s
epoger
2013/05/09 16:35:50
Yes, good idea to do it that way in the first plac
|
| +# 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 |
| + |
| +# Use the directory of this file as the out directory |
|
epoger
2013/05/09 16:35:50
I think it would be better to write test files int
scroggo
2013/05/09 19:05:59
Done.
|
| +out_dir = os.path.dirname(__file__) |
| +out_dir = os.path.abspath(out_dir) |
| + |
| +# Move up to trunk |
| +old_working_dir = os.getcwd() |
| +os.chdir(out_dir) |
| +os.chdir('../../../') |
| + |
| +# Find the binary |
| +skimage_binary = None |
| +xcode_path = "xcodebuild/Debug/skimage" |
| +gcc_path = "out/Debug/skimage" |
|
scroggo
2013/05/09 15:50:43
It looks like gm's self test assumes you have alre
epoger
2013/05/09 16:35:50
Yeah, it's a tough call, because individual develo
|
| + |
| +if (os.path.exists(gcc_path)): |
|
epoger
2013/05/09 16:35:50
Good idea to go looking for the binary in differen
scroggo
2013/05/09 19:05:59
I have added a function to find the binary. I also
|
| + skimage_binary = gcc_path |
| +elif (os.path.exists(xcode_path)): |
| + skimage_binary = xcode_path |
| + |
| +resultsFile = None |
| + |
| +if (skimage_binary != None): |
| + try: |
| + # 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] |
| + cmd_line.extend(["-r", "resources/CMYK.jpg", "resources/plane.png"]) |
|
epoger
2013/05/09 16:35:50
Alternatively, you could assemble these paths as a
scroggo
2013/05/09 19:05:59
Done.
|
| + # Create the expectations file |
| + create_expectations_cmd = cmd_line + ["--createExpectationsPath", out_dir] |
| + subprocess.check_call(create_expectations_cmd) |
|
scroggo
2013/05/09 15:57:29
There are some commands for calling programs more
epoger
2013/05/09 16:35:50
Unfortunately, no. Most developers will have chec
scroggo
2013/05/09 19:05:59
That sounds reasonable to me. Probably outside of
epoger
2013/05/09 19:19:39
Definitely outside the scope of this CL. Please c
|
| + # Now read from the expectations file |
| + resultsFile = os.path.join(out_dir, "results.json") |
| + check_expectations_cmd = cmd_line + ["--readExpectationsPath", resultsFile] |
|
epoger
2013/05/09 16:35:50
Great! This is definitely a good start... but, if
scroggo
2013/05/09 19:05:59
Definitely the long term plan is to compare agains
epoger
2013/05/09 19:19:39
To some extent, we may be able to have expectation
|
| + subprocess.check_call(check_expectations_cmd) |
| + print "Self tests succeeded!" |
| + except subprocess.CalledProcessError as e: |
| + print skimage_binary + " failed with error code " + str(e.returncode) |
| + print "Self tests failed!" |
|
epoger
2013/05/09 16:35:50
It would be better if the process exited with a no
scroggo
2013/05/09 19:05:59
Done.
|
| +else: |
| + print "Could not find skimage binary!" |
| + print "Did you forget to build tools project?" |
| + print "Self tests failed" |
| + |
| +# Delete the results file, which is no longer needed. |
| +if (resultsFile != None and os.path.exists(resultsFile)): |
| + os.remove(resultsFile) |
| + |
| +# Return to the original working directory. |
| +os.chdir(old_working_dir) |