| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import collections | 5 import collections |
| 6 import os | 6 import os |
| 7 import sys | 7 import sys |
| 8 import unittest | 8 import unittest |
| 9 | 9 |
| 10 PERF_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 10 PERF_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 pass | 52 pass |
| 53 | 53 |
| 54 | 54 |
| 55 PRESUBMIT.LoadSupport(InputAPIStub([])) # do this to support monkey patching | 55 PRESUBMIT.LoadSupport(InputAPIStub([])) # do this to support monkey patching |
| 56 | 56 |
| 57 class PresubmitTest(unittest.TestCase): | 57 class PresubmitTest(unittest.TestCase): |
| 58 def setUp(self): | 58 def setUp(self): |
| 59 success_file_hash = 'da39a3ee5e6b4b0d3255bfef95601890afd80709' | 59 success_file_hash = 'da39a3ee5e6b4b0d3255bfef95601890afd80709' |
| 60 | 60 |
| 61 self._stubs = system_stub.Override( | 61 self._stubs = system_stub.Override( |
| 62 PRESUBMIT, ['cloud_storage', 'open', 'os']) | 62 PRESUBMIT, ['cloud_storage', 'open', 'os', 'raw_input']) |
| 63 self._stubs.raw_input.input = 'public' |
| 63 # Files in Cloud Storage. | 64 # Files in Cloud Storage. |
| 64 self._stubs.cloud_storage.remote_paths = [ | 65 self._stubs.cloud_storage.remote_paths = [ |
| 65 'skip'.zfill(40), | 66 'skip'.zfill(40), |
| 66 ] | 67 ] |
| 67 # Local data files and their hashes. | 68 # Local data files and their hashes. |
| 68 self._stubs.cloud_storage.local_file_hashes = { | 69 self._stubs.cloud_storage.local_file_hashes = { |
| 69 '/path/to/skip.wpr': 'skip'.zfill(40), | 70 '/path/to/skip.wpr': 'skip'.zfill(40), |
| 70 '/path/to/success.wpr': success_file_hash, | 71 '/path/to/success.wpr': success_file_hash, |
| 71 '/path/to/wrong_hash.wpr': success_file_hash, | 72 '/path/to/wrong_hash.wpr': success_file_hash, |
| 72 } | 73 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 self.assertResultCount(results, 1, 0) | 116 self.assertResultCount(results, 1, 0) |
| 116 self.assertTrue('valid SHA-1 hash' in str(results[0]), msg=results[0]) | 117 self.assertTrue('valid SHA-1 hash' in str(results[0]), msg=results[0]) |
| 117 | 118 |
| 118 def testMissingFile(self): | 119 def testMissingFile(self): |
| 119 results = self._CheckUpload(['/path/to/missing.wpr.sha1']) | 120 results = self._CheckUpload(['/path/to/missing.wpr.sha1']) |
| 120 self.assertResultCount(results, 1, 0) | 121 self.assertResultCount(results, 1, 0) |
| 121 self.assertTrue('not found' in str(results[0]), msg=results[0]) | 122 self.assertTrue('not found' in str(results[0]), msg=results[0]) |
| 122 | 123 |
| 123 def testSkip(self): | 124 def testSkip(self): |
| 124 results = self._CheckUpload(['/path/to/skip.wpr.sha1']) | 125 results = self._CheckUpload(['/path/to/skip.wpr.sha1']) |
| 125 self.assertResultCount(results, 0, 1) | 126 self.assertResultCount(results, 0, 0) |
| 126 self.assertTrue('skipping' in str(results[0]), msg=results[0]) | |
| 127 | 127 |
| 128 def testSuccess(self): | 128 def testSuccess(self): |
| 129 results = self._CheckUpload(['/path/to/success.wpr.sha1']) | 129 results = self._CheckUpload(['/path/to/success.wpr.sha1']) |
| 130 self.assertResultCount(results, 0, 1) | 130 self.assertResultCount(results, 0, 1) |
| 131 self.assertTrue('Uploaded' in str(results[0]), msg=results[0]) | 131 self.assertTrue('Uploaded' in str(results[0]), msg=results[0]) |
| 132 | 132 |
| 133 def testWrongHash(self): | 133 def testWrongHash(self): |
| 134 results = self._CheckUpload(['/path/to/wrong_hash.wpr.sha1']) | 134 results = self._CheckUpload(['/path/to/wrong_hash.wpr.sha1']) |
| 135 self.assertTrue('does not match' in str(results[0]), msg=results[0]) | 135 self.assertTrue('does not match' in str(results[0]), msg=results[0]) |
| 136 | 136 |
| 137 | 137 |
| 138 if __name__ == '__main__': | 138 if __name__ == '__main__': |
| 139 unittest.main() | 139 unittest.main() |
| OLD | NEW |