OLD | NEW |
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 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 "incorrect-results.json") | 62 "incorrect-results.json") |
63 args = [skimage_binary, "--readPath", invalid_file, | 63 args = [skimage_binary, "--readPath", invalid_file, |
64 "--readExpectationsPath", incorrect_expectations] | 64 "--readExpectationsPath", incorrect_expectations] |
65 result = subprocess.call(args) | 65 result = subprocess.call(args) |
66 if 0 == result: | 66 if 0 == result: |
67 print "'%s' should have reported failure!" % " ".join(args) | 67 print "'%s' should have reported failure!" % " ".join(args) |
68 exit(1) | 68 exit(1) |
69 | 69 |
70 # Empty expectations: | 70 # Empty expectations: |
71 empty_expectations = os.path.join(expectations_dir, "empty-results.json") | 71 empty_expectations = os.path.join(expectations_dir, "empty-results.json") |
72 subprocess.check_call([skimage_binary, "--readPath", invalid_file, | 72 output = subprocess.check_output([skimage_binary, "--readPath", invalid_file
, |
73 "--readExpectationsPath", empty_expectations]) | 73 "--readExpectationsPath", |
| 74 empty_expectations], |
| 75 stderr=subprocess.STDOUT) |
| 76 if not "Missing" in output: |
| 77 # Another test (in main()) tests to ensure that "Missing" does not appear |
| 78 # in the output. That test could be passed if the output changed so |
| 79 # "Missing" never appears. This ensures that an error is not missed if |
| 80 # that happens. |
| 81 print "skimage output changed! This may cause other self tests to fail!" |
| 82 exit(1) |
74 | 83 |
75 # Ignore failure: | 84 # Ignore failure: |
76 ignore_expectations = os.path.join(expectations_dir, "ignore-results.json") | 85 ignore_expectations = os.path.join(expectations_dir, "ignore-results.json") |
77 subprocess.check_call([skimage_binary, "--readPath", invalid_file, | 86 output = subprocess.check_output([skimage_binary, "--readPath", invalid_file
, |
78 "--readExpectationsPath", ignore_expectations]) | 87 "--readExpectationsPath", |
| 88 ignore_expectations], |
| 89 stderr=subprocess.STDOUT) |
| 90 if not "failures" in output: |
| 91 # Another test (in main()) tests to ensure that "failures" does not |
| 92 # appear in the output. That test could be passed if the output changed |
| 93 # so "failures" never appears. This ensures that an error is not missed |
| 94 # if that happens. |
| 95 print "skimage output changed! This may cause other self tests to fail!" |
| 96 exit(1) |
79 | 97 |
80 def test_incorrect_expectations(file_dir, skimage_binary): | 98 def test_incorrect_expectations(file_dir, skimage_binary): |
81 """ Test that comparing to incorrect expectations fails, unless | 99 """ Test that comparing to incorrect expectations fails, unless |
82 ignore-failures is set to true. """ | 100 ignore-failures is set to true. """ |
83 valid_file = os.path.join(file_dir, "skimage", "input", | 101 valid_file = os.path.join(file_dir, "skimage", "input", |
84 "images-with-known-hashes", | 102 "images-with-known-hashes", |
85 "1209453360120438698.png") | 103 "1209453360120438698.png") |
86 expectations_dir = os.path.join(file_dir, "skimage", "input", | 104 expectations_dir = os.path.join(file_dir, "skimage", "input", |
87 "images-with-known-hashes") | 105 "images-with-known-hashes") |
88 | 106 |
(...skipping 29 matching lines...) Expand all Loading... |
118 "--createExpectationsPath", expectations_path]) | 136 "--createExpectationsPath", expectations_path]) |
119 | 137 |
120 # Make sure the expectations file was generated correctly. | 138 # Make sure the expectations file was generated correctly. |
121 golden_expectations = os.path.join(file_dir, "skimage", "output-expected", | 139 golden_expectations = os.path.join(file_dir, "skimage", "output-expected", |
122 "create-expectations", | 140 "create-expectations", |
123 "expectations.json") | 141 "expectations.json") |
124 DieIfFilesMismatch(expected=golden_expectations, actual=expectations_path) | 142 DieIfFilesMismatch(expected=golden_expectations, actual=expectations_path) |
125 | 143 |
126 # Tell skimage to read back the expectations file it just wrote, and | 144 # Tell skimage to read back the expectations file it just wrote, and |
127 # confirm that the images in images_dir match it. | 145 # confirm that the images in images_dir match it. |
128 subprocess.check_call([skimage_binary, "--readPath", images_dir, | 146 output = subprocess.check_output([skimage_binary, "--readPath", images_dir, |
129 "--readExpectationsPath", expectations_path]) | 147 "--readExpectationsPath", |
| 148 expectations_path], |
| 149 stderr=subprocess.STDOUT) |
| 150 |
| 151 # Although skimage succeeded, it would have reported success if the file |
| 152 # was missing from the expectations file. Consider this a failure, since |
| 153 # the expectations file was created from this same image. (It will print |
| 154 # "Missing" in this case before listing the missing expectations). |
| 155 if "Missing" in output: |
| 156 print "Expectations file was missing expectations!" |
| 157 print output |
| 158 exit(1) |
| 159 |
| 160 # Again, skimage would succeed if there were known failures (and print |
| 161 # "failures"), but there should be no failures, since the file just |
| 162 # created did not include failures to ignore. |
| 163 if "failures" in output: |
| 164 print "Image failed!" |
| 165 print output |
| 166 exit(1) |
| 167 |
130 | 168 |
131 test_incorrect_expectations(file_dir=file_dir, | 169 test_incorrect_expectations(file_dir=file_dir, |
132 skimage_binary=skimage_binary) | 170 skimage_binary=skimage_binary) |
133 | 171 |
134 # Generate an expectations file from an empty directory. | 172 # Generate an expectations file from an empty directory. |
135 empty_dir = tempfile.mkdtemp() | 173 empty_dir = tempfile.mkdtemp() |
136 expectations_path = os.path.join(file_dir, "skimage", "output-actual", | 174 expectations_path = os.path.join(file_dir, "skimage", "output-actual", |
137 "empty-dir", "expectations.json") | 175 "empty-dir", "expectations.json") |
138 subprocess.check_call([skimage_binary, "--readPath", empty_dir, | 176 subprocess.check_call([skimage_binary, "--readPath", empty_dir, |
139 "--createExpectationsPath", expectations_path]) | 177 "--createExpectationsPath", expectations_path]) |
(...skipping 11 matching lines...) Expand all Loading... |
151 "nonexistent-dir", "expectations.json") | 189 "nonexistent-dir", "expectations.json") |
152 DieIfFilesMismatch(expected=golden_expectations, actual=expectations_path) | 190 DieIfFilesMismatch(expected=golden_expectations, actual=expectations_path) |
153 | 191 |
154 test_invalid_file(file_dir=file_dir, skimage_binary=skimage_binary) | 192 test_invalid_file(file_dir=file_dir, skimage_binary=skimage_binary) |
155 | 193 |
156 # Done with all tests. | 194 # Done with all tests. |
157 print "Self tests succeeded!" | 195 print "Self tests succeeded!" |
158 | 196 |
159 if __name__ == "__main__": | 197 if __name__ == "__main__": |
160 main() | 198 main() |
OLD | NEW |