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 | |
14 import sys | 13 import sys |
15 import tempfile | 14 import tempfile |
16 import unittest | 15 import unittest |
17 | 16 |
18 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 17 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
19 sys.path.insert(0, ROOT_DIR) | 18 sys.path.insert(0, ROOT_DIR) |
20 sys.path.insert(0, os.path.join(ROOT_DIR, 'third_party')) | 19 sys.path.insert(0, os.path.join(ROOT_DIR, 'third_party')) |
21 | 20 |
22 import isolated_format | 21 import isolated_format |
23 import isolateserver | 22 import isolateserver |
24 import run_isolated | 23 import run_isolated |
25 from depot_tools import auto_stub | 24 from depot_tools import auto_stub |
| 25 from depot_tools import fix_encoding |
26 from utils import file_path | 26 from utils import file_path |
27 from utils import logging_utils | 27 from utils import logging_utils |
28 from utils import on_error | 28 from utils import on_error |
29 from utils import subprocess42 | 29 from utils import subprocess42 |
30 from utils import tools | 30 from utils import tools |
31 | 31 |
32 import isolateserver_mock | 32 import isolateserver_mock |
33 | 33 |
34 | 34 |
35 def write_content(filepath, content): | 35 def write_content(filepath, content): |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 self.mock( | 75 self.mock( |
76 logging_utils.OptionParserWithLogging, 'logger_root', | 76 logging_utils.OptionParserWithLogging, 'logger_root', |
77 logging.Logger('unittest')) | 77 logging.Logger('unittest')) |
78 | 78 |
79 def tearDown(self): | 79 def tearDown(self): |
80 for dirpath, dirnames, filenames in os.walk(self.tempdir, topdown=True): | 80 for dirpath, dirnames, filenames in os.walk(self.tempdir, topdown=True): |
81 for filename in filenames: | 81 for filename in filenames: |
82 file_path.set_read_only(os.path.join(dirpath, filename), False) | 82 file_path.set_read_only(os.path.join(dirpath, filename), False) |
83 for dirname in dirnames: | 83 for dirname in dirnames: |
84 file_path.set_read_only(os.path.join(dirpath, dirname), False) | 84 file_path.set_read_only(os.path.join(dirpath, dirname), False) |
85 shutil.rmtree(self.tempdir) | 85 file_path.rmtree(self.tempdir) |
86 super(RunIsolatedTestBase, self).tearDown() | 86 super(RunIsolatedTestBase, self).tearDown() |
87 | 87 |
88 @property | 88 @property |
89 def run_test_temp_dir(self): | 89 def run_test_temp_dir(self): |
90 """Where to map all files in run_isolated.run_tha_test.""" | 90 """Where to map all files in run_isolated.run_tha_test.""" |
91 return os.path.join(self.tempdir, 'isolated_run') | 91 return os.path.join(self.tempdir, 'isolated_run') |
92 | 92 |
93 def fake_make_temp_dir(self, prefix, _root_dir=None): | 93 def fake_make_temp_dir(self, prefix, _root_dir=None): |
94 """Predictably returns directory for run_tha_test (one per test case).""" | 94 """Predictably returns directory for run_tha_test (one per test case).""" |
95 self.assertIn(prefix, ('isolated_out', 'isolated_run', 'isolated_tmp')) | 95 self.assertIn(prefix, ('isolated_out', 'isolated_run', 'isolated_tmp')) |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 u'isolated': u'e0a0fffa0910dd09e7ef4c89496116f60317e6c4', | 470 u'isolated': u'e0a0fffa0910dd09e7ef4c89496116f60317e6c4', |
471 u'isolatedserver': u'http://localhost:1', | 471 u'isolatedserver': u'http://localhost:1', |
472 u'namespace': u'default-gzip', | 472 u'namespace': u'default-gzip', |
473 }, | 473 }, |
474 u'version': 2, | 474 u'version': 2, |
475 } | 475 } |
476 self.assertEqual(expected, tools.read_json(out)) | 476 self.assertEqual(expected, tools.read_json(out)) |
477 | 477 |
478 | 478 |
479 if __name__ == '__main__': | 479 if __name__ == '__main__': |
| 480 fix_encoding.fix_encoding() |
480 logging.basicConfig( | 481 logging.basicConfig( |
481 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) | 482 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) |
482 unittest.main() | 483 unittest.main() |
OLD | NEW |