/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

Remove last uses of the init= parameter to BzrBranch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Tests for the Branch facility that are not interface  tests.
 
18
 
 
19
For interface tests see test_branch_implementations.py.
 
20
 
 
21
For concrete class tests see this file, and for meta-branch tests
 
22
also see this file.
 
23
"""
 
24
 
 
25
 
 
26
import bzrlib.branch as branch
 
27
from bzrlib.errors import NotBranchError
 
28
from bzrlib.tests import TestCase, TestCaseInTempDir
 
29
from bzrlib.transport import get_transport
 
30
 
 
31
class TestDefaultFormat(TestCase):
 
32
 
 
33
    def test_get_set_default_initializer(self):
 
34
        old_initializer = branch.Branch.get_default_initializer()
 
35
        # default is BzrBranch._initialize
 
36
        self.assertEqual(branch.BzrBranch._initialize, old_initializer)
 
37
        def recorder(url):
 
38
            return "a branch %s" % url
 
39
        branch.Branch.set_default_initializer(recorder)
 
40
        try:
 
41
            b = branch.Branch.initialize("memory:/")
 
42
            self.assertEqual("a branch memory:/", b)
 
43
        finally:
 
44
            branch.Branch.set_default_initializer(old_initializer)
 
45
        self.assertEqual(old_initializer, branch.Branch.get_default_initializer())
 
46
 
 
47
 
 
48
class TestBzrBranchFormat(TestCaseInTempDir):
 
49
    """Tests for the BzrBranchFormat facility."""
 
50
 
 
51
    def test_find_format(self):
 
52
        # is the right format object found for a branch?
 
53
        # create a branch with a few known format objects.
 
54
        # this is not quite the same as 
 
55
        self.build_tree(["foo/", "bar/"])
 
56
        def check_format(format, url):
 
57
            format.initialize(url)
 
58
            t = get_transport(url)
 
59
            found_format = branch.BzrBranchFormat.find_format(t)
 
60
            self.failUnless(isinstance(found_format, format.__class__))
 
61
        check_format(branch.BzrBranchFormat5(), "foo")
 
62
        check_format(branch.BzrBranchFormat6(), "bar")
 
63
        
 
64
    def test_find_format_not_branch(self):
 
65
        self.assertRaises(NotBranchError,
 
66
                          branch.BzrBranchFormat.find_format,
 
67
                          get_transport('.'))