| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # coding=utf-8 | 2 # coding=utf-8 |
| 3 # Copyright 2013 The LUCI Authors. All rights reserved. | 3 # Copyright 2013 The LUCI Authors. All rights reserved. |
| 4 # Use of this source code is governed under the Apache License, Version 2.0 | 4 # Use of this source code is governed under the Apache License, Version 2.0 |
| 5 # that can be found in the LICENSE file. | 5 # that can be found in the LICENSE file. |
| 6 | 6 |
| 7 import base64 | 7 import base64 |
| 8 import json | 8 import json |
| 9 import logging | 9 import logging |
| 10 import os | 10 import os |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 u'namespace': u'default-gzip', | 356 u'namespace': u'default-gzip', |
| 357 }) | 357 }) |
| 358 task_details = self.get_task_details(isolated={ | 358 task_details = self.get_task_details(isolated={ |
| 359 'input': '123', | 359 'input': '123', |
| 360 'server': 'localhost:1', | 360 'server': 'localhost:1', |
| 361 'namespace': 'default-gzip', | 361 'namespace': 'default-gzip', |
| 362 }, extra_args=['foo', 'bar']) | 362 }, extra_args=['foo', 'bar']) |
| 363 # Mock running run_isolated with a script. | 363 # Mock running run_isolated with a script. |
| 364 SCRIPT_ISOLATED = ( | 364 SCRIPT_ISOLATED = ( |
| 365 'import json, sys;\n' | 365 'import json, sys;\n' |
| 366 'if len(sys.argv) != 2:\n' | 366 'args = []\n' |
| 367 ' raise Exception(sys.argv);\n' | 367 'if len(sys.argv) != 3 or sys.argv[1] != \'-f\':\n' |
| 368 'with open(sys.argv[1], \'wb\') as f:\n' | 368 ' raise Exception(sys.argv)\n' |
| 369 'with open(sys.argv[2], \'r\') as argsfile:\n' |
| 370 ' args = json.loads(argsfile.read())\n' |
| 371 'if len(args) != 1:\n' |
| 372 ' raise Exception(args);\n' |
| 373 'with open(args[0], \'wb\') as f:\n' |
| 369 ' json.dump({\n' | 374 ' json.dump({\n' |
| 370 ' \'exit_code\': 0,\n' | 375 ' \'exit_code\': 0,\n' |
| 371 ' \'had_hard_timeout\': False,\n' | 376 ' \'had_hard_timeout\': False,\n' |
| 372 ' \'internal_failure\': None,\n' | 377 ' \'internal_failure\': None,\n' |
| 373 ' \'outputs_ref\': {\n' | 378 ' \'outputs_ref\': {\n' |
| 374 ' \'isolated\': \'123\',\n' | 379 ' \'isolated\': \'123\',\n' |
| 375 ' \'isolatedserver\': \'http://localhost:1\',\n' | 380 ' \'isolatedserver\': \'http://localhost:1\',\n' |
| 376 ' \'namespace\': \'default-gzip\',\n' | 381 ' \'namespace\': \'default-gzip\',\n' |
| 377 ' },\n' | 382 ' },\n' |
| 378 ' }, f)\n' | 383 ' }, f)\n' |
| 379 'sys.stdout.write(\'hi\\n\')') | 384 'sys.stdout.write(\'hi\\n\')') |
| 380 self.mock( | 385 self.mock( |
| 381 task_runner, 'get_isolated_cmd', | 386 task_runner, 'get_run_isolated', |
| 387 lambda : |
| 388 [sys.executable, '-u', '-c', SCRIPT_ISOLATED]) |
| 389 self.mock( |
| 390 task_runner, 'get_isolated_args', |
| 382 lambda _work_dir, _details, isolated_result, bot_file, min_free_space: | 391 lambda _work_dir, _details, isolated_result, bot_file, min_free_space: |
| 383 [sys.executable, '-u', '-c', SCRIPT_ISOLATED, isolated_result]) | 392 [isolated_result]) |
| 384 expected = { | 393 expected = { |
| 385 u'exit_code': 0, | 394 u'exit_code': 0, |
| 386 u'hard_timeout': False, | 395 u'hard_timeout': False, |
| 387 u'io_timeout': False, | 396 u'io_timeout': False, |
| 388 u'must_signal_internal_failure': None, | 397 u'must_signal_internal_failure': None, |
| 389 u'version': task_runner.OUT_VERSION, | 398 u'version': task_runner.OUT_VERSION, |
| 390 } | 399 } |
| 391 self.assertEqual(expected, self._run_command(task_details)) | 400 self.assertEqual(expected, self._run_command(task_details)) |
| 392 | 401 |
| 393 def test_run_command_fail(self): | 402 def test_run_command_fail(self): |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 fix_encoding.fix_encoding() | 1203 fix_encoding.fix_encoding() |
| 1195 if '-v' in sys.argv: | 1204 if '-v' in sys.argv: |
| 1196 unittest.TestCase.maxDiff = None | 1205 unittest.TestCase.maxDiff = None |
| 1197 logging_utils.prepare_logging(None) | 1206 logging_utils.prepare_logging(None) |
| 1198 logging_utils.set_console_level( | 1207 logging_utils.set_console_level( |
| 1199 logging.DEBUG if '-v' in sys.argv else logging.CRITICAL+1) | 1208 logging.DEBUG if '-v' in sys.argv else logging.CRITICAL+1) |
| 1200 # Fix litteral text expectation. | 1209 # Fix litteral text expectation. |
| 1201 os.environ['LANG'] = 'en_US.UTF-8' | 1210 os.environ['LANG'] = 'en_US.UTF-8' |
| 1202 os.environ['LANGUAGE'] = 'en_US.UTF-8' | 1211 os.environ['LANGUAGE'] = 'en_US.UTF-8' |
| 1203 unittest.main() | 1212 unittest.main() |
| OLD | NEW |