| 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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 u'namespace': u'default-gzip', | 351 u'namespace': u'default-gzip', |
| 352 }) | 352 }) |
| 353 task_details = self.get_task_details(isolated={ | 353 task_details = self.get_task_details(isolated={ |
| 354 'input': '123', | 354 'input': '123', |
| 355 'server': 'localhost:1', | 355 'server': 'localhost:1', |
| 356 'namespace': 'default-gzip', | 356 'namespace': 'default-gzip', |
| 357 }, extra_args=['foo', 'bar']) | 357 }, extra_args=['foo', 'bar']) |
| 358 # Mock running run_isolated with a script. | 358 # Mock running run_isolated with a script. |
| 359 SCRIPT_ISOLATED = ( | 359 SCRIPT_ISOLATED = ( |
| 360 'import json, sys;\n' | 360 'import json, sys;\n' |
| 361 'if len(sys.argv) != 2:\n' | 361 'args = []\n' |
| 362 ' raise Exception(sys.argv);\n' | 362 'if len(sys.argv) != 3 or sys.argv[1] != \'-a\':\n' |
| 363 'with open(sys.argv[1], \'wb\') as f:\n' | 363 ' raise Exception(sys.argv)\n' |
| 364 'with open(sys.argv[2], \'r\') as argsfile:\n' |
| 365 ' args = json.loads(argsfile.read())\n' |
| 366 'if len(args) != 1:\n' |
| 367 ' raise Exception(args);\n' |
| 368 'with open(args[0], \'wb\') as f:\n' |
| 364 ' json.dump({\n' | 369 ' json.dump({\n' |
| 365 ' \'exit_code\': 0,\n' | 370 ' \'exit_code\': 0,\n' |
| 366 ' \'had_hard_timeout\': False,\n' | 371 ' \'had_hard_timeout\': False,\n' |
| 367 ' \'internal_failure\': None,\n' | 372 ' \'internal_failure\': None,\n' |
| 368 ' \'outputs_ref\': {\n' | 373 ' \'outputs_ref\': {\n' |
| 369 ' \'isolated\': \'123\',\n' | 374 ' \'isolated\': \'123\',\n' |
| 370 ' \'isolatedserver\': \'http://localhost:1\',\n' | 375 ' \'isolatedserver\': \'http://localhost:1\',\n' |
| 371 ' \'namespace\': \'default-gzip\',\n' | 376 ' \'namespace\': \'default-gzip\',\n' |
| 372 ' },\n' | 377 ' },\n' |
| 373 ' }, f)\n' | 378 ' }, f)\n' |
| 374 'sys.stdout.write(\'hi\\n\')') | 379 'sys.stdout.write(\'hi\\n\')') |
| 375 self.mock( | 380 self.mock( |
| 376 task_runner, 'get_isolated_cmd', | 381 task_runner, 'get_run_isolated', |
| 382 lambda : |
| 383 [sys.executable, '-u', '-c', SCRIPT_ISOLATED]) |
| 384 self.mock( |
| 385 task_runner, 'get_isolated_args', |
| 377 lambda _work_dir, _details, isolated_result, bot_file, min_free_space: | 386 lambda _work_dir, _details, isolated_result, bot_file, min_free_space: |
| 378 [sys.executable, '-u', '-c', SCRIPT_ISOLATED, isolated_result]) | 387 [isolated_result]) |
| 379 expected = { | 388 expected = { |
| 380 u'exit_code': 0, | 389 u'exit_code': 0, |
| 381 u'hard_timeout': False, | 390 u'hard_timeout': False, |
| 382 u'io_timeout': False, | 391 u'io_timeout': False, |
| 383 u'must_signal_internal_failure': None, | 392 u'must_signal_internal_failure': None, |
| 384 u'version': task_runner.OUT_VERSION, | 393 u'version': task_runner.OUT_VERSION, |
| 385 } | 394 } |
| 386 self.assertEqual(expected, self._run_command(task_details)) | 395 self.assertEqual(expected, self._run_command(task_details)) |
| 387 | 396 |
| 388 def test_run_command_fail(self): | 397 def test_run_command_fail(self): |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 fix_encoding.fix_encoding() | 1198 fix_encoding.fix_encoding() |
| 1190 if '-v' in sys.argv: | 1199 if '-v' in sys.argv: |
| 1191 unittest.TestCase.maxDiff = None | 1200 unittest.TestCase.maxDiff = None |
| 1192 logging_utils.prepare_logging(None) | 1201 logging_utils.prepare_logging(None) |
| 1193 logging_utils.set_console_level( | 1202 logging_utils.set_console_level( |
| 1194 logging.DEBUG if '-v' in sys.argv else logging.CRITICAL+1) | 1203 logging.DEBUG if '-v' in sys.argv else logging.CRITICAL+1) |
| 1195 # Fix litteral text expectation. | 1204 # Fix litteral text expectation. |
| 1196 os.environ['LANG'] = 'en_US.UTF-8' | 1205 os.environ['LANG'] = 'en_US.UTF-8' |
| 1197 os.environ['LANGUAGE'] = 'en_US.UTF-8' | 1206 os.environ['LANGUAGE'] = 'en_US.UTF-8' |
| 1198 unittest.main() | 1207 unittest.main() |
| OLD | NEW |