~bzr-pqm/bzr/bzr.dev

6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2009, 2011, 2016 Canonical Ltd
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
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
4585.1.3 by Jelmer Vernooij
Add last_revision test.
17
18
"""Tests specific to Branch implementations that use foreign VCS'es."""
19
20
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
21
from bzrlib.errors import (
5699.3.1 by Jelmer Vernooij
Require foreign branch formats to raise IncompatibleFormat for bzr dirs.
22
    IncompatibleFormat,
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
23
    UnstackableBranchFormat,
24
    )
25
from bzrlib.revision import (
26
    NULL_REVISION,
27
    )
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
28
from bzrlib.tests import (
4585.1.8 by Jelmer Vernooij
Make branch formats provide a factory for particular situations.
29
    TestCaseWithTransport,
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
30
    )
31
32
33
class ForeignBranchFactory(object):
34
    """Factory of branches for ForeignBranchTests."""
35
4585.1.8 by Jelmer Vernooij
Make branch formats provide a factory for particular situations.
36
    def make_empty_branch(self, transport):
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
37
        """Create an empty branch with no commits in it."""
38
        raise NotImplementedError(self.make_empty_branch)
39
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
40
    def make_branch(self, transport):
41
        """Create *some* branch, may be empty or not."""
42
        return self.make_empty_branch(transport)
43
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
44
4585.1.8 by Jelmer Vernooij
Make branch formats provide a factory for particular situations.
45
class ForeignBranchTests(TestCaseWithTransport):
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
46
    """Basic tests for foreign branch implementations.
47
    
4585.1.3 by Jelmer Vernooij
Add last_revision test.
48
    These tests mainly make sure that the implementation covers the required 
49
    bits of the API and returns reasonable values. 
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
50
    """
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
51
    branch_factory = None # Set to an instance of ForeignBranchFactory by scenario
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
52
4585.1.8 by Jelmer Vernooij
Make branch formats provide a factory for particular situations.
53
    def make_empty_branch(self):
54
        return self.branch_factory.make_empty_branch(self.get_transport())
55
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
56
    def make_branch(self):
57
        return self.branch_factory.make_branch(self.get_transport())
58
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
59
    def test_set_parent(self):
60
        """Test that setting the parent works."""
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
61
        branch = self.make_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
62
        branch.set_parent("foobar")
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
63
64
    def test_set_push_location(self):
65
        """Test that setting the push location works."""
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
66
        branch = self.make_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
67
        branch.set_push_location("http://bar/bloe")
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
68
69
    def test_repr_type(self):
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
70
        branch = self.make_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
71
        self.assertIsInstance(repr(branch), str)
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
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.
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
77
        branch = self.make_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
78
        self.assertIs(None, branch.get_parent())
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
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.
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
84
        branch = self.make_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
85
        self.assertIs(None, branch.get_push_location())
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
86
87
    def test_attributes(self):
88
        """Check that various required attributes are present."""
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
89
        branch = self.make_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
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))
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
94
95
    def test__get_nick(self):
96
        """Make sure _get_nick is implemented and returns a string."""
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
97
        branch = self.make_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
98
        self.assertIsInstance(branch._get_nick(local=False), str)
99
        self.assertIsInstance(branch._get_nick(local=True), str)
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
100
101
    def test_null_revid_revno(self):
102
        """null: should return revno 0."""
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
103
        branch = self.make_branch()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
104
        self.assertEqual(0, branch.revision_id_to_revno(NULL_REVISION))
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
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
        """
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
112
        branch = self.make_branch()
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
113
        self.assertRaises(UnstackableBranchFormat, 
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
114
                          branch.get_stacked_on_url)
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
115
4585.1.2 by Jelmer Vernooij
Add physical lock status test.
116
    def test_get_physical_lock_status(self):
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
117
        branch = self.make_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
118
        self.assertFalse(branch.get_physical_lock_status())
119
120
    def test_last_revision_empty_branch(self):
4585.1.8 by Jelmer Vernooij
Make branch formats provide a factory for particular situations.
121
        branch = self.make_empty_branch()
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
122
        self.assertEqual(NULL_REVISION, branch.last_revision())
123
        self.assertEqual(0, branch.revno())
124
        self.assertEqual((0, NULL_REVISION), branch.last_revision_info())
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
125
126
5699.3.1 by Jelmer Vernooij
Require foreign branch formats to raise IncompatibleFormat for bzr dirs.
127
class ForeignBranchFormatTests(TestCaseWithTransport):
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
128
    """Basic tests for foreign branch format objects."""
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
129
130
    branch_format = None # Set to a BranchFormat instance by adapter
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
131
132
    def test_initialize(self):
4585.1.2 by Jelmer Vernooij
Add physical lock status test.
133
        """Test this format is not initializable.
134
        
4585.1.3 by Jelmer Vernooij
Add last_revision test.
135
        Remote branches may be initializable on their own, but none currently
136
        support living in .bzr/branch.
4585.1.2 by Jelmer Vernooij
Add physical lock status test.
137
        """
5699.3.1 by Jelmer Vernooij
Require foreign branch formats to raise IncompatibleFormat for bzr dirs.
138
        bzrdir = self.make_bzrdir('dir')
139
        self.assertRaises(IncompatibleFormat, self.branch_format.initialize, bzrdir)
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
140
141
    def test_get_format_description_type(self):
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
142
        self.assertIsInstance(self.branch_format.get_format_description(), str)
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
143
144
    def test_network_name(self):
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
145
        self.assertIsInstance(self.branch_format.network_name(), str)