| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 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 import binascii | 6 import binascii |
| 7 import hashlib | 7 import hashlib |
| 8 import json | 8 import json |
| 9 import logging | 9 import logging |
| 10 import os | 10 import os |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 self.assertTrue(all(x[2] == fake_upload_urls for x in result)) | 107 self.assertTrue(all(x[2] == fake_upload_urls for x in result)) |
| 108 # 'get_missing_files' doesn't guarantee order of its results, so convert | 108 # 'get_missing_files' doesn't guarantee order of its results, so convert |
| 109 # it to unordered dict and compare dicts. | 109 # it to unordered dict and compare dicts. |
| 110 self.assertEqual(dict(x[:2] for x in result), missing) | 110 self.assertEqual(dict(x[:2] for x in result), missing) |
| 111 | 111 |
| 112 | 112 |
| 113 class IsolateServerArchiveTest(TestCase): | 113 class IsolateServerArchiveTest(TestCase): |
| 114 def setUp(self): | 114 def setUp(self): |
| 115 super(IsolateServerArchiveTest, self).setUp() | 115 super(IsolateServerArchiveTest, self).setUp() |
| 116 self.mock(isolateserver, 'randomness', lambda: 'not_really_random') | 116 self.mock(isolateserver, 'randomness', lambda: 'not_really_random') |
| 117 self.mock(isolateserver, 'ENABLE_GS_ISOLATE_API', False) |
| 117 self.mock(sys, 'stdout', StringIO.StringIO()) | 118 self.mock(sys, 'stdout', StringIO.StringIO()) |
| 118 | 119 |
| 119 def test_present(self): | 120 def test_present(self): |
| 120 files = [ | 121 files = [ |
| 121 os.path.join(BASE_PATH, 'isolateserver', f) | 122 os.path.join(BASE_PATH, 'isolateserver', f) |
| 122 for f in ('small_file.txt', 'empty_file.txt') | 123 for f in ('small_file.txt', 'empty_file.txt') |
| 123 ] | 124 ] |
| 124 hash_encoded = ''.join( | 125 hash_encoded = ''.join( |
| 125 binascii.unhexlify(isolateserver.hash_file(f, ALGO)) for f in files) | 126 binascii.unhexlify(isolateserver.hash_file(f, ALGO)) for f in files) |
| 126 path = 'http://random/' | 127 path = 'http://random/' |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 ), | 292 ), |
| 292 ] | 293 ] |
| 293 # |size| is currently ignored. | 294 # |size| is currently ignored. |
| 294 result = isolateserver.IsolateServer(path, 'x').push(s, -2, [content]) | 295 result = isolateserver.IsolateServer(path, 'x').push(s, -2, [content]) |
| 295 self.assertEqual('ok42', result) | 296 self.assertEqual('ok42', result) |
| 296 | 297 |
| 297 | 298 |
| 298 class IsolateServerDownloadTest(TestCase): | 299 class IsolateServerDownloadTest(TestCase): |
| 299 tempdir = None | 300 tempdir = None |
| 300 | 301 |
| 302 def setUp(self): |
| 303 super(IsolateServerDownloadTest, self).setUp() |
| 304 self.mock(isolateserver, 'ENABLE_GS_ISOLATE_API', False) |
| 305 |
| 301 def tearDown(self): | 306 def tearDown(self): |
| 302 try: | 307 try: |
| 303 if self.tempdir: | 308 if self.tempdir: |
| 304 shutil.rmtree(self.tempdir) | 309 shutil.rmtree(self.tempdir) |
| 305 finally: | 310 finally: |
| 306 super(IsolateServerDownloadTest, self).tearDown() | 311 super(IsolateServerDownloadTest, self).tearDown() |
| 307 | 312 |
| 308 def test_download_two_files(self): | 313 def test_download_two_files(self): |
| 309 # Test downloading two files. | 314 # Test downloading two files. |
| 310 actual = {} | 315 actual = {} |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 expected = gen_data(os.path.sep) | 474 expected = gen_data(os.path.sep) |
| 470 self.assertEqual(expected, actual) | 475 self.assertEqual(expected, actual) |
| 471 | 476 |
| 472 | 477 |
| 473 if __name__ == '__main__': | 478 if __name__ == '__main__': |
| 474 if '-v' in sys.argv: | 479 if '-v' in sys.argv: |
| 475 unittest.TestCase.maxDiff = None | 480 unittest.TestCase.maxDiff = None |
| 476 logging.basicConfig( | 481 logging.basicConfig( |
| 477 level=(logging.DEBUG if '-v' in sys.argv else logging.ERROR)) | 482 level=(logging.DEBUG if '-v' in sys.argv else logging.ERROR)) |
| 478 unittest.main() | 483 unittest.main() |
| OLD | NEW |