aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/tests/skimage_self_test.py
diff options
context:
space:
mode:
authorGravatar epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-13 19:12:05 +0000
committerGravatar epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-06-13 19:12:05 +0000
commit74feb1593a63932c086b1647fa75e91bb209ce60 (patch)
treee09a7a7f36245f3e13e5c088b7909fe7bf6d62f1 /tools/tests/skimage_self_test.py
parent21c10c5ff50cb8f2fd995fc9396d435d3396258b (diff)
skimage self-tests: confirm correctness of bitmap hash values
R=scroggo@google.com Review URL: https://codereview.chromium.org/16866010 git-svn-id: http://skia.googlecode.com/svn/trunk@9591 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools/tests/skimage_self_test.py')
-rwxr-xr-xtools/tests/skimage_self_test.py43
1 files changed, 28 insertions, 15 deletions
diff --git a/tools/tests/skimage_self_test.py b/tools/tests/skimage_self_test.py
index d2d072ff41..cb66fe1729 100755
--- a/tools/tests/skimage_self_test.py
+++ b/tools/tests/skimage_self_test.py
@@ -5,6 +5,7 @@
# Self-test for skimage.
+import filecmp
import os
import subprocess
import sys
@@ -30,6 +31,13 @@ def PickBinaryPath(base_dir):
return binary_full_path
raise BinaryNotFoundException
+# Quit early if two files have different content.
+def DieIfFilesMismatch(expected, actual):
+ if not filecmp.cmp(expected, actual):
+ print 'Error: file mismatch! expected=%s , actual=%s' % (
+ expected, actual)
+ exit(1)
+
def main():
# Use the directory of this file as the out directory
file_dir = os.path.abspath(os.path.dirname(__file__))
@@ -40,24 +48,29 @@ def main():
skimage_binary = PickBinaryPath(trunk_dir)
print "Running " + skimage_binary
- # Run skimage twice, first to create an expectations file, and then
- # comparing to it.
+ # Generate an expectations file from known images.
+ images_dir = os.path.join(file_dir, "skimage", "input",
+ "images-with-known-hashes")
+ expectations_path = os.path.join(file_dir, "skimage", "output-actual",
+ "create-expectations", "expectations.json")
+ subprocess.check_call([skimage_binary, "--readPath", images_dir,
+ "--createExpectationsPath", expectations_path])
+
+ # Make sure the expectations file was generated correctly.
+ golden_expectations = os.path.join(file_dir, "skimage", "output-expected",
+ "create-expectations",
+ "expectations.json")
+ DieIfFilesMismatch(expected=golden_expectations, actual=expectations_path)
- # 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])
+ # Tell skimage to read back the expectations file it just wrote, and
+ # confirm that the images in images_dir match it.
+ subprocess.check_call([skimage_binary, "--readPath", images_dir,
+ "--readExpectationsPath", expectations_path])
- # Create the expectations file
- results_file = os.path.join(file_dir, "skimage", "self_test_results.json")
- create_expectations_cmd = cmd_line + ["--createExpectationsPath",
- results_file]
- subprocess.check_call(create_expectations_cmd)
+ # TODO(scroggo): Add a test that compares expectations and image files that
+ # are known to NOT match, and make sure it returns an error.
- # Now read from the expectations file
- check_expectations_cmd = cmd_line + ["--readExpectationsPath",
- results_file]
- subprocess.check_call(check_expectations_cmd)
+ # Done with all tests.
print "Self tests succeeded!"
if __name__ == "__main__":