| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Swarming Authors. All rights reserved. | 2 # Copyright 2014 The Swarming Authors. All rights reserved. |
| 3 # Use of this source code is governed by the Apache v2.0 license that can be | 3 # Use of this source code is governed by the Apache v2.0 license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import json | 6 import json |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 import shutil | |
| 10 import sys | 9 import sys |
| 11 import tempfile | 10 import tempfile |
| 12 import unittest | 11 import unittest |
| 13 | 12 |
| 14 BOT_DIR = os.path.dirname(os.path.abspath(__file__)) | 13 BOT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 15 | 14 |
| 16 import test_env_bot | 15 import test_env_bot |
| 17 test_env_bot.setup_test_env() | 16 test_env_bot.setup_test_env() |
| 18 | 17 |
| 19 from utils import subprocess42 | 18 from utils import subprocess42 |
| 20 | 19 |
| 21 import fake_swarming | 20 import fake_swarming |
| 22 from bot_code import bot_main | 21 from bot_code import bot_main |
| 23 from depot_tools import auto_stub | 22 from depot_tools import auto_stub |
| 23 from depot_tools import fix_encoding |
| 24 from utils import file_path |
| 24 | 25 |
| 25 | 26 |
| 26 class TestCase(auto_stub.TestCase): | 27 class TestCase(auto_stub.TestCase): |
| 27 def setUp(self): | 28 def setUp(self): |
| 28 super(TestCase, self).setUp() | 29 super(TestCase, self).setUp() |
| 29 self._tmpdir = tempfile.mkdtemp(prefix='swarming_main') | 30 self._tmpdir = tempfile.mkdtemp(prefix='swarming_main') |
| 30 self._zip_file = os.path.join(self._tmpdir, 'swarming_bot.zip') | 31 self._zip_file = os.path.join(self._tmpdir, 'swarming_bot.zip') |
| 31 code, _ = fake_swarming.gen_zip(self.url) | 32 code, _ = fake_swarming.gen_zip(self.url) |
| 32 with open(self._zip_file, 'wb') as f: | 33 with open(self._zip_file, 'wb') as f: |
| 33 f.write(code) | 34 f.write(code) |
| 34 | 35 |
| 35 def tearDown(self): | 36 def tearDown(self): |
| 36 try: | 37 try: |
| 37 shutil.rmtree(self._tmpdir) | 38 file_path.rmtree(self._tmpdir) |
| 38 finally: | 39 finally: |
| 39 super(TestCase, self).tearDown() | 40 super(TestCase, self).tearDown() |
| 40 | 41 |
| 41 | 42 |
| 42 class SimpleMainTest(TestCase): | 43 class SimpleMainTest(TestCase): |
| 43 @property | 44 @property |
| 44 def url(self): | 45 def url(self): |
| 45 return 'http://localhost:1' | 46 return 'http://localhost:1' |
| 46 | 47 |
| 47 def test_attributes(self): | 48 def test_attributes(self): |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 }, | 113 }, |
| 113 ] | 114 ] |
| 114 if sys.platform == 'win32': | 115 if sys.platform == 'win32': |
| 115 # Sadly, the signal handler generate an error. | 116 # Sadly, the signal handler generate an error. |
| 116 # TODO(maruel): Fix one day. | 117 # TODO(maruel): Fix one day. |
| 117 self.assertEqual(u'bot_error', events.pop(0)['event']) | 118 self.assertEqual(u'bot_error', events.pop(0)['event']) |
| 118 self.assertEqual(expected, events) | 119 self.assertEqual(expected, events) |
| 119 | 120 |
| 120 | 121 |
| 121 if __name__ == '__main__': | 122 if __name__ == '__main__': |
| 123 fix_encoding.fix_encoding() |
| 122 if '-v' in sys.argv: | 124 if '-v' in sys.argv: |
| 123 unittest.TestCase.maxDiff = None | 125 unittest.TestCase.maxDiff = None |
| 124 unittest.main() | 126 unittest.main() |
| OLD | NEW |