1113
1114
b = bzrdir.BzrDir.create(urlutils.local_path_to_url('.'))
1114
1115
self.build_tree(['a'])
1115
1116
self.assertEquals(['a'], self.get_ls())
1119
class _TestBzrDirFormat(bzrdir.BzrDirMetaFormat1):
1120
"""Test BzrDirFormat implementation for TestBzrDirSprout."""
1122
def _open(self, transport):
1123
return _TestBzrDir(transport, self)
1126
class _TestBzrDir(bzrdir.BzrDirMeta1):
1127
"""Test BzrDir implementation for TestBzrDirSprout.
1129
When created a _TestBzrDir already has repository and a branch. The branch
1130
is a test double as well.
1133
def __init__(self, *args, **kwargs):
1134
super(_TestBzrDir, self).__init__(*args, **kwargs)
1135
self.test_branch = _TestBranch()
1136
self.test_branch.repository = self.create_repository()
1138
def open_branch(self, unsupported=False):
1139
return self.test_branch
1141
def cloning_metadir(self):
1142
return _TestBzrDirFormat()
1145
class _TestBranch(bzrlib.branch.Branch):
1146
"""Test Branch implementation for TestBzrDirSprout."""
1148
def __init__(self, *args, **kwargs):
1149
super(_TestBranch, self).__init__(*args, **kwargs)
1152
def sprout(self, *args, **kwargs):
1153
self.calls.append('sprout')
1156
class TestBzrDirSprout(TestCaseWithMemoryTransport):
1158
def test_sprout_uses_branch_sprout(self):
1159
"""BzrDir.sprout calls Branch.sprout.
1161
Usually, BzrDir.sprout should delegate to the branch's sprout method
1162
for part of the work. This allows the source branch to control the
1163
choice of format for the new branch.
1165
There are exceptions, but this tests avoids them:
1166
- if there's no branch in the source bzrdir,
1167
- or if the stacking has been requested and the format needs to be
1168
overridden to satisfy that.
1170
# Make an instrumented bzrdir.
1171
t = self.get_transport('source')
1173
source_bzrdir = _TestBzrDirFormat().initialize_on_transport(t)
1174
# The instrumented bzrdir has a test_branch attribute that logs calls
1175
# made to the branch contained in that bzrdir. Initially the test
1176
# branch exists but no calls have been made to it.
1177
self.assertEqual([], source_bzrdir.test_branch.calls)
1180
target_url = self.get_url('target')
1181
result = source_bzrdir.sprout(target_url, recurse='no')
1183
# The bzrdir called the branch's sprout method.
1184
self.assertEqual(['sprout'], source_bzrdir.test_branch.calls)