~bzr-pqm/bzr/bzr.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Copyright (C) 2009, 2011, 2016 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA


"""Tests specific to Branch implementations that use foreign VCS'es."""


from bzrlib.errors import (
    IncompatibleFormat,
    UnstackableBranchFormat,
    )
from bzrlib.revision import (
    NULL_REVISION,
    )
from bzrlib.tests import (
    TestCaseWithTransport,
    )


class ForeignBranchFactory(object):
    """Factory of branches for ForeignBranchTests."""

    def make_empty_branch(self, transport):
        """Create an empty branch with no commits in it."""
        raise NotImplementedError(self.make_empty_branch)

    def make_branch(self, transport):
        """Create *some* branch, may be empty or not."""
        return self.make_empty_branch(transport)


class ForeignBranchTests(TestCaseWithTransport):
    """Basic tests for foreign branch implementations.
    
    These tests mainly make sure that the implementation covers the required 
    bits of the API and returns reasonable values. 
    """
    branch_factory = None # Set to an instance of ForeignBranchFactory by scenario

    def make_empty_branch(self):
        return self.branch_factory.make_empty_branch(self.get_transport())

    def make_branch(self):
        return self.branch_factory.make_branch(self.get_transport())

    def test_set_parent(self):
        """Test that setting the parent works."""
        branch = self.make_branch()
        branch.set_parent("foobar")

    def test_set_push_location(self):
        """Test that setting the push location works."""
        branch = self.make_branch()
        branch.set_push_location("http://bar/bloe")

    def test_repr_type(self):
        branch = self.make_branch()
        self.assertIsInstance(repr(branch), str)

    def test_get_parent(self):
        """Test that getting the parent location works, and returns None."""
        # TODO: Allow this to be non-None when foreign branches add support 
        #       for storing this URL.
        branch = self.make_branch()
        self.assertIs(None, branch.get_parent())

    def test_get_push_location(self):
        """Test that getting the push location works, and returns None."""
        # TODO: Allow this to be non-None when foreign branches add support 
        #       for storing this URL.
        branch = self.make_branch()
        self.assertIs(None, branch.get_push_location())

    def test_attributes(self):
        """Check that various required attributes are present."""
        branch = self.make_branch()
        self.assertIsNot(None, getattr(branch, "repository", None))
        self.assertIsNot(None, getattr(branch, "mapping", None))
        self.assertIsNot(None, getattr(branch, "_format", None))
        self.assertIsNot(None, getattr(branch, "base", None))

    def test__get_nick(self):
        """Make sure _get_nick is implemented and returns a string."""
        branch = self.make_branch()
        self.assertIsInstance(branch._get_nick(local=False), str)
        self.assertIsInstance(branch._get_nick(local=True), str)

    def test_null_revid_revno(self):
        """null: should return revno 0."""
        branch = self.make_branch()
        self.assertEqual(0, branch.revision_id_to_revno(NULL_REVISION))

    def test_get_stacked_on_url(self):
        """Test that get_stacked_on_url() behaves as expected.

        Inter-Format stacking doesn't work yet, so all foreign implementations
        should raise UnstackableBranchFormat at the moment.
        """
        branch = self.make_branch()
        self.assertRaises(UnstackableBranchFormat, 
                          branch.get_stacked_on_url)

    def test_get_physical_lock_status(self):
        branch = self.make_branch()
        self.assertFalse(branch.get_physical_lock_status())

    def test_last_revision_empty_branch(self):
        branch = self.make_empty_branch()
        self.assertEqual(NULL_REVISION, branch.last_revision())
        self.assertEqual(0, branch.revno())
        self.assertEqual((0, NULL_REVISION), branch.last_revision_info())


class ForeignBranchFormatTests(TestCaseWithTransport):
    """Basic tests for foreign branch format objects."""

    branch_format = None # Set to a BranchFormat instance by adapter

    def test_initialize(self):
        """Test this format is not initializable.
        
        Remote branches may be initializable on their own, but none currently
        support living in .bzr/branch.
        """
        bzrdir = self.make_bzrdir('dir')
        self.assertRaises(IncompatibleFormat, self.branch_format.initialize, bzrdir)

    def test_get_format_description_type(self):
        self.assertIsInstance(self.branch_format.get_format_description(), str)

    def test_network_name(self):
        self.assertIsInstance(self.branch_format.network_name(), str)