/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
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
189
        commit_col = dlg._treeview_files.get_column(0)
190
        self.assertEqual('Commit', commit_col.get_title())
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
191
        renderer = commit_col.get_cell_renderers()[0]
192
        self.assertTrue(renderer.get_active())
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
193
194
    def test_pending(self):
195
        tree = self.make_branch_and_tree('tree')
196
        rev_id1 = tree.commit('one')
197
198
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
199
        rev_id2 = tree2.commit('two',
200
                               committer='Joe Foo <joe@foo.com>',
201
                               timestamp=1191264271.05,
202
                               timezone=+7200)
203
        tree.merge_from_branch(tree2.branch)
204
205
        dlg = commit.CommitDialog(tree)
206
        # TODO: assert that the pending box is set to show
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
207
        commit_col = dlg._treeview_files.get_column(0)
208
        self.assertEqual('Commit*', commit_col.get_title())
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
209
        renderer = commit_col.get_cell_renderers()[0]
210
        self.assertFalse(renderer.get_active())
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
211
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
212
        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.
213
        self.assertEqual([(rev_id2, '2007-10-01', 'Joe Foo', 'two')], values)
214
215
    def test_pending_multiple(self):
216
        tree = self.make_branch_and_tree('tree')
217
        rev_id1 = tree.commit('one')
218
219
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
220
        rev_id2 = tree2.commit('two',
221
                               committer='Joe Foo <joe@foo.com>',
222
                               timestamp=1191264271.05,
223
                               timezone=+7200)
224
        rev_id3 = tree2.commit('three',
225
                               committer='Jerry Foo <jerry@foo.com>',
226
                               timestamp=1191264278.05,
227
                               timezone=+7200)
228
        tree.merge_from_branch(tree2.branch)
229
        tree3 = tree.bzrdir.sprout('tree3').open_workingtree()
230
        rev_id4 = tree3.commit('four',
231
                               committer='Joe Foo <joe@foo.com>',
232
                               timestamp=1191264279.05,
233
                               timezone=+7200)
234
        rev_id5 = tree3.commit('five',
235
                               committer='Jerry Foo <jerry@foo.com>',
236
                               timestamp=1191372278.05,
237
                               timezone=+7200)
238
        tree.merge_from_branch(tree3.branch)
239
240
        dlg = commit.CommitDialog(tree)
241
        # TODO: assert that the pending box is set to show
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
242
        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.
243
        self.assertEqual([(rev_id3, '2007-10-01', 'Jerry Foo', 'three'),
244
                          (rev_id2, '2007-10-01', 'Joe Foo', 'two'),
245
                          (rev_id5, '2007-10-03', 'Jerry Foo', 'five'),
246
                          (rev_id4, '2007-10-01', 'Joe Foo', 'four'),
247
                         ], values)
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
248
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
249
    def test_filelist_added(self):
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
250
        tree = self.make_branch_and_tree('tree')
251
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
252
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
253
254
        dlg = commit.CommitDialog(tree)
255
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
256
        self.assertEqual([(None, None, True, 'All Files', ''),
257
                          ('a-id', 'a', True, 'a', 'added'),
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
258
                          ('b-id', 'b', True, 'b/', 'added'),
259
                          ('c-id', 'b/c', True, 'b/c', 'added'),
260
                         ], values)
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
261
262
    def test_filelist_renamed(self):
263
        tree = self.make_branch_and_tree('tree')
264
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
265
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
266
        rev_id1 = tree.commit('one')
267
268
        tree.rename_one('b', 'd')
269
        tree.rename_one('a', 'd/a')
270
271
        dlg = commit.CommitDialog(tree)
272
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
273
        self.assertEqual([(None, None, True, 'All Files', ''),
274
                          ('b-id', 'd', True, 'b/ => d/', 'renamed'),
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
275
                          ('a-id', 'd/a', True, 'a => d/a', 'renamed'),
276
                         ], values)
277
278
    def test_filelist_modified(self):
279
        tree = self.make_branch_and_tree('tree')
280
        self.build_tree(['tree/a'])
281
        tree.add(['a'], ['a-id'])
282
        rev_id1 = tree.commit('one')
283
284
        self.build_tree_contents([('tree/a', 'new contents for a\n')])
285
286
        dlg = commit.CommitDialog(tree)
287
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
288
        self.assertEqual([(None, None, True, 'All Files', ''),
289
                          ('a-id', 'a', True, 'a', 'modified'),
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
290
                         ], values)
291
292
    def test_filelist_renamed_and_modified(self):
293
        tree = self.make_branch_and_tree('tree')
294
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
295
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
296
        rev_id1 = tree.commit('one')
297
298
        tree.rename_one('b', 'd')
299
        tree.rename_one('a', 'd/a')
300
        self.build_tree_contents([('tree/d/a', 'new contents for a\n'),
301
                                  ('tree/d/c', 'new contents for c\n'),
302
                                 ])
303
        # 'c' is not considered renamed, because only its parent was moved, it
304
        # stayed in the same directory
305
306
        dlg = commit.CommitDialog(tree)
307
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
308
        self.assertEqual([(None, None, True, 'All Files', ''),
309
                          ('b-id', 'd', True, 'b/ => d/', 'renamed'),
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
310
                          ('a-id', 'd/a', True, 'a => d/a', 'renamed and modified'),
311
                          ('c-id', 'd/c', True, 'd/c', 'modified'),
312
                         ], values)
313
314
    def test_filelist_kind_changed(self):
315
        tree = self.make_branch_and_tree('tree')
316
        self.build_tree(['tree/a', 'tree/b'])
317
        tree.add(['a', 'b'], ['a-id', 'b-id'])
318
        tree.commit('one')
319
320
        os.remove('tree/a')
321
        self.build_tree(['tree/a/'])
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
322
        # XXX:  This is technically valid, and the file list handles it fine,
323
        #       but 'show_diff_trees()' does not, so we skip this part of the
324
        #       test for now.
325
        # tree.rename_one('b', 'c')
326
        # os.remove('tree/c')
327
        # self.build_tree(['tree/c/'])
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
328
329
        dlg = commit.CommitDialog(tree)
330
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
331
        self.assertEqual([(None, None, True, 'All Files', ''),
332
                          ('a-id', 'a', True, 'a => a/', 'kind changed'),
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
333
                          # ('b-id', 'c', True, 'b => c/', 'renamed and modified'),
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
334
                         ], values)
335
336
    def test_filelist_removed(self):
337
        tree = self.make_branch_and_tree('tree')
338
        self.build_tree(['tree/a', 'tree/b/'])
339
        tree.add(['a', 'b'], ['a-id', 'b-id'])
340
        tree.commit('one')
341
342
        os.remove('tree/a')
343
        tree.remove('b', force=True)
344
345
        dlg = commit.CommitDialog(tree)
346
        values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store]
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
347
        self.assertEqual([(None, None, True, 'All Files', ''),
348
                          ('a-id', 'a', True, 'a', 'removed'),
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
349
                          ('b-id', 'b', True, 'b/', 'removed'),
350
                         ], values)
278.1.18 by John Arbash Meinel
Start checking the diff view is correct.
351
352
    def test_diff_view(self):
353
        tree = self.make_branch_and_tree('tree')
354
        self.build_tree(['tree/a', 'tree/b'])
355
        tree.add(['a', 'b'], ['a-id', 'b-id'])
356
        tree.commit('one')
357
358
        self.build_tree_contents([('tree/a', 'new contents for a\n')])
359
        tree.remove('b')
360
361
        dlg = commit.CommitDialog(tree)
362
        diff_buffer = dlg._diff_view.buffer
363
        text = diff_buffer.get_text(diff_buffer.get_start_iter(),
364
                                    diff_buffer.get_end_iter()).splitlines(True)
365
366
        self.assertEqual("=== removed file 'b'\n", text[0])
367
        self.assertContainsRe(text[1],
368
            r"--- b\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
369
        self.assertEqual('+++ b\t1970-01-01 00:00:00 +0000\n', text[2])
370
        self.assertEqual('@@ -1,1 +0,0 @@\n', text[3])
371
        self.assertEqual('-contents of tree/b\n', text[4])
372
        self.assertEqual('\n', text[5])
373
374
        self.assertEqual("=== modified file 'a'\n", text[6])
375
        self.assertContainsRe(text[7],
376
            r"--- a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
377
        self.assertContainsRe(text[8],
378
            r"\+\+\+ a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
379
        self.assertEqual('@@ -1,1 +1,1 @@\n', text[9])
380
        self.assertEqual('-contents of tree/a\n', text[10])
381
        self.assertEqual('+new contents for a\n', text[11])
382
        self.assertEqual('\n', text[12])
383
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
384
        self.assertEqual('Diff for All Files', dlg._diff_label.get_text())
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
385
386
    def test_file_selection(self):
387
        """Several things should happen when a file has been selected."""
388
        tree = self.make_branch_and_tree('tree')
389
        self.build_tree(['tree/a', 'tree/b'])
390
        tree.add(['a', 'b'], ['a-id', 'b-id'])
391
392
        dlg = commit.CommitDialog(tree)
393
        diff_buffer = dlg._diff_view.buffer
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
394
        self.assertEqual('Diff for All Files', dlg._diff_label.get_text())
278.1.21 by John Arbash Meinel
Start tracking the per-file commit messages.
395
        self.assertEqual('File commit message',
396
                         dlg._file_message_expander.get_label())
397
        self.assertFalse(dlg._file_message_expander.get_expanded())
398
        self.assertFalse(dlg._file_message_expander.get_property('sensitive'))
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
399
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
400
        dlg._treeview_files.set_cursor((1,))
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
401
        self.assertEqual('Diff for a', dlg._diff_label.get_text())
402
        text = diff_buffer.get_text(diff_buffer.get_start_iter(),
403
                                    diff_buffer.get_end_iter()).splitlines(True)
404
        self.assertEqual("=== added file 'a'\n", text[0])
405
        self.assertContainsRe(text[1],
406
            r"--- a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
407
        self.assertContainsRe(text[2],
408
            r"\+\+\+ a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
409
        self.assertEqual('@@ -0,0 +1,1 @@\n', text[3])
410
        self.assertEqual('+contents of tree/a\n', text[4])
411
        self.assertEqual('\n', text[5])
278.1.21 by John Arbash Meinel
Start tracking the per-file commit messages.
412
        self.assertEqual('Commit message for a',
413
                         dlg._file_message_expander.get_label())
414
        self.assertTrue(dlg._file_message_expander.get_expanded())
415
        self.assertTrue(dlg._file_message_expander.get_property('sensitive'))
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
416
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
417
        dlg._treeview_files.set_cursor((2,))
278.1.19 by John Arbash Meinel
Test what happens when a specific file is selected.
418
        self.assertEqual('Diff for b', dlg._diff_label.get_text())
419
        text = diff_buffer.get_text(diff_buffer.get_start_iter(),
420
                                    diff_buffer.get_end_iter()).splitlines(True)
421
        self.assertEqual("=== added file 'b'\n", text[0])
422
        self.assertContainsRe(text[1],
423
            r"--- b\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
424
        self.assertContainsRe(text[2],
425
            r"\+\+\+ b\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
426
        self.assertEqual('@@ -0,0 +1,1 @@\n', text[3])
427
        self.assertEqual('+contents of tree/b\n', text[4])
428
        self.assertEqual('\n', text[5])
278.1.21 by John Arbash Meinel
Start tracking the per-file commit messages.
429
        self.assertEqual('Commit message for b',
430
                         dlg._file_message_expander.get_label())
431
        self.assertTrue(dlg._file_message_expander.get_expanded())
432
        self.assertTrue(dlg._file_message_expander.get_property('sensitive'))
433
434
        dlg._treeview_files.set_cursor((0,))
435
        self.assertEqual('Diff for All Files', dlg._diff_label.get_text())
436
        self.assertEqual('File commit message',
437
                         dlg._file_message_expander.get_label())
438
        self.assertFalse(dlg._file_message_expander.get_expanded())
439
        self.assertFalse(dlg._file_message_expander.get_property('sensitive'))
440
441
    def test_file_selection_message(self):
442
        """Selecting a file should bring up its commit message."""
443
        tree = self.make_branch_and_tree('tree')
444
        self.build_tree(['tree/a', 'tree/b/'])
445
        tree.add(['a', 'b'], ['a-id', 'b-id'])
446
447
        def get_file_text():
448
            buf = dlg._file_message_text_view.get_buffer()
449
            return buf.get_text(buf.get_start_iter(), buf.get_end_iter())
450
451
        def get_saved_text(path):
452
            """Get the saved text for a given record."""
453
            return dlg._files_store.get_value(dlg._files_store.get_iter(path), 5)
454
455
        dlg = commit.CommitDialog(tree)
456
        self.assertEqual('File commit message',
457
                         dlg._file_message_expander.get_label())
458
        self.assertFalse(dlg._file_message_expander.get_expanded())
459
        self.assertFalse(dlg._file_message_expander.get_property('sensitive'))
460
        self.assertEqual('', get_file_text())
461
462
        dlg._treeview_files.set_cursor((1,))
463
        self.assertEqual('Commit message for a',
464
                         dlg._file_message_expander.get_label())
465
        self.assertTrue(dlg._file_message_expander.get_expanded())
466
        self.assertTrue(dlg._file_message_expander.get_property('sensitive'))
467
        self.assertEqual('', get_file_text())
468
469
        self.assertEqual('', get_saved_text(1))
470
        dlg._file_message_text_view.get_buffer().set_text('Some text\nfor a\n')
471
        dlg._save_current_file_message()
472
        # We should have updated the ListStore with the new file commit info
473
        self.assertEqual('Some text\nfor a\n', get_saved_text(1))
474
475
        dlg._treeview_files.set_cursor((2,))
476
        self.assertEqual('Commit message for b/',
477
                         dlg._file_message_expander.get_label())
478
        self.assertTrue(dlg._file_message_expander.get_expanded())
479
        self.assertTrue(dlg._file_message_expander.get_property('sensitive'))
480
        self.assertEqual('', get_file_text())
481
482
        self.assertEqual('', get_saved_text(2))
483
        dlg._file_message_text_view.get_buffer().set_text('More text\nfor b\n')
484
        # Now switch back to 'a'. The message should be saved, and the buffer
485
        # should be updated with the other text
486
        dlg._treeview_files.set_cursor((1,))
487
        self.assertEqual('More text\nfor b\n', get_saved_text(2))
488
        self.assertEqual('Commit message for a',
489
                         dlg._file_message_expander.get_label())
490
        self.assertTrue(dlg._file_message_expander.get_expanded())
491
        self.assertTrue(dlg._file_message_expander.get_property('sensitive'))
492
        self.assertEqual('Some text\nfor a\n', get_file_text())
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
493
494
    def test_toggle_all_files(self):
495
        """When checking the All Files entry, it should toggle all fields"""
496
        tree = self.make_branch_and_tree('tree')
497
        self.build_tree(['tree/a', 'tree/b/'])
498
        tree.add(['a', 'b'], ['a-id', 'b-id'])
499
500
        dlg = commit.CommitDialog(tree)
501
        self.assertEqual([(None, None, True),
502
                          ('a-id', 'a', True),
503
                          ('b-id', 'b', True),
504
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])
505
506
        # TODO: jam 20071002 I'm not sure how to exactly trigger a toggle, it
507
        #       looks like we need to call renderer.activate() and pass an
508
        #       event and widget, and lots of other stuff I'm not sure what to
509
        #       do with. So instead, we just call toggle directly, and assume
510
        #       that toggle is hooked in correctly
511
        # column = dlg._treeview_files.get_column(0)
512
        # renderer = column.get_cell_renderers()[0]
513
514
        # Toggle a single entry should set just that entry to False
515
        dlg._toggle_commit(None, 1, dlg._files_store)
516
        self.assertEqual([(None, None, True),
517
                          ('a-id', 'a', False),
518
                          ('b-id', 'b', True),
519
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])
520
521
        # Toggling the main entry should set all entries
522
        dlg._toggle_commit(None, 0, dlg._files_store)
523
        self.assertEqual([(None, None, False),
524
                          ('a-id', 'a', False),
525
                          ('b-id', 'b', False),
526
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])
527
528
        dlg._toggle_commit(None, 2, dlg._files_store)
529
        self.assertEqual([(None, None, False),
530
                          ('a-id', 'a', False),
531
                          ('b-id', 'b', True),
532
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])
533
534
        dlg._toggle_commit(None, 0, dlg._files_store)
535
        self.assertEqual([(None, None, True),
536
                          ('a-id', 'a', True),
537
                          ('b-id', 'b', True),
538
                         ], [(r[0], r[1], r[2]) for r in dlg._files_store])