~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Martin Pool
  • Date: 2009-09-14 01:48:28 UTC
  • mfrom: (4685 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4688.
  • Revision ID: mbp@sourcefrog.net-20090914014828-ydr9rlkdfq2sv57z
Merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    smart,
37
37
    tests,
38
38
    urlutils,
 
39
    versionedfile,
39
40
    )
40
41
from bzrlib.branch import Branch, BranchReferenceFormat
41
42
import bzrlib.smart.branch
87
88
        if self._chroot_server is None:
88
89
            backing_transport = tests.TestCaseWithTransport.get_transport(self)
89
90
            self._chroot_server = chroot.ChrootServer(backing_transport)
90
 
            self._chroot_server.setUp()
91
 
            self.addCleanup(self._chroot_server.tearDown)
 
91
            self.start_server(self._chroot_server)
92
92
        t = get_transport(self._chroot_server.get_url())
93
93
        if relpath is not None:
94
94
            t = t.clone(relpath)
113
113
        return self.get_transport().get_smart_medium()
114
114
 
115
115
 
 
116
class TestByteStreamToStream(tests.TestCase):
 
117
 
 
118
    def test_repeated_substreams_same_kind_are_one_stream(self):
 
119
        # Make a stream - an iterable of bytestrings.
 
120
        stream = [('text', [versionedfile.FulltextContentFactory(('k1',), None,
 
121
            None, 'foo')]),('text', [
 
122
            versionedfile.FulltextContentFactory(('k2',), None, None, 'bar')])]
 
123
        fmt = bzrdir.format_registry.get('pack-0.92')().repository_format
 
124
        bytes = smart.repository._stream_to_byte_stream(stream, fmt)
 
125
        streams = []
 
126
        # Iterate the resulting iterable; checking that we get only one stream
 
127
        # out.
 
128
        fmt, stream = smart.repository._byte_stream_to_stream(bytes)
 
129
        for kind, substream in stream:
 
130
            streams.append((kind, list(substream)))
 
131
        self.assertLength(1, streams)
 
132
        self.assertLength(2, streams[0][1])
 
133
 
 
134
 
116
135
class TestSmartServerResponse(tests.TestCase):
117
136
 
118
137
    def test__eq__(self):
202
221
        self.make_bzrdir('.')
203
222
        request_class = bzrlib.smart.bzrdir.SmartServerRequestCreateRepository
204
223
        request = request_class(backing)
205
 
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
 
224
        reference_bzrdir_format = bzrdir.format_registry.get('pack-0.92')()
206
225
        reference_format = reference_bzrdir_format.repository_format
207
226
        network_name = reference_format.network_name()
208
227
        expected = SuccessfulSmartServerResponse(
247
266
            subtrees = 'yes'
248
267
        else:
249
268
            subtrees = 'no'
 
269
        if repo._format.supports_external_lookups:
 
270
            external = 'yes'
 
271
        else:
 
272
            external = 'no'
250
273
        if (smart.bzrdir.SmartServerRequestFindRepositoryV3 ==
251
274
            self._request_class):
252
275
            return SuccessfulSmartServerResponse(
253
 
                ('ok', '', rich_root, subtrees, 'no',
 
276
                ('ok', '', rich_root, subtrees, external,
254
277
                 repo._format.network_name()))
255
278
        elif (smart.bzrdir.SmartServerRequestFindRepositoryV2 ==
256
279
            self._request_class):
257
280
            # All tests so far are on formats, and for non-external
258
281
            # repositories.
259
282
            return SuccessfulSmartServerResponse(
260
 
                ('ok', '', rich_root, subtrees, 'no'))
 
283
                ('ok', '', rich_root, subtrees, external))
261
284
        else:
262
285
            return SuccessfulSmartServerResponse(('ok', '', rich_root, subtrees))
263
286
 
452
475
    def test_stacked_branch(self):
453
476
        """Opening a stacked branch does not open the stacked-on branch."""
454
477
        trunk = self.make_branch('trunk')
455
 
        feature = self.make_branch('feature', format='1.9')
 
478
        feature = self.make_branch('feature')
456
479
        feature.set_stacked_on_url(trunk.base)
457
480
        opened_branches = []
458
481
        Branch.hooks.install_named_hook('open', opened_branches.append, None)
1242
1265
            SmartServerResponse(('history-incomplete', 2, r2)),
1243
1266
            request.execute('stacked', 1, (3, r3)))
1244
1267
 
 
1268
 
1245
1269
class TestSmartServerRepositoryGetStream(tests.TestCaseWithMemoryTransport):
1246
1270
 
1247
1271
    def make_two_commit_repo(self):