1
# Copyright (C) 2009, 2011, 2016 Canonical Ltd
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.
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.
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
18
"""Tests specific to Branch implementations that use foreign VCS'es."""
21
from bzrlib.errors import (
23
UnstackableBranchFormat,
25
from bzrlib.revision import (
28
from bzrlib.tests import (
29
TestCaseWithTransport,
33
class ForeignBranchFactory(object):
34
"""Factory of branches for ForeignBranchTests."""
36
def make_empty_branch(self, transport):
37
"""Create an empty branch with no commits in it."""
38
raise NotImplementedError(self.make_empty_branch)
40
def make_branch(self, transport):
41
"""Create *some* branch, may be empty or not."""
42
return self.make_empty_branch(transport)
45
class ForeignBranchTests(TestCaseWithTransport):
46
"""Basic tests for foreign branch implementations.
48
These tests mainly make sure that the implementation covers the required
49
bits of the API and returns reasonable values.
51
branch_factory = None # Set to an instance of ForeignBranchFactory by scenario
53
def make_empty_branch(self):
54
return self.branch_factory.make_empty_branch(self.get_transport())
56
def make_branch(self):
57
return self.branch_factory.make_branch(self.get_transport())
59
def test_set_parent(self):
60
"""Test that setting the parent works."""
61
branch = self.make_branch()
62
branch.set_parent("foobar")
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")
69
def test_repr_type(self):
70
branch = self.make_branch()
71
self.assertIsInstance(repr(branch), str)
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())
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())
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))
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)
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))
106
def test_get_stacked_on_url(self):
107
"""Test that get_stacked_on_url() behaves as expected.
109
Inter-Format stacking doesn't work yet, so all foreign implementations
110
should raise UnstackableBranchFormat at the moment.
112
branch = self.make_branch()
113
self.assertRaises(UnstackableBranchFormat,
114
branch.get_stacked_on_url)
116
def test_get_physical_lock_status(self):
117
branch = self.make_branch()
118
self.assertFalse(branch.get_physical_lock_status())
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())
127
class ForeignBranchFormatTests(TestCaseWithTransport):
128
"""Basic tests for foreign branch format objects."""
130
branch_format = None # Set to a BranchFormat instance by adapter
132
def test_initialize(self):
133
"""Test this format is not initializable.
135
Remote branches may be initializable on their own, but none currently
136
support living in .bzr/branch.
138
bzrdir = self.make_bzrdir('dir')
139
self.assertRaises(IncompatibleFormat, self.branch_format.initialize, bzrdir)
141
def test_get_format_description_type(self):
142
self.assertIsInstance(self.branch_format.get_format_description(), str)
144
def test_network_name(self):
145
self.assertIsInstance(self.branch_format.network_name(), str)