Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: tools/tests/skimage_self_test.py

Issue 17101029: Treat empty directory properly in skimage. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Use README files to force directories to exist. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/tests/skimage/output-expected/nonexistent-dir/expectations.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # Self-test for skimage. 6 # Self-test for skimage.
7 7
8 import filecmp 8 import filecmp
9 import os 9 import os
10 import subprocess 10 import subprocess
11 import sys 11 import sys
12 import tempfile
12 13
13 class BinaryNotFoundException(Exception): 14 class BinaryNotFoundException(Exception):
14 def __str__ (self): 15 def __str__ (self):
15 return ("Could not find binary!\n" 16 return ("Could not find binary!\n"
16 "Did you forget to build the tools project?\n" 17 "Did you forget to build the tools project?\n"
17 "Self tests failed") 18 "Self tests failed")
18 19
19 # Find a path to the binary to use. Iterates through a list of possible 20 # Find a path to the binary to use. Iterates through a list of possible
20 # locations the binary may be. 21 # locations the binary may be.
21 def PickBinaryPath(base_dir): 22 def PickBinaryPath(base_dir):
(...skipping 22 matching lines...) Expand all
44 45
45 trunk_dir = os.path.normpath(os.path.join(file_dir, os.pardir, os.pardir)) 46 trunk_dir = os.path.normpath(os.path.join(file_dir, os.pardir, os.pardir))
46 47
47 # Find the binary 48 # Find the binary
48 skimage_binary = PickBinaryPath(trunk_dir) 49 skimage_binary = PickBinaryPath(trunk_dir)
49 print "Running " + skimage_binary 50 print "Running " + skimage_binary
50 51
51 # Generate an expectations file from known images. 52 # Generate an expectations file from known images.
52 images_dir = os.path.join(file_dir, "skimage", "input", 53 images_dir = os.path.join(file_dir, "skimage", "input",
53 "images-with-known-hashes") 54 "images-with-known-hashes")
54 expectations_path = os.path.join(file_dir, "skimage", "output-actual", 55 expectations_path = os.path.join(file_dir, "skimage", "output-actual",
scroggo 2013/06/19 20:34:16 Patch set 4 reverts the changes in patch set 3. I
55 "create-expectations", "expectations.json") 56 "create-expectations", "expectations.json")
56 subprocess.check_call([skimage_binary, "--readPath", images_dir, 57 subprocess.check_call([skimage_binary, "--readPath", images_dir,
57 "--createExpectationsPath", expectations_path]) 58 "--createExpectationsPath", expectations_path])
58 59
59 # Make sure the expectations file was generated correctly. 60 # Make sure the expectations file was generated correctly.
60 golden_expectations = os.path.join(file_dir, "skimage", "output-expected", 61 golden_expectations = os.path.join(file_dir, "skimage", "output-expected",
61 "create-expectations", 62 "create-expectations",
62 "expectations.json") 63 "expectations.json")
63 DieIfFilesMismatch(expected=golden_expectations, actual=expectations_path) 64 DieIfFilesMismatch(expected=golden_expectations, actual=expectations_path)
64 65
65 # Tell skimage to read back the expectations file it just wrote, and 66 # Tell skimage to read back the expectations file it just wrote, and
66 # confirm that the images in images_dir match it. 67 # confirm that the images in images_dir match it.
67 subprocess.check_call([skimage_binary, "--readPath", images_dir, 68 subprocess.check_call([skimage_binary, "--readPath", images_dir,
68 "--readExpectationsPath", expectations_path]) 69 "--readExpectationsPath", expectations_path])
69 70
70 # TODO(scroggo): Add a test that compares expectations and image files that 71 # TODO(scroggo): Add a test that compares expectations and image files that
71 # are known to NOT match, and make sure it returns an error. 72 # are known to NOT match, and make sure it returns an error.
72 73
74 # Generate an expectations file from an empty directory.
75 empty_dir = tempfile.mkdtemp()
76 expectations_path = os.path.join(file_dir, "skimage", "output-actual",
77 "empty-dir", "expectations.json")
78 subprocess.check_call([skimage_binary, "--readPath", empty_dir,
79 "--createExpectationsPath", expectations_path])
80 golden_expectations = os.path.join(file_dir, "skimage", "output-expected",
81 "empty-dir", "expectations.json")
82 DieIfFilesMismatch(expected=golden_expectations, actual=expectations_path)
83 os.rmdir(empty_dir)
84
85 # Generate an expectations file from a nonexistent directory.
86 expectations_path = os.path.join(file_dir, "skimage", "output-actual",
87 "nonexistent-dir", "expectations.json")
88 subprocess.check_call([skimage_binary, "--readPath", "/nonexistent/dir",
89 "--createExpectationsPath", expectations_path])
90 golden_expectations = os.path.join(file_dir, "skimage", "output-expected",
91 "nonexistent-dir", "expectations.json")
92 DieIfFilesMismatch(expected=golden_expectations, actual=expectations_path)
93
73 # Done with all tests. 94 # Done with all tests.
74 print "Self tests succeeded!" 95 print "Self tests succeeded!"
75 96
76 if __name__ == "__main__": 97 if __name__ == "__main__":
77 main() 98 main()
OLDNEW
« no previous file with comments | « tools/tests/skimage/output-expected/nonexistent-dir/expectations.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698