/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
1
# Copyright (C) 2009 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
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 (
22
    UnstackableBranchFormat,
23
    )
24
from bzrlib.revision import (
25
    NULL_REVISION,
26
    )
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
27
from bzrlib.tests import (
28
    TestCase,
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_break_lock(self):
65
        """Test that break_lock() works, even if it is a no-op."""
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.break_lock()
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
68
69
    def test_set_push_location(self):
70
        """Test that setting the push location works."""
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
71
        branch = self.make_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
72
        branch.set_push_location("http://bar/bloe")
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
73
74
    def test_repr_type(self):
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
75
        branch = self.make_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
76
        self.assertIsInstance(repr(branch), str)
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
77
78
    def test_get_parent(self):
79
        """Test that getting the parent location works, and returns None."""
80
        # TODO: Allow this to be non-None when foreign branches add support 
81
        #       for storing this URL.
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
82
        branch = self.make_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
83
        self.assertIs(None, branch.get_parent())
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
84
85
    def test_get_push_location(self):
86
        """Test that getting the push location works, and returns None."""
87
        # TODO: Allow this to be non-None when foreign branches add support 
88
        #       for storing this URL.
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.assertIs(None, branch.get_push_location())
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
91
92
    def test_attributes(self):
93
        """Check that various required attributes are present."""
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
94
        branch = self.make_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
95
        self.assertIsNot(None, getattr(branch, "repository", None))
96
        self.assertIsNot(None, getattr(branch, "mapping", None))
97
        self.assertIsNot(None, getattr(branch, "_format", None))
98
        self.assertIsNot(None, getattr(branch, "base", None))
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
99
100
    def test__get_nick(self):
101
        """Make sure _get_nick is implemented and returns a string."""
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
102
        branch = self.make_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
103
        self.assertIsInstance(branch._get_nick(local=False), str)
104
        self.assertIsInstance(branch._get_nick(local=True), str)
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
105
106
    def test_null_revid_revno(self):
107
        """null: should return revno 0."""
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
108
        branch = self.make_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
109
        self.assertEquals(0, branch.revision_id_to_revno(NULL_REVISION))
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
110
111
    def test_get_stacked_on_url(self):
112
        """Test that get_stacked_on_url() behaves as expected.
113
114
        Inter-Format stacking doesn't work yet, so all foreign implementations
115
        should raise UnstackableBranchFormat at the moment.
116
        """
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
117
        branch = self.make_branch()
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
118
        self.assertRaises(UnstackableBranchFormat, 
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
119
                          branch.get_stacked_on_url)
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
120
4585.1.2 by Jelmer Vernooij
Add physical lock status test.
121
    def test_get_physical_lock_status(self):
4585.1.9 by Jelmer Vernooij
Distinguish between "some branch" and empty branches.
122
        branch = self.make_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
123
        self.assertFalse(branch.get_physical_lock_status())
124
125
    def test_last_revision_empty_branch(self):
4585.1.8 by Jelmer Vernooij
Make branch formats provide a factory for particular situations.
126
        branch = self.make_empty_branch()
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
127
        self.assertEquals(NULL_REVISION, branch.last_revision())
128
        self.assertEquals(0, branch.revno())
129
        self.assertEquals((0, NULL_REVISION), branch.last_revision_info())
130
131
132
class ForeignBranchFormatTests(TestCase):
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
133
    """Basic tests for foreign branch format objects."""
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
134
135
    branch_format = None # Set to a BranchFormat instance by adapter
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
136
137
    def test_initialize(self):
4585.1.2 by Jelmer Vernooij
Add physical lock status test.
138
        """Test this format is not initializable.
139
        
4585.1.3 by Jelmer Vernooij
Add last_revision test.
140
        Remote branches may be initializable on their own, but none currently
141
        support living in .bzr/branch.
4585.1.2 by Jelmer Vernooij
Add physical lock status test.
142
        """
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
143
        self.assertRaises(NotImplementedError, self.branch_format.initialize, None)
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
144
145
    def test_get_format_description_type(self):
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
146
        self.assertIsInstance(self.branch_format.get_format_description(), str)
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
147
148
    def test_network_name(self):
4585.1.7 by Jelmer Vernooij
Use scenarios and adapters.
149
        self.assertIsInstance(self.branch_format.network_name(), str)
4585.1.1 by Jelmer Vernooij
Add foreign branch tests.
150
151