~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branchbuilder.py

Initial commit for russian version of documents.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for the BranchBuilder class."""
18
18
 
26
26
 
27
27
 
28
28
class TestBranchBuilder(tests.TestCaseWithMemoryTransport):
29
 
 
 
29
    
30
30
    def test_create(self):
31
31
        """Test the constructor api."""
32
32
        builder = BranchBuilder(self.get_transport().clone('foo'))
59
59
            'commit 1',
60
60
            branch.repository.get_revision(branch.last_revision()).message)
61
61
 
62
 
    def test_build_commit_timestamp(self):
63
 
        """You can set a date when committing."""
64
 
        builder = self.make_branch_builder('foo')
65
 
        rev_id = builder.build_commit(timestamp=1236043340)
66
 
        branch = builder.get_branch()
67
 
        self.assertEqual((1, rev_id), branch.last_revision_info())
68
 
        rev = branch.repository.get_revision(branch.last_revision())
69
 
        self.assertEqual(
70
 
            'commit 1',
71
 
            rev.message)
72
 
        self.assertEqual(
73
 
            1236043340,
74
 
            int(rev.timestamp))
75
 
 
76
62
    def test_build_two_commits(self):
77
63
        """The second commit has the right parents and message."""
78
64
        builder = BranchBuilder(self.get_transport().clone('foo'))
144
130
                              (u'b', 'b-id', 'directory'),
145
131
                             ], rev_tree)
146
132
 
147
 
    def test_commit_timestamp(self):
148
 
        builder = self.make_branch_builder('foo')
149
 
        rev_id = builder.build_snapshot(None, None,
150
 
            [('add', (u'', None, 'directory', None))],
151
 
            timestamp=1234567890)
152
 
        rev = builder.get_branch().repository.get_revision(rev_id)
153
 
        self.assertEqual(
154
 
            1234567890,
155
 
            int(rev.timestamp))
156
 
 
157
133
    def test_commit_message_default(self):
158
134
        builder = BranchBuilder(self.get_transport().clone('foo'))
159
135
        rev_id = builder.build_snapshot(None, None,
221
197
            builder.build_snapshot, 'B-id', None, [('weirdo', ('foo',))])
222
198
        self.assertEqual('Unknown build action: "weirdo"', str(e))
223
199
 
224
 
    def test_rename(self):
225
 
        builder = self.build_a_rev()
226
 
        builder.build_snapshot('B-id', None,
227
 
            [('rename', ('a', 'b'))])
228
 
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
229
 
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
230
 
                              (u'b', 'a-id', 'file')], rev_tree)
231
 
 
232
 
    def test_rename_into_subdir(self):
233
 
        builder = self.build_a_rev()
234
 
        builder.build_snapshot('B-id', None,
235
 
            [('add', ('dir', 'dir-id', 'directory', None)),
236
 
             ('rename', ('a', 'dir/a'))])
237
 
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
238
 
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
239
 
                              (u'dir', 'dir-id', 'directory'),
240
 
                              (u'dir/a', 'a-id', 'file')], rev_tree)
 
200
    # TODO: rename a file/directory, but rename isn't supported by the
 
201
    #       MemoryTree api yet, so for now we wait until it is used
241
202
 
242
203
    def test_set_parent(self):
243
204
        builder = self.build_a_rev()
245
206
        self.addCleanup(builder.finish_series)
246
207
        builder.build_snapshot('B-id', ['A-id'],
247
208
            [('modify', ('a-id', 'new\ncontent\n'))])
248
 
        builder.build_snapshot('C-id', ['A-id'],
 
209
        builder.build_snapshot('C-id', ['A-id'], 
249
210
            [('add', ('c', 'c-id', 'file', 'alt\ncontent\n'))])
250
211
        # We should now have a graph:
251
212
        #   A
326
287
            builder.finish_series()
327
288
        self.assertIs(None, builder._tree)
328
289
        self.assertFalse(builder._branch.is_locked())
329
 
 
330
 
    def test_ghost_mainline_history(self):
331
 
        builder = BranchBuilder(self.get_transport().clone('foo'))
332
 
        builder.start_series()
333
 
        try:
334
 
            builder.build_snapshot('tip', ['ghost'],
335
 
                [('add', ('', 'ROOT_ID', 'directory', ''))],
336
 
                allow_leftmost_as_ghost=True)
337
 
        finally:
338
 
            builder.finish_series()
339
 
        b = builder.get_branch()
340
 
        b.lock_read()
341
 
        self.addCleanup(b.unlock)
342
 
        self.assertEqual(('ghost',),
343
 
            b.repository.get_graph().get_parent_map(['tip'])['tip'])