/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.436.2 by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands.
1
# Copyright (C) 2006-2007 by Jelmer Vernooij
2
# 
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
6
# (at your option) any later version.
7
#
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.
12
#
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
0.436.16 by Jelmer Vernooij
Some more work on maptree.
16
"""Tests for the rebase code."""
0.436.2 by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands.
17
0.436.7 by Jelmer Vernooij
Add more test, make basic rebase work.
18
from bzrlib.errors import UnknownFormatError, NoSuchFile
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
19
from bzrlib.revision import NULL_REVISION
0.436.5 by Jelmer Vernooij
Import change_revision_parent from bzr-svn.
20
from bzrlib.tests import TestCase, TestCaseWithTransport
21
22
from rebase import (marshall_rebase_plan, unmarshall_rebase_plan, 
0.436.7 by Jelmer Vernooij
Add more test, make basic rebase work.
23
                    replay_snapshot, generate_simple_plan,
24
                    generate_transpose_plan, rebase_plan_exists,
0.436.18 by Jelmer Vernooij
More tests, extend MapTree a bit.
25
                    rebase_todo, REBASE_PLAN_FILENAME, 
26
                    REBASE_CURRENT_REVID_FILENAME, read_rebase_plan, 
27
                    remove_rebase_plan, read_active_rebase_revid, 
28
                    write_active_rebase_revid, write_rebase_plan, MapTree)
0.436.5 by Jelmer Vernooij
Import change_revision_parent from bzr-svn.
29
0.436.4 by Jelmer Vernooij
Add some tests.
30
0.436.3 by Jelmer Vernooij
Fill in commands.
31
class RebasePlanReadWriterTests(TestCase):
0.436.4 by Jelmer Vernooij
Add some tests.
32
    def test_simple_marshall_rebase_plan(self):
33
        self.assertEqualDiff(
34
"""# Bazaar rebase plan 1
35
1 bla
36
oldrev newrev newparent1 newparent2
37
""", marshall_rebase_plan((1, "bla"), 
38
                          {"oldrev": ("newrev", ["newparent1", "newparent2"])}))
39
40
    def test_simple_unmarshall_rebase_plan(self):
41
        self.assertEquals(((1, "bla"), 
42
                          {"oldrev": ("newrev", ["newparent1", "newparent2"])}),
43
                         unmarshall_rebase_plan("""# Bazaar rebase plan 1
44
1 bla
45
oldrev newrev newparent1 newparent2
46
"""))
47
48
    def test_unmarshall_rebase_plan_formatunknown(self):
49
        self.assertRaises(UnknownFormatError,
50
                         unmarshall_rebase_plan, """# Bazaar rebase plan x
51
1 bla
52
oldrev newrev newparent1 newparent2
53
""")
0.436.5 by Jelmer Vernooij
Import change_revision_parent from bzr-svn.
54
55
56
class ConversionTests(TestCaseWithTransport):
57
    def test_simple(self):
58
        wt = self.make_branch_and_tree('.')
59
        b = wt.branch
60
        file('hello', 'w').write('hello world')
61
        wt.add('hello')
62
        wt.commit(message='add hello', rev_id="bla")
63
        file('hello', 'w').write('world')
64
        wt.commit(message='change hello', rev_id="bloe")
65
        wt.set_last_revision("bla")
66
        b.set_revision_history(["bla"])
67
        file('hello', 'w').write('world')
68
        wt.commit(message='change hello', rev_id="bla2")
69
        
0.436.7 by Jelmer Vernooij
Add more test, make basic rebase work.
70
        newrev = replay_snapshot(wt.branch.repository, "bla2", "bla4", 
0.436.5 by Jelmer Vernooij
Import change_revision_parent from bzr-svn.
71
                                        ["bloe"])
72
        self.assertEqual("bla4", newrev)
73
        self.assertTrue(wt.branch.repository.has_revision(newrev))
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
74
        self.assertEqual(["bloe"], 
75
                wt.branch.repository.revision_parents(newrev))
76
        self.assertEqual("bla2", 
77
            wt.branch.repository.get_revision(newrev).properties["rebase-of"])
0.436.6 by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation.
78
79
80
class PlanCreatorTests(TestCaseWithTransport):
81
    def test_simple_plan_creator(self):
82
        wt = self.make_branch_and_tree('.')
83
        b = wt.branch
84
        file('hello', 'w').write('hello world')
85
        wt.add('hello')
86
        wt.commit(message='add hello', rev_id="bla")
87
        file('hello', 'w').write('world')
88
        wt.commit(message='change hello', rev_id="bloe")
89
        wt.set_last_revision("bla")
90
        b.set_revision_history(["bla"])
91
        file('hello', 'w').write('world')
92
        wt.commit(message='change hello', rev_id="bla2")
93
94
        self.assertEquals({'bla2': ('newbla2', ["bloe"])}, 
95
                generate_simple_plan(b.repository, b.revision_history(), "bla2", "bloe", 
96
                    lambda y: "new"+y.revision_id))
97
     
98
    def test_simple_plan_creator_extra_history(self):
99
        wt = self.make_branch_and_tree('.')
100
        b = wt.branch
101
        file('hello', 'w').write('hello world')
102
        wt.add('hello')
103
        wt.commit(message='add hello', rev_id="bla")
104
        file('hello', 'w').write('world')
105
        wt.commit(message='change hello', rev_id="bloe")
106
        wt.set_last_revision("bla")
107
        b.set_revision_history(["bla"])
108
        file('hello', 'w').write('world')
109
        wt.commit(message='change hello', rev_id="bla2")
110
        file('hello', 'w').write('universe')
111
        wt.commit(message='change hello again', rev_id="bla3")
112
113
        self.assertEquals({'bla2': ('newbla2', ["bloe"]), 'bla3': ('newbla3', ['newbla2'])}, 
114
                generate_simple_plan(b.repository, b.revision_history(), "bla2", "bloe", 
115
                    lambda y: "new"+y.revision_id))
116
 
117
118
    def test_generate_transpose_plan(self):
119
        wt = self.make_branch_and_tree('.')
120
        b = wt.branch
121
        file('hello', 'w').write('hello world')
122
        wt.add('hello')
123
        wt.commit(message='add hello', rev_id="bla")
124
        file('hello', 'w').write('world')
125
        wt.commit(message='change hello', rev_id="bloe")
126
        wt.set_last_revision("bla")
127
        b.set_revision_history(["bla"])
128
        file('hello', 'w').write('world')
129
        wt.commit(message='change hello', rev_id="bla2")
130
        file('hello', 'w').write('universe')
131
        wt.commit(message='change hello again', rev_id="bla3")
132
        wt.set_last_revision("bla")
133
        b.set_revision_history(["bla"])
134
        file('hello', 'w').write('somebar')
135
        wt.commit(message='change hello yet again', rev_id="blie")
136
        wt.set_last_revision(NULL_REVISION)
137
        b.set_revision_history([])
138
        wt.add('hello')
139
        wt.commit(message='add hello', rev_id="lala")
140
141
        self.assertEquals({
142
                'bla': ('lala', []),
143
                'blie': ('newblie', ['lala']),
144
            },
145
                generate_transpose_plan(b.repository, b.repository.get_revision_graph("blie"), 
146
                {"bla": "lala"}, lambda y: "new"+y.revision_id))
147
        self.assertEquals({
148
                'bla': ('lala', []),
149
                'bla2': ('newbla2', ['lala']),
150
                'bla3': ('newbla3', ['newbla2']),
151
                'blie': ('newblie', ['lala']),
152
                'bloe': ('newbloe', ['lala'])},
153
                generate_transpose_plan(b.repository, b.repository.get_revision_graph(), 
154
                {"bla": "lala"}, lambda y: "new"+y.revision_id))
155
0.436.7 by Jelmer Vernooij
Add more test, make basic rebase work.
156
157
class PlanFileTests(TestCaseWithTransport):
158
   def test_rebase_plan_exists_false(self):
159
        wt = self.make_branch_and_tree('.')
160
        self.assertFalse(rebase_plan_exists(wt))
161
162
   def test_rebase_plan_exists_empty(self):
163
        wt = self.make_branch_and_tree('.')
164
        wt._control_files.put_utf8(REBASE_PLAN_FILENAME, "")
165
        self.assertFalse(rebase_plan_exists(wt))
166
167
   def test_rebase_plan_exists(self):
168
        wt = self.make_branch_and_tree('.')
169
        wt._control_files.put_utf8(REBASE_PLAN_FILENAME, "foo")
170
        self.assertTrue(rebase_plan_exists(wt))
171
172
   def test_remove_rebase_plan(self):
173
        wt = self.make_branch_and_tree('.')
174
        wt._control_files.put_utf8(REBASE_PLAN_FILENAME, "foo")
175
        remove_rebase_plan(wt)
176
        self.assertFalse(rebase_plan_exists(wt))
177
178
   def test_remove_rebase_plan_twice(self):
179
        wt = self.make_branch_and_tree('.')
180
        remove_rebase_plan(wt)
181
        self.assertFalse(rebase_plan_exists(wt))
182
183
   def test_write_rebase_plan(self):
184
        wt = self.make_branch_and_tree('.')
185
        file('hello', 'w').write('hello world')
186
        wt.add('hello')
187
        wt.commit(message='add hello', rev_id="bla")
188
        write_rebase_plan(wt, 
189
                {"oldrev": ("newrev", ["newparent1", "newparent2"])})
190
        self.assertEqualDiff("""# Bazaar rebase plan 1
191
1 bla
192
oldrev newrev newparent1 newparent2
193
""", wt._control_files.get(REBASE_PLAN_FILENAME).read())
194
195
   def test_read_rebase_plan_nonexistant(self):
196
        wt = self.make_branch_and_tree('.')
197
        self.assertRaises(NoSuchFile, read_rebase_plan, wt)
198
199
   def test_read_rebase_plan_empty(self):
200
        wt = self.make_branch_and_tree('.')
201
        wt._control_files.put_utf8(REBASE_PLAN_FILENAME, "")
202
        self.assertRaises(NoSuchFile, read_rebase_plan, wt)
203
        
204
   def test_read_rebase_plan(self):
205
        wt = self.make_branch_and_tree('.')
206
        wt._control_files.put_utf8(REBASE_PLAN_FILENAME, """# Bazaar rebase plan 1
207
1 bla
208
oldrev newrev newparent1 newparent2
209
""")
210
        self.assertEquals(((1, "bla"), {"oldrev": ("newrev", ["newparent1", "newparent2"])}),
211
                read_rebase_plan(wt))
212
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
213
0.436.9 by Jelmer Vernooij
Add rebase-todo command, fix rebase-continue.
214
class CurrentRevidFileTests(TestCaseWithTransport):
215
    def test_read_nonexistant(self):
216
        wt = self.make_branch_and_tree('.')
217
        self.assertIs(None, read_active_rebase_revid(wt))
218
219
    def test_read_null(self):
220
        wt = self.make_branch_and_tree('.')
221
        wt._control_files.put_utf8(REBASE_CURRENT_REVID_FILENAME, NULL_REVISION)
222
        self.assertIs(None, read_active_rebase_revid(wt))
223
224
    def test_read(self):
225
        wt = self.make_branch_and_tree('.')
226
        wt._control_files.put_utf8(REBASE_CURRENT_REVID_FILENAME, "bla")
227
        self.assertEquals("bla", read_active_rebase_revid(wt))
228
229
    def test_write(self):
230
        wt = self.make_branch_and_tree('.')
231
        write_active_rebase_revid(wt, "bloe")
232
        self.assertEquals("bloe", read_active_rebase_revid(wt))
233
234
    def test_write_null(self):
235
        wt = self.make_branch_and_tree('.')
236
        write_active_rebase_revid(wt, None)
237
        self.assertIs(None, read_active_rebase_revid(wt))
0.436.18 by Jelmer Vernooij
More tests, extend MapTree a bit.
238
0.436.20 by Jelmer Vernooij
Some more blackbox tests.
239
0.436.18 by Jelmer Vernooij
More tests, extend MapTree a bit.
240
class RebaseTodoTests(TestCase):
241
    def test_done(self):
242
        class Repository:
243
            def has_revision(self, revid):
244
                return revid == "bloe"
245
        self.assertEquals([], 
246
                list(rebase_todo(Repository(), { "bla": ("bloe", [])})))
247
248
    def test_notstarted(self):
249
        class Repository:
250
            def has_revision(self, revid):
251
                return False
252
        self.assertEquals(["bla"], 
253
                list(rebase_todo(Repository(), { "bla": ("bloe", [])})))
254
255
    def test_halfway(self):
256
        class Repository:
257
            def has_revision(self, revid):
258
                return revid == "bloe"
259
        self.assertEquals(["ha"], 
260
                list(rebase_todo(Repository(), { "bla": ("bloe", []), 
261
                                                 "ha": ("hee", [])})))