Add ICU message format support
[chromium-blink-merge.git] / tools / bisect_test.py
blobb970f84e36d552c7e667d12b45fb80618d2d6176
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import unittest
7 bisect_builds = __import__('bisect-builds')
10 class BisectTest(unittest.TestCase):
12 patched = []
13 max_rev = 10000
15 def monkey_patch(self, obj, name, new):
16 self.patched.append((obj, name, getattr(obj, name)))
17 setattr(obj, name, new)
19 def clear_patching(self):
20 for obj, name, old in self.patched:
21 setattr(obj, name, old)
22 self.patched = []
24 def setUp(self):
25 self.monkey_patch(bisect_builds.DownloadJob, 'Start', lambda *args: None)
26 self.monkey_patch(bisect_builds.DownloadJob, 'Stop', lambda *args: None)
27 self.monkey_patch(bisect_builds.DownloadJob, 'WaitFor', lambda *args: None)
28 self.monkey_patch(bisect_builds, 'RunRevision', lambda *args: (0, "", ""))
29 self.monkey_patch(bisect_builds.PathContext, 'ParseDirectoryIndex',
30 lambda *args: range(self.max_rev))
32 def tearDown(self):
33 self.clear_patching()
35 def bisect(self, good_rev, bad_rev, evaluate):
36 return bisect_builds.Bisect(good_rev=good_rev,
37 bad_rev=bad_rev,
38 evaluate=evaluate,
39 num_runs=1,
40 official_builds=False,
41 platform='linux',
42 profile=None,
43 try_args=())
45 def testBisectConsistentAnswer(self):
46 self.assertEqual(self.bisect(1000, 100, lambda *args: 'g'), (100, 101))
47 self.assertEqual(self.bisect(100, 1000, lambda *args: 'b'), (100, 101))
48 self.assertEqual(self.bisect(2000, 200, lambda *args: 'b'), (1999, 2000))
49 self.assertEqual(self.bisect(200, 2000, lambda *args: 'g'), (1999, 2000))
52 if __name__ == '__main__':
53 unittest.main()