~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branchbuilder.py

  • Committer: Robert Collins
  • Date: 2007-06-26 08:52:20 UTC
  • mto: This revision was merged to the branch mainline in revision 2554.
  • Revision ID: robertc@robertcollins.net-20070626085220-iovhwfjflk8vffbh
Add require_api API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
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
"""Tests for the BranchBuilder class."""
 
18
 
 
19
from bzrlib import (
 
20
    branch as _mod_branch,
 
21
    revision as _mod_revision,
 
22
    tests,
 
23
    )
 
24
from bzrlib.branchbuilder import BranchBuilder
 
25
 
 
26
 
 
27
class TestBranchBuilder(tests.TestCaseWithMemoryTransport):
 
28
    
 
29
    def test_create(self):
 
30
        """Test the constructor api."""
 
31
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
32
        # we dont care if the branch has been built or not at this point.
 
33
 
 
34
    def test_get_branch(self):
 
35
        """get_branch returns the created branch."""
 
36
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
37
        branch = builder.get_branch()
 
38
        self.assertIsInstance(branch, _mod_branch.Branch)
 
39
        self.assertEqual(self.get_transport().clone('foo').base,
 
40
            branch.base)
 
41
        self.assertEqual(
 
42
            (0, _mod_revision.NULL_REVISION),
 
43
            branch.last_revision_info())
 
44
 
 
45
    def test_format(self):
 
46
        """Making a BranchBuilder with a format option sets the branch type."""
 
47
        builder = BranchBuilder(self.get_transport(), format='dirstate-tags')
 
48
        branch = builder.get_branch()
 
49
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
 
50
 
 
51
    def test_build_one_commit(self):
 
52
        """doing build_commit causes a commit to happen."""
 
53
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
54
        rev_id = builder.build_commit()
 
55
        branch = builder.get_branch()
 
56
        self.assertEqual((1, rev_id), branch.last_revision_info())
 
57
        self.assertEqual(
 
58
            'commit 1',
 
59
            branch.repository.get_revision(branch.last_revision()).message)
 
60
 
 
61
    def test_build_two_commits(self):
 
62
        """The second commit has the right parents and message."""
 
63
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
64
        rev_id1 = builder.build_commit()
 
65
        rev_id2 = builder.build_commit()
 
66
        branch = builder.get_branch()
 
67
        self.assertEqual((2, rev_id2), branch.last_revision_info())
 
68
        self.assertEqual(
 
69
            'commit 2',
 
70
            branch.repository.get_revision(branch.last_revision()).message)
 
71
        self.assertEqual(
 
72
            [rev_id1],
 
73
            branch.repository.get_revision(branch.last_revision()).parent_ids)