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.
7 bisect_builds
= __import__('bisect-builds')
10 class BisectTest(unittest
.TestCase
):
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
)
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
))
35 def bisect(self
, good_rev
, bad_rev
, evaluate
):
36 return bisect_builds
.Bisect(good_rev
=good_rev
,
40 official_builds
=False,
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__':