~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_interbranch/__init__.py

Simplify interbranch test base class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
"""
26
26
 
27
27
 
 
28
from bzrlib import (
 
29
    memorytree,
 
30
    )
28
31
from bzrlib.branch import (
29
32
                           GenericInterBranch,
30
33
                           InterBranch,
31
34
                           )
32
35
from bzrlib.errors import (
33
36
    FileExists,
 
37
    NotBranchError,
34
38
    UninitializableFormat,
35
39
    )
36
40
from bzrlib.tests import multiply_tests
37
 
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
 
41
from bzrlib.tests import TestCaseWithTransport
38
42
from bzrlib.transport import get_transport
39
43
 
40
44
 
75
79
    return result
76
80
 
77
81
 
78
 
class TestCaseWithInterBranch(TestCaseWithBzrDir):
 
82
class TestCaseWithInterBranch(TestCaseWithTransport):
79
83
 
80
84
    def setUp(self):
81
85
        super(TestCaseWithInterBranch, self).setUp()
82
86
 
83
 
    def make_branch(self, relpath, format=None):
84
 
        repo = self.make_repository(relpath, format=format)
85
 
        return repo.bzrdir.create_branch()
86
 
 
87
 
    def make_bzrdir(self, relpath, format=None):
88
 
        try:
89
 
            url = self.get_url(relpath)
90
 
            segments = url.split('/')
91
 
            if segments and segments[-1] not in ('', '.'):
92
 
                parent = '/'.join(segments[:-1])
93
 
                t = get_transport(parent)
94
 
                try:
95
 
                    t.mkdir(segments[-1])
96
 
                except FileExists:
97
 
                    pass
98
 
            if format is None:
99
 
                format = self.branch_format_from._matchingbzrdir
100
 
            return format.initialize(url)
101
 
        except UninitializableFormat:
102
 
            raise TestSkipped("Format %s is not initializable." % format)
103
 
 
104
 
    def make_repository(self, relpath, format=None):
105
 
        made_control = self.make_bzrdir(relpath, format=format)
106
 
        return made_control.create_repository()
107
 
 
108
 
    def make_to_bzrdir(self, relpath):
109
 
        return self.make_bzrdir(relpath,
110
 
            self.branch_format_to._matchingbzrdir)
 
87
    def make_from_branch(self, relpath):
 
88
        repo = self.make_repository(relpath)
 
89
        return self.branch_format_from.initialize(repo.bzrdir)
 
90
 
 
91
    def make_from_branch_and_memory_tree(self, relpath):
 
92
        """Create a branch on the default transport and a MemoryTree for it."""
 
93
        b = self.make_from_branch(relpath)
 
94
        return memorytree.MemoryTree.create_on_branch(b)
 
95
 
 
96
    def make_from_branch_and_tree(self, relpath):
 
97
        """Create a branch on the default transport and a working tree for it."""
 
98
        b = self.make_from_branch(relpath)
 
99
        return b.bzrdir.create_workingtree()
111
100
 
112
101
    def make_to_branch(self, relpath):
113
 
        made_control = self.make_to_bzrdir(relpath)
114
 
        return self.branch_format_to.initialize(made_control)
 
102
        repo = self.make_repository(relpath)
 
103
        return self.branch_format_to.initialize(repo.bzrdir)
 
104
 
 
105
    def make_to_branch_and_memory_tree(self, relpath):
 
106
        """Create a branch on the default transport and a MemoryTree for it."""
 
107
        b = self.make_to_branch(relpath)
 
108
        return memorytree.MemoryTree.create_on_branch(b)
 
109
 
 
110
    def sprout_to(self, origdir, to_url):
 
111
        """Sprout a bzrdir, using to_format for the new bzrdir."""
 
112
        newbranch = self.make_to_branch(to_url)
 
113
        origdir.open_branch().copy_content_into(newbranch)
 
114
        newbranch.bzrdir.create_workingtree()
 
115
        return newbranch.bzrdir
115
116
 
116
117
 
117
118
def load_tests(standard_tests, module, loader):