OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Swarming Authors. All rights reserved. | 2 # Copyright 2013 The Swarming Authors. All rights reserved. |
3 # Use of this source code is governed under the Apache License, Version 2.0 that | 3 # Use of this source code is governed under the Apache License, Version 2.0 that |
4 # can be found in the LICENSE file. | 4 # can be found in the LICENSE file. |
5 | 5 |
6 # pylint: disable=R0201 | 6 # pylint: disable=R0201 |
7 | 7 |
8 import StringIO | 8 import StringIO |
9 import functools | 9 import functools |
10 import json | 10 import json |
11 import logging | 11 import logging |
12 import os | 12 import os |
13 import shutil | 13 import shutil |
14 import sys | 14 import sys |
15 import tempfile | 15 import tempfile |
16 import unittest | 16 import unittest |
17 | 17 |
18 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 18 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
19 sys.path.insert(0, ROOT_DIR) | 19 sys.path.insert(0, ROOT_DIR) |
20 sys.path.insert(0, os.path.join(ROOT_DIR, 'third_party')) | 20 sys.path.insert(0, os.path.join(ROOT_DIR, 'third_party')) |
21 | 21 |
22 import isolated_format | 22 import isolated_format |
23 import isolateserver | 23 import isolateserver |
24 import run_isolated | 24 import run_isolated |
25 from depot_tools import auto_stub | 25 from depot_tools import auto_stub |
26 from utils import file_path | 26 from utils import file_path |
| 27 from utils import logging_utils |
27 from utils import on_error | 28 from utils import on_error |
28 from utils import subprocess42 | 29 from utils import subprocess42 |
29 from utils import tools | 30 from utils import tools |
30 | 31 |
31 import isolateserver_mock | 32 import isolateserver_mock |
32 | 33 |
33 | 34 |
34 def write_content(filepath, content): | 35 def write_content(filepath, content): |
35 with open(filepath, 'wb') as f: | 36 with open(filepath, 'wb') as f: |
36 f.write(content) | 37 f.write(content) |
(...skipping 22 matching lines...) Expand all Loading... |
59 channel.send_result(digest) | 60 channel.send_result(digest) |
60 | 61 |
61 | 62 |
62 class RunIsolatedTestBase(auto_stub.TestCase): | 63 class RunIsolatedTestBase(auto_stub.TestCase): |
63 def setUp(self): | 64 def setUp(self): |
64 super(RunIsolatedTestBase, self).setUp() | 65 super(RunIsolatedTestBase, self).setUp() |
65 self.tempdir = tempfile.mkdtemp(prefix=u'run_isolated_test') | 66 self.tempdir = tempfile.mkdtemp(prefix=u'run_isolated_test') |
66 logging.debug(self.tempdir) | 67 logging.debug(self.tempdir) |
67 self.mock(run_isolated, 'make_temp_dir', self.fake_make_temp_dir) | 68 self.mock(run_isolated, 'make_temp_dir', self.fake_make_temp_dir) |
68 self.mock(run_isolated.auth, 'ensure_logged_in', lambda _: None) | 69 self.mock(run_isolated.auth, 'ensure_logged_in', lambda _: None) |
| 70 self.mock( |
| 71 logging_utils.OptionParserWithLogging, 'logger_root', |
| 72 logging.Logger('unittest')) |
69 | 73 |
70 def tearDown(self): | 74 def tearDown(self): |
71 for dirpath, dirnames, filenames in os.walk(self.tempdir, topdown=True): | 75 for dirpath, dirnames, filenames in os.walk(self.tempdir, topdown=True): |
72 for filename in filenames: | 76 for filename in filenames: |
73 file_path.set_read_only(os.path.join(dirpath, filename), False) | 77 file_path.set_read_only(os.path.join(dirpath, filename), False) |
74 for dirname in dirnames: | 78 for dirname in dirnames: |
75 file_path.set_read_only(os.path.join(dirpath, dirname), False) | 79 file_path.set_read_only(os.path.join(dirpath, dirname), False) |
76 shutil.rmtree(self.tempdir) | 80 shutil.rmtree(self.tempdir) |
77 super(RunIsolatedTestBase, self).tearDown() | 81 super(RunIsolatedTestBase, self).tearDown() |
78 | 82 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 ]) + '\n' | 381 ]) + '\n' |
378 self.assertEqual(expected, sys.stdout.getvalue()) | 382 self.assertEqual(expected, sys.stdout.getvalue()) |
379 finally: | 383 finally: |
380 server.close() | 384 server.close() |
381 | 385 |
382 | 386 |
383 if __name__ == '__main__': | 387 if __name__ == '__main__': |
384 logging.basicConfig( | 388 logging.basicConfig( |
385 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) | 389 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) |
386 unittest.main() | 390 unittest.main() |
OLD | NEW |