/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
1
# Copyright (C) 2007 John Arbash Meinel <john@arbash-meinel.com>
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
16
17
"""Test the Commit functionality."""
18
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
19
import os
20
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
21
from bzrlib import (
22
    tests,
23
    revision,
24
    )
25
26
from bzrlib.plugins.gtk import commit
27
28
29
# TODO: All we need is basic ancestry code to test this, we shouldn't need a
30
# TestCaseWithTransport, just a TestCaseWithMemoryTransport or somesuch.
31
32
class TestPendingRevisions(tests.TestCaseWithTransport):
33
34
    def test_pending_revisions_none(self):
35
        tree = self.make_branch_and_tree('.')
36
        tree.commit('one')
37
38
        self.assertIs(None, commit.pending_revisions(tree))
39
40
    def test_pending_revisions_simple(self):
41
        tree = self.make_branch_and_tree('tree')
42
        rev_id1 = tree.commit('one')
43
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
44
        rev_id2 = tree2.commit('two')
45
        tree.merge_from_branch(tree2.branch)
46
        self.assertEqual([rev_id1, rev_id2], tree.get_parent_ids())
47
48
        pending_revisions = commit.pending_revisions(tree)
49
        # One primary merge
50
        self.assertEqual(1, len(pending_revisions))
51
        # Revision == rev_id2
52
        self.assertEqual(rev_id2, pending_revisions[0][0].revision_id)
53
        # No children of this revision.
54
        self.assertEqual([], pending_revisions[0][1])
55
56
    def test_pending_revisions_with_children(self):
57
        tree = self.make_branch_and_tree('tree')
58
        rev_id1 = tree.commit('one')
59
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
60
        rev_id2 = tree2.commit('two')
61
        rev_id3 = tree2.commit('three')
62
        rev_id4 = tree2.commit('four')
63
        tree.merge_from_branch(tree2.branch)
64
        self.assertEqual([rev_id1, rev_id4], tree.get_parent_ids())
65
66
        pending_revisions = commit.pending_revisions(tree)
67
        # One primary merge
68
        self.assertEqual(1, len(pending_revisions))
69
        # Revision == rev_id2
70
        self.assertEqual(rev_id4, pending_revisions[0][0].revision_id)
71
        # Two children for this revision
72
        self.assertEqual(2, len(pending_revisions[0][1]))
73
        self.assertEqual(rev_id3, pending_revisions[0][1][0].revision_id)
74
        self.assertEqual(rev_id2, pending_revisions[0][1][1].revision_id)
75
76
    def test_pending_revisions_multi_merge(self):
77
        tree = self.make_branch_and_tree('tree')
78
        rev_id1 = tree.commit('one')
79
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
80
        rev_id2 = tree2.commit('two')
81
        rev_id3 = tree2.commit('three')
82
        tree3 = tree2.bzrdir.sprout('tree3').open_workingtree()
83
        rev_id4 = tree3.commit('four')
84
        rev_id5 = tree3.commit('five')
85
        tree.merge_from_branch(tree2.branch)
86
        tree.merge_from_branch(tree3.branch)
87
        self.assertEqual([rev_id1, rev_id3, rev_id5], tree.get_parent_ids())
88
89
        pending_revisions = commit.pending_revisions(tree)
90
        # Two primary merges
91
        self.assertEqual(2, len(pending_revisions))
92
        # Revision == rev_id2
93
        self.assertEqual(rev_id3, pending_revisions[0][0].revision_id)
94
        self.assertEqual(rev_id5, pending_revisions[1][0].revision_id)
95
        # One child for the first merge
96
        self.assertEqual(1, len(pending_revisions[0][1]))
97
        self.assertEqual(rev_id2, pending_revisions[0][1][0].revision_id)
98
        # One child for the second merge
99
        self.assertEqual(1, len(pending_revisions[1][1]))
100
        self.assertEqual(rev_id4, pending_revisions[1][1][0].revision_id)
101
102
103
class Test_RevToPendingInfo(tests.TestCaseWithTransport):
104
105
    def test_basic_info(self):
106
        tree = self.make_branch_and_tree('tree')
107
        rev_id = tree.commit('Multiline\ncommit\nmessage',
108
                             committer='Joe Foo <joe@foo.com>',
109
                             timestamp=1191012408.674,
110
                             timezone=-18000
111
                             )
112
        rev = tree.branch.repository.get_revision(rev_id)
113
        rev_dict = commit.CommitDialog._rev_to_pending_info(rev)
114
        self.assertEqual({'committer':'Joe Foo',
115
                          'summary':'Multiline',
116
                          'date':'2007-09-28',
117
                          'revision_id':rev_id,
118
                         }, rev_dict)
119
120
121
class CommitDialogNoWidgets(commit.CommitDialog):
122
123
    def construct(self):
124
        pass # Don't create any widgets here
125
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
126
    def fill_in_data(self):
127
        pass # With no widgets, there are no widgets to fill out
128
129
130
class TestCommitDialogSimple(tests.TestCaseWithTransport):
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
131
132
    def test_setup_parameters_no_pending(self):
133
        tree = self.make_branch_and_tree('tree')
134
        rev_id = tree.commit('first')
135
136
        dlg = CommitDialogNoWidgets(tree)
137
        self.assertEqual(rev_id, dlg._basis_tree.get_revision_id())
138
        self.assertIs(None, dlg._pending)
139
        self.assertFalse(dlg._is_checkout)
140
141
    def test_setup_parameters_checkout(self):
142
        tree = self.make_branch_and_tree('tree')
143
        rev_id = tree.commit('first')
144
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
145
        tree2.branch.bind(tree.branch)
146
147
        dlg = CommitDialogNoWidgets(tree2)
148
        self.assertEqual(rev_id, dlg._basis_tree.get_revision_id())
149
        self.assertIs(None, dlg._pending)
150
        self.assertTrue(dlg._is_checkout)
151
152
    def test_setup_parameters_pending(self):
153
        tree = self.make_branch_and_tree('tree')
154
        rev_id1 = tree.commit('one')
155
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
156
        rev_id2 = tree2.commit('two')
157
        tree.merge_from_branch(tree2.branch)
158
159
        dlg = CommitDialogNoWidgets(tree)
160
        self.assertEqual(rev_id1, dlg._basis_tree.get_revision_id())
161
        self.assertIsNot(None, dlg._pending)
162
        self.assertEqual(1, len(dlg._pending))
163
        self.assertEqual(rev_id2, dlg._pending[0][0].revision_id)
164
165
    def test_setup_parameters_delta(self):
166
        tree = self.make_branch_and_tree('tree')
167
        self.build_tree(['tree/a'])
168
        tree.add(['a'], ['a-id'])
169
170
        dlg = CommitDialogNoWidgets(tree)
278.1.12 by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names.
171
        self.assertIs(None, dlg._delta)
172
        dlg._compute_delta()
173
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
174
        delta = dlg._delta
175
        self.assertEqual([], delta.modified)
176
        self.assertEqual([], delta.renamed)
177
        self.assertEqual([], delta.removed)
178
        self.assertEqual([(u'a', 'a-id', 'file')], delta.added)
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
179
180
181
class TestCommitDialog(tests.TestCaseWithTransport):
182
183
    def test_no_pending(self):
184
        tree = self.make_branch_and_tree('tree')
185
        rev_id1 = tree.commit('one')
186
187
        dlg = commit.CommitDialog(tree)
188
        # TODO: assert that the pending box is hidden
189
190
    def test_pending(self):
191
        tree = self.make_branch_and_tree('tree')
192
        rev_id1 = tree.commit('one')
193
194
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
195
        rev_id2 = tree2.commit('two',
196
                               committer='Joe Foo <joe@foo.com>',
197
                               timestamp=1191264271.05,
198
                               timezone=+7200)
199
        tree.merge_from_branch(tree2.branch)
200
201
        dlg = commit.CommitDialog(tree)
202
        # TODO: assert that the pending box is set to show
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
203
        values = [(r[0], r[1], r[2], r[3]) for r in dlg._pending_store]
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
204
        self.assertEqual([(rev_id2, '2007-10-01', 'Joe Foo', 'two')], values)
205
206
    def test_pending_multiple(self):
207
        tree = self.make_branch_and_tree('tree')
208
        rev_id1 = tree.commit('one')
209
210
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
211
        rev_id2 = tree2.commit('two',
212
                               committer='Joe Foo <joe@foo.com>',
213
                               timestamp=1191264271.05,
214
                               timezone=+7200)
215
        rev_id3 = tree2.commit('three',
216
                               committer='Jerry Foo <jerry@foo.com>',
217
                               timestamp=1191264278.05,
218
                               timezone=+7200)
219
        tree.merge_from_branch(tree2.branch)
220
        tree3 = tree.bzrdir.sprout('tree3').open_workingtree()
221
        rev_id4 = tree3.commit('four',
222
                               committer='Joe Foo <joe@foo.com>',
223
                               timestamp=1191264279.05,
224
                               timezone=+7200)
225
        rev_id5 = tree3.commit('five',
226
                               committer='Jerry Foo <jerry@foo.com>',
227
                               timestamp=1191372278.05,
228
                               timezone=+7200)
229
        tree.merge_from_branch(tree3.branch)
230
231
        dlg = commit.CommitDialog(tree)
232
        # TODO: assert that the pending box is set to show
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
233
        values = [(r[0], r[1], r[2], r[3]) for r in dlg._pending_store]
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
234
        self.assertEqual([(rev_id3, '2007-10-01', 'Jerry Foo', 'three'),
235
                          (rev_id2, '2007-10-01', 'Joe Foo', 'two'),
236
                          (rev_id5, '2007-10-03', 'Jerry Foo', 'five'),
237
                          (rev_id4, '2007-10-01', 'Joe Foo', 'four'),
238
                         ], values)
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
239
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
240
    def test_filelist_added(self):
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
241
        tree = self.make_branch_and_tree('tree')
242
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
243
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
244
245
        dlg = commit.CommitDialog(tree)
246
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
247
        self.assertEqual([('a-id', 'a', True, 'a', 'added'),
248
                          ('b-id', 'b', True, 'b/', 'added'),
249
                          ('c-id', 'b/c', True, 'b/c', 'added'),
250
                         ], values)
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
251
252
    def test_filelist_renamed(self):
253
        tree = self.make_branch_and_tree('tree')
254
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
255
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
256
        rev_id1 = tree.commit('one')
257
258
        tree.rename_one('b', 'd')
259
        tree.rename_one('a', 'd/a')
260
261
        dlg = commit.CommitDialog(tree)
262
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
263
        self.assertEqual([('b-id', 'd', True, 'b/ => d/', 'renamed'),
264
                          ('a-id', 'd/a', True, 'a => d/a', 'renamed'),
265
                         ], values)
266
267
    def test_filelist_modified(self):
268
        tree = self.make_branch_and_tree('tree')
269
        self.build_tree(['tree/a'])
270
        tree.add(['a'], ['a-id'])
271
        rev_id1 = tree.commit('one')
272
273
        self.build_tree_contents([('tree/a', 'new contents for a\n')])
274
275
        dlg = commit.CommitDialog(tree)
276
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
277
        self.assertEqual([('a-id', 'a', True, 'a', 'modified'),
278
                         ], values)
279
280
    def test_filelist_renamed_and_modified(self):
281
        tree = self.make_branch_and_tree('tree')
282
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
283
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
284
        rev_id1 = tree.commit('one')
285
286
        tree.rename_one('b', 'd')
287
        tree.rename_one('a', 'd/a')
288
        self.build_tree_contents([('tree/d/a', 'new contents for a\n'),
289
                                  ('tree/d/c', 'new contents for c\n'),
290
                                 ])
291
        # 'c' is not considered renamed, because only its parent was moved, it
292
        # stayed in the same directory
293
294
        dlg = commit.CommitDialog(tree)
295
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
296
        self.assertEqual([('b-id', 'd', True, 'b/ => d/', 'renamed'),
297
                          ('a-id', 'd/a', True, 'a => d/a', 'renamed and modified'),
298
                          ('c-id', 'd/c', True, 'd/c', 'modified'),
299
                         ], values)
300
301
    def test_filelist_kind_changed(self):
302
        tree = self.make_branch_and_tree('tree')
303
        self.build_tree(['tree/a', 'tree/b'])
304
        tree.add(['a', 'b'], ['a-id', 'b-id'])
305
        tree.commit('one')
306
307
        os.remove('tree/a')
308
        self.build_tree(['tree/a/'])
309
        tree.rename_one('b', 'c')
310
        os.remove('tree/c')
311
        self.build_tree(['tree/c/'])
312
313
        dlg = commit.CommitDialog(tree)
314
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
315
        self.assertEqual([('a-id', 'a', True, 'a => a/', 'kind changed'),
316
                          ('b-id', 'c', True, 'b => c/', 'renamed and modified'),
317
                         ], values)
318
319
    def test_filelist_removed(self):
320
        tree = self.make_branch_and_tree('tree')
321
        self.build_tree(['tree/a', 'tree/b/'])
322
        tree.add(['a', 'b'], ['a-id', 'b-id'])
323
        tree.commit('one')
324
325
        os.remove('tree/a')
326
        tree.remove('b', force=True)
327
328
        dlg = commit.CommitDialog(tree)
329
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
330
        self.assertEqual([('a-id', 'a', True, 'a', 'removed'),
331
                          ('b-id', 'b', True, 'b/', 'removed'),
332
                         ], values)