OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The LUCI Authors. All rights reserved. | 2 # Copyright 2014 The LUCI Authors. All rights reserved. |
3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
5 | 5 |
6 import os | 6 import os |
7 import sys | 7 import sys |
8 import unittest | 8 import unittest |
9 import threading | 9 import threading |
10 | 10 |
11 THIS_FILE = os.path.abspath(__file__) | 11 THIS_FILE = os.path.abspath(__file__) |
12 | 12 |
13 import test_env_api | 13 import test_env_api |
14 test_env_api.setup_test_env() | 14 test_env_api.setup_test_env() |
15 | 15 |
16 import bot | 16 import bot |
17 | 17 |
18 | 18 |
19 class TestBot(unittest.TestCase): | 19 class TestBot(unittest.TestCase): |
20 def test_bot(self): | 20 def test_bot(self): |
21 obj = bot.Bot( | 21 obj = bot.Bot( |
| 22 None, |
22 {'dimensions': {'foo': 'bar'}}, | 23 {'dimensions': {'foo': 'bar'}}, |
23 'https://localhost:1', | 24 'https://localhost:1', |
24 '1234-1a2b3c4-tainted-joe', | 25 '1234-1a2b3c4-tainted-joe', |
25 'base_dir', | 26 'base_dir', |
26 None) | 27 None) |
27 self.assertEqual({'foo': 'bar'}, obj.dimensions) | 28 self.assertEqual({'foo': 'bar'}, obj.dimensions) |
28 self.assertEqual( | 29 self.assertEqual( |
29 os.path.join(os.path.dirname(THIS_FILE), 'swarming_bot.zip'), | 30 os.path.join(os.path.dirname(THIS_FILE), 'swarming_bot.zip'), |
30 obj.swarming_bot_zip) | 31 obj.swarming_bot_zip) |
31 self.assertEqual('1234-1a2b3c4-tainted-joe', obj.server_version) | 32 self.assertEqual('1234-1a2b3c4-tainted-joe', obj.server_version) |
32 self.assertEqual('base_dir', obj.base_dir) | 33 self.assertEqual('base_dir', obj.base_dir) |
33 | 34 |
34 def test_bot_call_later(self): | 35 def test_bot_call_later(self): |
35 obj = bot.Bot({}, 'https://localhost:1', '1234-1a2b3c4-tainted-joe', | 36 obj = bot.Bot(None, {}, 'https://localhost:1', '1234-1a2b3c4-tainted-joe', |
36 'base_dir', None) | 37 'base_dir', None) |
37 ev = threading.Event() | 38 ev = threading.Event() |
38 obj.call_later(0.001, ev.set) | 39 obj.call_later(0.001, ev.set) |
39 self.assertTrue(ev.wait(1)) | 40 self.assertTrue(ev.wait(1)) |
40 | 41 |
41 def test_bot_call_later_cancel(self): | 42 def test_bot_call_later_cancel(self): |
42 obj = bot.Bot({}, 'https://localhost:1', '1234-1a2b3c4-tainted-joe', | 43 obj = bot.Bot(None, {}, 'https://localhost:1', '1234-1a2b3c4-tainted-joe', |
43 'base_dir', None) | 44 'base_dir', None) |
44 ev = threading.Event() | 45 ev = threading.Event() |
45 obj.call_later(0.1, ev.set) | 46 obj.call_later(0.1, ev.set) |
46 obj.cancel_all_timers() | 47 obj.cancel_all_timers() |
47 self.assertFalse(ev.wait(0.3)) | 48 self.assertFalse(ev.wait(0.3)) |
48 | 49 |
49 | 50 |
50 if __name__ == '__main__': | 51 if __name__ == '__main__': |
51 if '-v' in sys.argv: | 52 if '-v' in sys.argv: |
52 unittest.TestCase.maxDiff = None | 53 unittest.TestCase.maxDiff = None |
53 unittest.main() | 54 unittest.main() |
OLD | NEW |