/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.54.76 by Vincent Ladeuil
Fix the broken test.
1
# Copyright (C) 2007-2010 Canonical Ltd
0.54.61 by Jeff Licquia
Assign copyright to Canonical.
2
#
0.54.40 by Jeff Licquia
Move the tests to their own module.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
0.54.61 by Jeff Licquia
Assign copyright to Canonical.
6
# (at your option) any later version.
0.54.57 by Jeff Licquia
Check and fix more PEP 8 failures.
7
#
0.54.40 by Jeff Licquia
Move the tests to their own module.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
0.54.57 by Jeff Licquia
Check and fix more PEP 8 failures.
12
#
0.54.40 by Jeff Licquia
Move the tests to their own module.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
0.54.56 by Jeff Licquia
Fix some pylint complaints.
17
"Test suite for the bzr bisect plugin."
18
0.54.40 by Jeff Licquia
Move the tests to their own module.
19
import os
0.54.72 by James Westby
Start to remove the use of sys.stdout.
20
from cStringIO import StringIO
0.54.41 by Jeff Licquia
Add a merged subtree to the repo the tests create.
21
import shutil
0.54.60 by Jeff Licquia
Move plugin metadata to its own package, and redo versioning.
22
import bzrlib
0.54.41 by Jeff Licquia
Add a merged subtree to the repo the tests create.
23
import bzrlib.bzrdir
0.54.40 by Jeff Licquia
Move the tests to their own module.
24
import bzrlib.tests
0.54.49 by Jeff Licquia
Add subtree and harness tests.
25
import bzrlib.revisionspec
0.54.40 by Jeff Licquia
Move the tests to their own module.
26
import bzrlib.plugins.bisect as bisect
27
0.54.52 by Jeff Licquia
PEP 8 fixes.
28
0.54.40 by Jeff Licquia
Move the tests to their own module.
29
class BisectTestCase(bzrlib.tests.TestCaseWithTransport):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
30
    "Test harness specific to the bisect plugin."
0.54.57 by Jeff Licquia
Check and fix more PEP 8 failures.
31
0.54.40 by Jeff Licquia
Move the tests to their own module.
32
    def assertRevno(self, rev):
33
        "Make sure we're at the right revision."
34
0.54.52 by Jeff Licquia
PEP 8 fixes.
35
        rev_contents = {1: "one", 1.1: "one dot one", 1.2: "one dot two",
36
                        1.3: "one dot three", 2: "two", 3: "three",
37
                        4: "four", 5: "five"}
0.54.40 by Jeff Licquia
Move the tests to their own module.
38
0.54.56 by Jeff Licquia
Fix some pylint complaints.
39
        test_file = open("test_file")
40
        content = test_file.read().strip()
0.54.50 by Jeff Licquia
Better diagnostics when an assertRevno() call fails.
41
        if content != rev_contents[rev]:
42
            rev_ids = dict((rev_contents[k], k) for k in rev_contents.keys())
43
            found_rev = rev_ids[content]
44
            raise AssertionError("expected rev %0.1f, found rev %0.1f"
45
                                 % (rev, found_rev))
0.54.40 by Jeff Licquia
Move the tests to their own module.
46
47
    def setUp(self):
48
        bzrlib.tests.TestCaseWithTransport.setUp(self)
49
0.54.41 by Jeff Licquia
Add a merged subtree to the repo the tests create.
50
        # These tests assume a branch with five revisions, and
51
        # a branch from version 1 containing three revisions
52
        # merged at version 2.
0.54.40 by Jeff Licquia
Move the tests to their own module.
53
54
        self.tree = self.make_branch_and_tree(".")
55
0.54.56 by Jeff Licquia
Fix some pylint complaints.
56
        test_file = open("test_file", "w")
57
        test_file.write("one")
58
        test_file.close()
0.54.52 by Jeff Licquia
PEP 8 fixes.
59
        self.tree.add(self.tree.relpath(os.path.join(os.getcwd(),
60
                                                     'test_file')))
0.54.40 by Jeff Licquia
Move the tests to their own module.
61
        self.tree.commit(message = "add test file")
62
0.54.41 by Jeff Licquia
Add a merged subtree to the repo the tests create.
63
        bzrlib.bzrdir.BzrDir.open(".").sprout("../temp-clone")
64
        clone_bzrdir = bzrlib.bzrdir.BzrDir.open("../temp-clone")
65
        clone_tree = clone_bzrdir.open_workingtree()
66
        for content in ["one dot one", "one dot two", "one dot three"]:
0.54.56 by Jeff Licquia
Fix some pylint complaints.
67
            test_file = open("../temp-clone/test_file", "w")
68
            test_file.write(content)
69
            test_file.close()
0.54.41 by Jeff Licquia
Add a merged subtree to the repo the tests create.
70
            clone_tree.commit(message = "make branch test change")
0.54.49 by Jeff Licquia
Add subtree and harness tests.
71
            saved_subtree_revid = clone_tree.branch.last_revision()
0.54.41 by Jeff Licquia
Add a merged subtree to the repo the tests create.
72
73
        self.tree.merge_from_branch(clone_tree.branch)
0.54.56 by Jeff Licquia
Fix some pylint complaints.
74
        test_file = open("test_file", "w")
75
        test_file.write("two")
76
        test_file.close()
0.54.41 by Jeff Licquia
Add a merged subtree to the repo the tests create.
77
        self.tree.commit(message = "merge external branch")
78
        shutil.rmtree("../temp-clone")
79
0.54.49 by Jeff Licquia
Add subtree and harness tests.
80
        self.subtree_rev = saved_subtree_revid
81
0.54.41 by Jeff Licquia
Add a merged subtree to the repo the tests create.
82
        file_contents = ["three", "four", "five"]
0.54.40 by Jeff Licquia
Move the tests to their own module.
83
        for content in file_contents:
0.54.56 by Jeff Licquia
Fix some pylint complaints.
84
            test_file = open("test_file", "w")
85
            test_file.write(content)
86
            test_file.close()
0.54.40 by Jeff Licquia
Move the tests to their own module.
87
            self.tree.commit(message = "make test change")
88
0.54.52 by Jeff Licquia
PEP 8 fixes.
89
0.54.49 by Jeff Licquia
Add subtree and harness tests.
90
class BisectHarnessTests(BisectTestCase):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
91
    "Tests for the harness itself."
0.54.57 by Jeff Licquia
Check and fix more PEP 8 failures.
92
0.54.49 by Jeff Licquia
Add subtree and harness tests.
93
    def testLastRev(self):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
94
        "Test that the last revision is correct."
0.54.52 by Jeff Licquia
PEP 8 fixes.
95
        repo = self.tree.branch.repository
96
        top_revtree = repo.revision_tree(self.tree.last_revision())
0.54.49 by Jeff Licquia
Add subtree and harness tests.
97
        top_revtree.lock_read()
98
        top_file = top_revtree.get_file(top_revtree.path2id("test_file"))
99
        test_content = top_file.read().strip()
100
        top_file.close()
101
        top_revtree.unlock()
102
        assert test_content == "five"
103
104
    def testSubtreeRev(self):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
105
        "Test that the last revision in a subtree is correct."
0.54.52 by Jeff Licquia
PEP 8 fixes.
106
        repo = self.tree.branch.repository
107
        sub_revtree = repo.revision_tree(self.subtree_rev)
0.54.49 by Jeff Licquia
Add subtree and harness tests.
108
        sub_revtree.lock_read()
109
        sub_file = sub_revtree.get_file(sub_revtree.path2id("test_file"))
110
        test_content = sub_file.read().strip()
111
        sub_file.close()
112
        sub_revtree.unlock()
113
        assert test_content == "one dot three"
114
0.54.52 by Jeff Licquia
PEP 8 fixes.
115
0.54.60 by Jeff Licquia
Move plugin metadata to its own package, and redo versioning.
116
class BisectMetaTests(BisectTestCase):
117
    "Test the metadata provided by the package."
118
119
    def testVersionPresent(self):
120
        assert bisect.version_info
121
122
    def testBzrVersioning(self):
0.54.76 by Vincent Ladeuil
Fix the broken test.
123
        assert bisect.bzr_minimum_api <= bzrlib.api_minimum_version
0.54.60 by Jeff Licquia
Move plugin metadata to its own package, and redo versioning.
124
        assert bisect.bzr_minimum_api <= bzrlib.version_info[:3]
125
126
0.54.40 by Jeff Licquia
Move the tests to their own module.
127
class BisectCurrentUnitTests(BisectTestCase):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
128
    "Test the BisectCurrent class."
0.54.57 by Jeff Licquia
Check and fix more PEP 8 failures.
129
0.54.40 by Jeff Licquia
Move the tests to their own module.
130
    def testShowLog(self):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
131
        "Test that the log can be shown."
0.54.40 by Jeff Licquia
Move the tests to their own module.
132
        # Not a very good test; just makes sure the code doesn't fail,
133
        # not that the output makes any sense.
0.54.72 by James Westby
Start to remove the use of sys.stdout.
134
        sio = StringIO()
135
        bisect.BisectCurrent().show_rev_log(out=sio)
0.54.40 by Jeff Licquia
Move the tests to their own module.
136
0.54.49 by Jeff Licquia
Add subtree and harness tests.
137
    def testShowLogSubtree(self):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
138
        "Test that a subtree's log can be shown."
139
        current = bisect.BisectCurrent()
140
        current.switch(self.subtree_rev)
0.54.72 by James Westby
Start to remove the use of sys.stdout.
141
        sio = StringIO()
142
        current.show_rev_log(out=sio)
0.54.49 by Jeff Licquia
Add subtree and harness tests.
143
0.54.40 by Jeff Licquia
Move the tests to their own module.
144
    def testSwitchVersions(self):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
145
        "Test switching versions."
146
        current = bisect.BisectCurrent()
0.54.40 by Jeff Licquia
Move the tests to their own module.
147
        self.assertRevno(5)
0.54.56 by Jeff Licquia
Fix some pylint complaints.
148
        current.switch(4)
0.54.40 by Jeff Licquia
Move the tests to their own module.
149
        self.assertRevno(4)
150
151
    def testReset(self):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
152
        "Test resetting the working tree to a non-bisected state."
153
        current = bisect.BisectCurrent()
154
        current.switch(4)
155
        current.reset()
0.54.40 by Jeff Licquia
Move the tests to their own module.
156
        self.assertRevno(5)
157
        assert not os.path.exists(bisect.bisect_rev_path)
158
0.54.43 by Jeff Licquia
Add non-functioning is_merge_point() method to BisectCurrent.
159
    def testIsMergePoint(self):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
160
        "Test merge point detection."
161
        current = bisect.BisectCurrent()
0.54.43 by Jeff Licquia
Add non-functioning is_merge_point() method to BisectCurrent.
162
        self.assertRevno(5)
0.54.56 by Jeff Licquia
Fix some pylint complaints.
163
        assert not current.is_merge_point()
164
        current.switch(2)
165
        assert current.is_merge_point()
0.54.43 by Jeff Licquia
Add non-functioning is_merge_point() method to BisectCurrent.
166
0.54.52 by Jeff Licquia
PEP 8 fixes.
167
0.54.40 by Jeff Licquia
Move the tests to their own module.
168
class BisectLogUnitTests(BisectTestCase):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
169
    "Test the BisectLog class."
0.54.57 by Jeff Licquia
Check and fix more PEP 8 failures.
170
0.54.40 by Jeff Licquia
Move the tests to their own module.
171
    def testCreateBlank(self):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
172
        "Test creation of new log."
173
        bisect_log = bisect.BisectLog()
174
        bisect_log.save()
0.54.40 by Jeff Licquia
Move the tests to their own module.
175
        assert os.path.exists(bisect.bisect_info_path)
176
177
    def testLoad(self):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
178
        "Test loading a log."
179
        preloaded_log = open(bisect.bisect_info_path, "w")
180
        preloaded_log.write("rev1 yes\nrev2 no\nrev3 yes\n")
181
        preloaded_log.close()
0.54.40 by Jeff Licquia
Move the tests to their own module.
182
0.54.56 by Jeff Licquia
Fix some pylint complaints.
183
        bisect_log = bisect.BisectLog()
184
        assert len(bisect_log._items) == 3
185
        assert bisect_log._items[0] == ("rev1", "yes")
186
        assert bisect_log._items[1] == ("rev2", "no")
187
        assert bisect_log._items[2] == ("rev3", "yes")
0.54.40 by Jeff Licquia
Move the tests to their own module.
188
189
    def testSave(self):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
190
        "Test saving the log."
191
        bisect_log = bisect.BisectLog()
192
        bisect_log._items = [("rev1", "yes"), ("rev2", "no"), ("rev3", "yes")]
193
        bisect_log.save()
0.54.40 by Jeff Licquia
Move the tests to their own module.
194
0.54.56 by Jeff Licquia
Fix some pylint complaints.
195
        logfile = open(bisect.bisect_info_path)
196
        assert logfile.read() == "rev1 yes\nrev2 no\nrev3 yes\n"
0.54.40 by Jeff Licquia
Move the tests to their own module.
197
0.54.52 by Jeff Licquia
PEP 8 fixes.
198
0.54.40 by Jeff Licquia
Move the tests to their own module.
199
class BisectFuncTests(BisectTestCase):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
200
    "Functional tests for the bisect plugin."
0.54.57 by Jeff Licquia
Check and fix more PEP 8 failures.
201
0.54.40 by Jeff Licquia
Move the tests to their own module.
202
    def testWorkflow(self):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
203
        "Run through a basic usage scenario."
204
0.54.40 by Jeff Licquia
Move the tests to their own module.
205
        # Start up the bisection.  When the two ends are set, we should
206
        # end up in the middle.
207
208
        self.run_bzr(['bisect', 'start'])
209
        self.run_bzr(['bisect', 'yes'])
210
        self.run_bzr(['bisect', 'no', '-r', '1'])
211
        self.assertRevno(3)
212
213
        # Mark feature as present in the middle.  Should move us
214
        # halfway back between the current middle and the start.
215
216
        self.run_bzr(['bisect', 'yes'])
217
        self.assertRevno(2)
218
219
        # Mark feature as not present.  Since this is only one
220
        # rev back from the lowest marked revision with the feature,
221
        # the process should end, with the current rev set to the
222
        # rev following.
223
224
        self.run_bzr(['bisect', 'no'])
225
        self.assertRevno(3)
226
0.59.7 by Jeff Licquia
Tests for detecting "done" status, plus a first run at implementation.
227
        # Run again.  Since we're done, this should do nothing.
228
229
        self.run_bzr(['bisect', 'no'])
230
        self.assertRevno(3)
231
0.54.42 by Jeff Licquia
Add functional test for subtree functionality (not passing).
232
    def testWorkflowSubtree(self):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
233
        """Run through a usage scenario where the offending change
234
        is in a subtree."""
235
0.54.42 by Jeff Licquia
Add functional test for subtree functionality (not passing).
236
        # Similar to testWorkflow, but make sure the plugin traverses
237
        # subtrees when the "final" revision is a merge point.
238
239
        # This part is similar to testWorkflow.
240
241
        self.run_bzr(['bisect', 'start'])
242
        self.run_bzr(['bisect', 'yes'])
243
        self.run_bzr(['bisect', 'no', '-r', '1'])
244
        self.run_bzr(['bisect', 'yes'])
245
246
        # Check to make sure we're where we expect to be.
247
248
        self.assertRevno(2)
249
250
        # Now, mark the merge point revno, meaning the feature
251
        # appeared at a merge point.
252
253
        self.run_bzr(['bisect', 'yes'])
254
        self.assertRevno(1.2)
255
256
        # Continue bisecting along the subtree to the real conclusion.
257
258
        self.run_bzr(['bisect', 'yes'])
259
        self.assertRevno(1.1)
260
        self.run_bzr(['bisect', 'yes'])
261
        self.assertRevno(1.1)
262
0.59.7 by Jeff Licquia
Tests for detecting "done" status, plus a first run at implementation.
263
        # Run again.  Since we're done, this should do nothing.
264
265
        self.run_bzr(['bisect', 'yes'])
266
        self.assertRevno(1.1)
267
0.54.40 by Jeff Licquia
Move the tests to their own module.
268
    def testMove(self):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
269
        "Test manually moving to a different revision during the bisection."
270
0.54.40 by Jeff Licquia
Move the tests to their own module.
271
        # Set up a bisection in progress.
272
273
        self.run_bzr(['bisect', 'start'])
274
        self.run_bzr(['bisect', 'yes'])
275
        self.run_bzr(['bisect', 'no', '-r', '1'])
276
277
        # Move.
278
279
        self.run_bzr(['bisect', 'move', '-r', '2'])
280
        self.assertRevno(2)
281
282
    def testReset(self):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
283
        "Test resetting the tree."
284
0.54.40 by Jeff Licquia
Move the tests to their own module.
285
        # Set up a bisection in progress.
286
287
        self.run_bzr(['bisect', 'start'])
288
        self.run_bzr(['bisect', 'yes'])
289
        self.run_bzr(['bisect', 'no', '-r', '1'])
290
        self.run_bzr(['bisect', 'yes'])
291
292
        # Now reset.
293
294
        self.run_bzr(['bisect', 'reset'])
295
        self.assertRevno(5)
296
0.59.4 by Jeff Licquia
Make reset a no-op if no bisection is in progress.
297
        # Check that reset doesn't do anything unless there's a
298
        # bisection in progress.
299
300
        test_file = open("test_file", "w")
301
        test_file.write("keep me")
302
        test_file.close()
303
0.54.73 by James Westby
Some cleanups.
304
        out, err = self.run_bzr(['bisect', 'reset'], retcode=3)
305
        self.assert_("No bisection in progress." in err)
0.59.4 by Jeff Licquia
Make reset a no-op if no bisection is in progress.
306
307
        test_file = open("test_file")
308
        content = test_file.read().strip()
309
        test_file.close()
310
        self.failUnless(content == "keep me")
311
0.54.40 by Jeff Licquia
Move the tests to their own module.
312
    def testLog(self):
0.54.56 by Jeff Licquia
Fix some pylint complaints.
313
        "Test saving the current bisection state, and re-loading it."
314
0.54.40 by Jeff Licquia
Move the tests to their own module.
315
        # Set up a bisection in progress.
316
317
        self.run_bzr(['bisect', 'start'])
318
        self.run_bzr(['bisect', 'yes'])
319
        self.run_bzr(['bisect', 'no', '-r', '1'])
320
        self.run_bzr(['bisect', 'yes'])
321
322
        # Now save the log.
323
324
        self.run_bzr(['bisect', 'log', '-o', 'bisect_log'])
325
326
        # Reset.
327
328
        self.run_bzr(['bisect', 'reset'])
329
330
        # Read it back in.
331
332
        self.run_bzr(['bisect', 'replay', 'bisect_log'])
333
        self.assertRevno(2)
334
335
        # Mark another state, and see if the bisect moves in the
336
        # right way.
337
338
        self.run_bzr(['bisect', 'no'])
339
        self.assertRevno(3)
0.54.53 by Jeff Licquia
Move test suite detection function to the test module.
340
341
342
def test_suite():
0.54.56 by Jeff Licquia
Fix some pylint complaints.
343
    "Set up the bisect plugin test suite."
0.54.53 by Jeff Licquia
Move test suite detection function to the test module.
344
    from bzrlib.tests.TestUtil import TestLoader, TestSuite
345
    from bzrlib.plugins.bisect import tests
346
    suite = TestSuite()
347
    suite.addTest(TestLoader().loadTestsFromTestCase(tests.BisectHarnessTests))
0.54.60 by Jeff Licquia
Move plugin metadata to its own package, and redo versioning.
348
    suite.addTest(TestLoader().loadTestsFromTestCase(tests.BisectMetaTests))
0.54.53 by Jeff Licquia
Move test suite detection function to the test module.
349
    suite.addTest(TestLoader().loadTestsFromTestCase(tests.BisectFuncTests))
350
    suite.addTest(TestLoader().loadTestsFromTestCase(
351
        tests.BisectCurrentUnitTests))
352
    suite.addTest(TestLoader().loadTestsFromTestCase(tests.BisectLogUnitTests))
353
    return suite