~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_foreign_vcs/test_branch.py

  • Committer: Mark Hammond
  • Date: 2008-09-04 12:03:01 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: mhammond@skippinet.com.au-20080904120301-x3tujl7hloy0o75j
build the list of icons without changing directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2011, 2016 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
 
18
 
"""Tests specific to Branch implementations that use foreign VCS'es."""
19
 
 
20
 
 
21
 
from bzrlib.errors import (
22
 
    IncompatibleFormat,
23
 
    UnstackableBranchFormat,
24
 
    )
25
 
from bzrlib.revision import (
26
 
    NULL_REVISION,
27
 
    )
28
 
from bzrlib.tests import (
29
 
    TestCaseWithTransport,
30
 
    )
31
 
 
32
 
 
33
 
class ForeignBranchFactory(object):
34
 
    """Factory of branches for ForeignBranchTests."""
35
 
 
36
 
    def make_empty_branch(self, transport):
37
 
        """Create an empty branch with no commits in it."""
38
 
        raise NotImplementedError(self.make_empty_branch)
39
 
 
40
 
    def make_branch(self, transport):
41
 
        """Create *some* branch, may be empty or not."""
42
 
        return self.make_empty_branch(transport)
43
 
 
44
 
 
45
 
class ForeignBranchTests(TestCaseWithTransport):
46
 
    """Basic tests for foreign branch implementations.
47
 
    
48
 
    These tests mainly make sure that the implementation covers the required 
49
 
    bits of the API and returns reasonable values. 
50
 
    """
51
 
    branch_factory = None # Set to an instance of ForeignBranchFactory by scenario
52
 
 
53
 
    def make_empty_branch(self):
54
 
        return self.branch_factory.make_empty_branch(self.get_transport())
55
 
 
56
 
    def make_branch(self):
57
 
        return self.branch_factory.make_branch(self.get_transport())
58
 
 
59
 
    def test_set_parent(self):
60
 
        """Test that setting the parent works."""
61
 
        branch = self.make_branch()
62
 
        branch.set_parent("foobar")
63
 
 
64
 
    def test_set_push_location(self):
65
 
        """Test that setting the push location works."""
66
 
        branch = self.make_branch()
67
 
        branch.set_push_location("http://bar/bloe")
68
 
 
69
 
    def test_repr_type(self):
70
 
        branch = self.make_branch()
71
 
        self.assertIsInstance(repr(branch), str)
72
 
 
73
 
    def test_get_parent(self):
74
 
        """Test that getting the parent location works, and returns None."""
75
 
        # TODO: Allow this to be non-None when foreign branches add support 
76
 
        #       for storing this URL.
77
 
        branch = self.make_branch()
78
 
        self.assertIs(None, branch.get_parent())
79
 
 
80
 
    def test_get_push_location(self):
81
 
        """Test that getting the push location works, and returns None."""
82
 
        # TODO: Allow this to be non-None when foreign branches add support 
83
 
        #       for storing this URL.
84
 
        branch = self.make_branch()
85
 
        self.assertIs(None, branch.get_push_location())
86
 
 
87
 
    def test_attributes(self):
88
 
        """Check that various required attributes are present."""
89
 
        branch = self.make_branch()
90
 
        self.assertIsNot(None, getattr(branch, "repository", None))
91
 
        self.assertIsNot(None, getattr(branch, "mapping", None))
92
 
        self.assertIsNot(None, getattr(branch, "_format", None))
93
 
        self.assertIsNot(None, getattr(branch, "base", None))
94
 
 
95
 
    def test__get_nick(self):
96
 
        """Make sure _get_nick is implemented and returns a string."""
97
 
        branch = self.make_branch()
98
 
        self.assertIsInstance(branch._get_nick(local=False), str)
99
 
        self.assertIsInstance(branch._get_nick(local=True), str)
100
 
 
101
 
    def test_null_revid_revno(self):
102
 
        """null: should return revno 0."""
103
 
        branch = self.make_branch()
104
 
        self.assertEqual(0, branch.revision_id_to_revno(NULL_REVISION))
105
 
 
106
 
    def test_get_stacked_on_url(self):
107
 
        """Test that get_stacked_on_url() behaves as expected.
108
 
 
109
 
        Inter-Format stacking doesn't work yet, so all foreign implementations
110
 
        should raise UnstackableBranchFormat at the moment.
111
 
        """
112
 
        branch = self.make_branch()
113
 
        self.assertRaises(UnstackableBranchFormat, 
114
 
                          branch.get_stacked_on_url)
115
 
 
116
 
    def test_get_physical_lock_status(self):
117
 
        branch = self.make_branch()
118
 
        self.assertFalse(branch.get_physical_lock_status())
119
 
 
120
 
    def test_last_revision_empty_branch(self):
121
 
        branch = self.make_empty_branch()
122
 
        self.assertEqual(NULL_REVISION, branch.last_revision())
123
 
        self.assertEqual(0, branch.revno())
124
 
        self.assertEqual((0, NULL_REVISION), branch.last_revision_info())
125
 
 
126
 
 
127
 
class ForeignBranchFormatTests(TestCaseWithTransport):
128
 
    """Basic tests for foreign branch format objects."""
129
 
 
130
 
    branch_format = None # Set to a BranchFormat instance by adapter
131
 
 
132
 
    def test_initialize(self):
133
 
        """Test this format is not initializable.
134
 
        
135
 
        Remote branches may be initializable on their own, but none currently
136
 
        support living in .bzr/branch.
137
 
        """
138
 
        bzrdir = self.make_bzrdir('dir')
139
 
        self.assertRaises(IncompatibleFormat, self.branch_format.initialize, bzrdir)
140
 
 
141
 
    def test_get_format_description_type(self):
142
 
        self.assertIsInstance(self.branch_format.get_format_description(), str)
143
 
 
144
 
    def test_network_name(self):
145
 
        self.assertIsInstance(self.branch_format.network_name(), str)