~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_repository/test_fetch.py

  • Committer: Patch Queue Manager
  • Date: 2016-02-01 19:56:05 UTC
  • mfrom: (6615.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20160201195605-o7rl92wf6uyum3fk
(vila) Open trunk again as 2.8b1 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tests for fetch between repositories of the same type."""
18
18
 
19
19
from bzrlib import (
20
 
    bzrdir,
 
20
    controldir,
21
21
    errors,
22
22
    gpg,
23
 
    graph,
24
23
    remote,
25
24
    repository,
26
 
    tests,
27
25
    )
28
26
from bzrlib.inventory import ROOT_ID
29
 
from bzrlib.tests import TestSkipped
 
27
from bzrlib.tests import (
 
28
    TestNotApplicable,
 
29
    TestSkipped,
 
30
    )
30
31
from bzrlib.tests.per_repository import TestCaseWithRepository
31
32
 
32
33
 
66
67
        tree_a.add('foo', 'file1')
67
68
        tree_a.commit('rev1', rev_id='rev1')
68
69
        # create a knit-3 based format to fetch into
69
 
        f = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
 
70
        f = controldir.format_registry.make_bzrdir('development-subtree')
70
71
        try:
71
72
            format = tree_a.branch.repository._format
72
73
            format.check_conversion_target(f.repository_format)
100
101
                              % b_bzrdir.transport)
101
102
        tree_b.commit('no change', rev_id='rev2')
102
103
        rev2_tree = knit3_repo.revision_tree('rev2')
103
 
        self.assertEqual('rev1', rev2_tree.inventory.root.revision)
 
104
        self.assertEqual(
 
105
            'rev1',
 
106
            rev2_tree.get_file_revision(rev2_tree.get_root_id()))
104
107
 
105
108
    def do_test_fetch_to_rich_root_sets_parents_correctly(self, result,
106
109
        snapshots, root_id=ROOT_ID, allow_lefthand_ghost=False):
135
138
        repo.lock_write()
136
139
        self.addCleanup(repo.unlock)
137
140
        repo.fetch(source.repository)
 
141
        graph = repo.get_file_graph()
138
142
        self.assertEqual(result,
139
 
            repo.texts.get_parent_map([(root_id, 'tip')])[(root_id, 'tip')])
 
143
            graph.get_parent_map([(root_id, 'tip')])[(root_id, 'tip')])
140
144
 
141
145
    def test_fetch_to_rich_root_set_parent_no_parents(self):
142
146
        # No parents rev -> No parents
154
158
 
155
159
    def test_fetch_to_rich_root_set_parent_1_ghost_parent(self):
156
160
        # 1 ghost parent -> No parents
 
161
        if not self.repository_format.supports_ghosts:
 
162
            raise TestNotApplicable("repository format does not support "
 
163
                 "ghosts")
157
164
        self.do_test_fetch_to_rich_root_sets_parents_correctly((),
158
165
            [('tip', ['ghost'], [('add', ('', ROOT_ID, 'directory', ''))]),
159
166
            ], allow_lefthand_ghost=True)
197
204
             ('base', None, []),
198
205
             ('tip', None, [('unversion', 'my-root'),
199
206
                            ('unversion', ROOT_ID),
 
207
                            ('flush', None),
200
208
                            ('add', ('', 'my-root', 'directory', '')),
201
209
                            ]),
202
210
            ], root_id='my-root')
225
233
            # 'my-root' at root
226
234
             ('right', None, [('unversion', 'my-root'),
227
235
                              ('unversion', ROOT_ID),
 
236
                              ('flush', None),
228
237
                              ('add', ('', 'my-root', 'directory', ''))]),
229
238
             ('tip', ['base', 'right'], [('unversion', 'my-root'),
230
239
                            ('unversion', ROOT_ID),
 
240
                            ('flush', None),
231
241
                            ('add', ('', 'my-root', 'directory', '')),
232
242
                            ]),
233
243
            ], root_id='my-root')
263
273
        repo = wt.branch.repository
264
274
        repo.lock_write()
265
275
        repo.start_write_group()
266
 
        repo.sign_revision('rev1', gpg.LoopbackGPGStrategy(None))
 
276
        try:
 
277
            repo.sign_revision('rev1', gpg.LoopbackGPGStrategy(None))
 
278
        except errors.UnsupportedOperation:
 
279
            self.assertFalse(repo._format.supports_revision_signatures)
 
280
            raise TestNotApplicable("repository format does not support signatures")
267
281
        repo.commit_write_group()
268
282
        repo.unlock()
269
283
        return repo
323
337
    def test_fetch_into_smart_with_ghost(self):
324
338
        trans = self.make_smart_server('target')
325
339
        source_b = self.make_simple_branch_with_ghost()
 
340
        if not source_b.bzrdir._format.supports_transport(trans):
 
341
            raise TestNotApplicable("format does not support transport")
326
342
        target = self.make_repository('target')
327
343
        # Re-open the repository over the smart protocol
328
344
        target = repository.Repository.open(trans.base)
334
350
            # The code inside fetch() that tries to lock and then fails, also
335
351
            # causes weird problems with 'lock_not_held' later on...
336
352
            target.lock_read()
337
 
            raise tests.KnownFailure('some repositories fail to fetch'
 
353
            self.knownFailure('some repositories fail to fetch'
338
354
                ' via the smart server because of locking issues.')
339
355
 
340
356
    def test_fetch_from_smart_with_ghost(self):
341
357
        trans = self.make_smart_server('source')
342
358
        source_b = self.make_simple_branch_with_ghost()
 
359
        if not source_b.bzrdir._format.supports_transport(trans):
 
360
            raise TestNotApplicable("format does not support transport")
343
361
        target = self.make_repository('target')
344
362
        target.lock_write()
345
363
        self.addCleanup(target.unlock)
349
367
        self.addCleanup(source.unlock)
350
368
        target.fetch(source, revision_id='B-id')
351
369
 
352
 
 
353
 
class TestSource(TestCaseWithRepository):
354
 
    """Tests for/about the results of Repository._get_source."""
355
 
 
356
 
    def test_no_absent_records_in_stream_with_ghosts(self):
357
 
        # XXX: Arguably should be in per_interrepository but
358
 
        # doesn't actually gain coverage there; need a specific set of
359
 
        # permutations to cover it.
360
 
        # bug lp:376255 was reported about this.
361
 
        builder = self.make_branch_builder('repo')
362
 
        builder.start_series()
363
 
        builder.build_snapshot('tip', ['ghost'],
364
 
            [('add', ('', 'ROOT_ID', 'directory', ''))],
365
 
            allow_leftmost_as_ghost=True)
366
 
        builder.finish_series()
367
 
        b = builder.get_branch()
368
 
        b.lock_read()
369
 
        self.addCleanup(b.unlock)
370
 
        repo = b.repository
371
 
        source = repo._get_source(repo._format)
372
 
        search = graph.PendingAncestryResult(['tip'], repo)
373
 
        stream = source.get_stream(search)
374
 
        for substream_type, substream in stream:
375
 
            for record in substream:
376
 
                self.assertNotEqual('absent', record.storage_kind,
377
 
                    "Absent record for %s" % (((substream_type,) + record.key),))