OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import os | 5 import os |
6 import sys | 6 import sys |
7 import unittest | 7 import unittest |
8 | 8 |
9 # TODO(robertocn): Use abspath for these, to prevent relative path errors. | 9 # TODO(robertocn): Use abspath for these, to prevent relative path errors. |
10 _RECIPE_MODULES_DIR = os.path.join(os.path.dirname(__file__), os.path.pardir) | 10 _RECIPE_MODULES_DIR = os.path.join(os.path.dirname(__file__), os.path.pardir) |
11 # For the importing of mock. | 11 # For the importing of mock. |
12 _ROOT_DIR = os.path.join(os.path.dirname(__file__), os.path.pardir, | 12 _ROOT_DIR = os.path.join(os.path.dirname(__file__), os.path.pardir, |
13 os.path.pardir, os.path.pardir, os.path.pardir) | 13 os.path.pardir, os.path.pardir, os.path.pardir) |
14 | 14 |
15 sys.path.append(_RECIPE_MODULES_DIR) | 15 sys.path.append(_RECIPE_MODULES_DIR) |
16 sys.path.append(os.path.join(_ROOT_DIR, 'third_party', 'mock-1.0.1')) | 16 sys.path.append(os.path.join(_ROOT_DIR, 'third_party', 'mock-1.0.1')) |
17 | 17 |
18 import mock | 18 import mock |
19 | 19 |
20 from auto_bisect.bisector import Bisector | 20 from auto_bisect.bisector import Bisector |
21 | 21 |
22 | 22 |
23 class MockRevisionClass(object): # pragma: no cover | 23 class MockRevisionClass(object): # pragma: no cover |
| 24 |
24 def __init__(self, rev_string, bisector): | 25 def __init__(self, rev_string, bisector): |
25 self.commit_pos = int(rev_string) | 26 self.commit_pos = int(rev_string) |
26 self.revision_string = rev_string | 27 self.revision_string = rev_string |
27 self.bisector = bisector | 28 self.bisector = bisector |
28 self.previous_revision = None | 29 self.previous_revision = None |
29 self.next_revision = None | 30 self.next_revision = None |
30 self.values = [] | 31 self.values = [] |
31 | 32 |
32 def get_next_url(self): | 33 def get_next_url(self): |
33 if self.in_progress: | 34 if self.in_progress: |
34 return 'mockurl' | 35 return 'mockurl' |
35 return None | 36 return None |
36 | 37 |
37 | 38 |
38 class BisectorTest(unittest.TestCase): # pragma: no cover | 39 class BisectorTest(unittest.TestCase): # pragma: no cover |
| 40 |
39 def setUp(self): | 41 def setUp(self): |
40 self.bisect_config = { | 42 self.bisect_config = { |
41 'test_type': 'perf', | 43 'test_type': 'perf', |
42 'command': 'tools/perf/run_benchmark -v ' | 44 'command': ('tools/perf/run_benchmark -v ' |
43 '--browser=release page_cycler.intl_ar_fa_he', | 45 '--browser=release page_cycler.intl_ar_fa_he'), |
44 'good_revision': '306475', | 46 'good_revision': '306475', |
45 'bad_revision': '306478', | 47 'bad_revision': '306478', |
46 'metric': 'warm_times/page_load_time', | 48 'metric': 'warm_times/page_load_time', |
47 'repeat_count': '2', | 49 'repeat_count': '2', |
48 'max_time_minutes': '5', | 50 'max_time_minutes': '5', |
49 'truncate_percent': '25', | 51 'truncate_percent': '25', |
50 'bug_id': '425582', | 52 'bug_id': '425582', |
51 'gs_bucket': 'chrome-perf', | 53 'gs_bucket': 'chrome-perf', |
52 'builder_host': 'master4.golo.chromium.org', | 54 'builder_host': 'master4.golo.chromium.org', |
53 'builder_port': '8341', | 55 'builder_port': '8341', |
54 'dummy_builds': True, | 56 'dummy_builds': True, |
55 } | 57 } |
56 self.dummy_api = mock.Mock() | 58 self.dummy_api = mock.Mock() |
57 | 59 |
58 | |
59 | |
60 def test_create_bisector(self): | 60 def test_create_bisector(self): |
61 bisector = Bisector(self.dummy_api, self.bisect_config, MockRevisionClass) | 61 bisector = Bisector(self.dummy_api, self.bisect_config, MockRevisionClass) |
62 # Check the proper revision range is initialized | 62 # Check the proper revision range is initialized |
63 self.assertEqual(4, len(bisector.revisions)) | 63 self.assertEqual(4, len(bisector.revisions)) |
64 a, b, c, d = bisector.revisions | 64 a, b, c, d = bisector.revisions |
65 # Check that revisions are properly chained | 65 # Check that revisions are properly chained |
66 self.assertEqual(a, b.previous_revision) | 66 self.assertEqual(a, b.previous_revision) |
67 self.assertEqual(b, c.previous_revision) | 67 self.assertEqual(b, c.previous_revision) |
68 self.assertEqual(c, d.previous_revision) | 68 self.assertEqual(c, d.previous_revision) |
69 self.assertEqual(d, c.next_revision) | 69 self.assertEqual(d, c.next_revision) |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 self.assertTrue(self.called_abort) | 251 self.assertTrue(self.called_abort) |
252 | 252 |
253 # Verifying the side effects of updating the candidate range | 253 # Verifying the side effects of updating the candidate range |
254 self.assertEqual(r[2], bisector.lkgr) | 254 self.assertEqual(r[2], bisector.lkgr) |
255 self.assertEqual(r[3], bisector.fkbr) | 255 self.assertEqual(r[3], bisector.fkbr) |
256 | 256 |
257 | 257 |
258 # TODO(robertocn): Add test for bisector.check_bisect_finished. | 258 # TODO(robertocn): Add test for bisector.check_bisect_finished. |
259 if __name__ == '__main__': | 259 if __name__ == '__main__': |
260 unittest.main() # pragma: no cover | 260 unittest.main() # pragma: no cover |
OLD | NEW |