~amanica/bzr/320119-log_exclusive_lower_bound

« back to all changes in this revision

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

  • Committer: Johan Walles
  • Date: 2009-05-06 05:36:28 UTC
  • mfrom: (4332 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4343.
  • Revision ID: johan.walles@gmail.com-20090506053628-tbf1wz4a0m9t684g
MergeĀ fromĀ upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
"""
26
26
 
27
27
 
 
28
from bzrlib import (
 
29
    branchbuilder,
 
30
    memorytree,
 
31
    )
28
32
from bzrlib.branch import (
29
33
                           GenericInterBranch,
30
34
                           InterBranch,
31
35
                           )
 
36
from bzrlib.bzrdir import (
 
37
    BzrDirFormat,
 
38
    BzrDirMetaFormat1,
 
39
    )
32
40
from bzrlib.errors import (
33
41
    FileExists,
 
42
    NotBranchError,
34
43
    UninitializableFormat,
35
44
    )
36
 
from bzrlib.tests import multiply_tests
37
 
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
 
45
from bzrlib.tests import (
 
46
    TestCaseWithTransport,
 
47
    multiply_tests,
 
48
    )
38
49
from bzrlib.transport import get_transport
39
50
 
40
51
 
75
86
    return result
76
87
 
77
88
 
78
 
class TestCaseWithInterBranch(TestCaseWithBzrDir):
79
 
 
80
 
    def setUp(self):
81
 
        super(TestCaseWithInterBranch, self).setUp()
82
 
 
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)
 
89
class TestCaseWithInterBranch(TestCaseWithTransport):
 
90
 
 
91
    def make_from_branch(self, relpath):
 
92
        repo = self.make_repository(relpath)
 
93
        return self.branch_format_from.initialize(repo.bzrdir)
 
94
 
 
95
    def make_from_branch_and_memory_tree(self, relpath):
 
96
        """Create a branch on the default transport and a MemoryTree for it."""
 
97
        b = self.make_from_branch(relpath)
 
98
        return memorytree.MemoryTree.create_on_branch(b)
 
99
 
 
100
    def make_from_branch_and_tree(self, relpath):
 
101
        """Create a branch on the default transport and a working tree for it."""
 
102
        b = self.make_from_branch(relpath)
 
103
        return b.bzrdir.create_workingtree()
 
104
 
 
105
    def make_from_branch_builder(self, relpath):
 
106
        default_format = BzrDirFormat.get_default_format()
 
107
        format = BzrDirMetaFormat1()
 
108
        format.set_branch_format(self.branch_format_from)
 
109
        format.repository_format = default_format.repository_format
 
110
        format.workingtree_format = default_format.workingtree_format
 
111
        return branchbuilder.BranchBuilder(self.get_transport(relpath),
 
112
            format=format)
111
113
 
112
114
    def make_to_branch(self, relpath):
113
 
        made_control = self.make_to_bzrdir(relpath)
114
 
        return self.branch_format_to.initialize(made_control)
 
115
        repo = self.make_repository(relpath)
 
116
        return self.branch_format_to.initialize(repo.bzrdir)
 
117
 
 
118
    def make_to_branch_and_memory_tree(self, relpath):
 
119
        """Create a branch on the default transport and a MemoryTree for it."""
 
120
        b = self.make_to_branch(relpath)
 
121
        return memorytree.MemoryTree.create_on_branch(b)
 
122
 
 
123
    def make_to_branch_and_tree(self, relpath):
 
124
        """Create a branch on the default transport and a working tree for it."""
 
125
        b = self.make_to_branch(relpath)
 
126
        return b.bzrdir.create_workingtree()
 
127
 
 
128
    def sprout_to(self, origdir, to_url):
 
129
        """Sprout a bzrdir, using to_format for the new branch."""
 
130
        newbranch = self.make_to_branch(to_url)
 
131
        origbranch = origdir.open_branch()
 
132
        newbranch.repository.fetch(origbranch.repository)
 
133
        origbranch.copy_content_into(newbranch)
 
134
        newbranch.bzrdir.create_workingtree()
 
135
        return newbranch.bzrdir
 
136
 
 
137
    def sprout_from(self, origdir, to_url):
 
138
        """Sprout a bzrdir, using from_format for the new bzrdir."""
 
139
        newbranch = self.make_from_branch(to_url)
 
140
        origbranch = origdir.open_branch()
 
141
        newbranch.repository.fetch(origbranch.repository)
 
142
        origbranch.copy_content_into(newbranch)
 
143
        newbranch.bzrdir.create_workingtree()
 
144
        return newbranch.bzrdir
 
145
 
 
146
 
115
147
 
116
148
 
117
149
def load_tests(standard_tests, module, loader):
118
150
    submod_tests = loader.loadTestsFromModuleNames([
 
151
        'bzrlib.tests.per_interbranch.test_push',
119
152
        'bzrlib.tests.per_interbranch.test_update_revisions',
120
153
        ])
121
154
    scenarios = make_scenarios(default_test_list())