/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/per_workingtree/test_parents.py

  • Committer: Jelmer Vernooij
  • Date: 2018-03-24 17:48:04 UTC
  • mfrom: (6921 work)
  • mto: This revision was merged to the branch mainline in revision 6923.
  • Revision ID: jelmer@jelmer.uk-20180324174804-xf22o05byoj12x1q
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    InventoryDirectory,
29
29
    InventoryLink,
30
30
    )
31
 
from ...bzr.inventorytree import InventoryRevisionTree
 
31
from ...bzr.inventorytree import (
 
32
    InventoryRevisionTree,
 
33
    InventoryTree,
 
34
    )
32
35
from ...sixish import (
33
36
    BytesIO,
34
37
    )
 
38
from ...tests import TestNotApplicable
35
39
from ..per_workingtree import TestCaseWithWorkingTree
36
40
from .. import (
37
41
    features,
102
106
        # remove the tree's history
103
107
        uncommit(t.branch, tree=t)
104
108
        rev_tree = t.branch.repository.revision_tree(revision_in_repo)
105
 
        t.set_parent_trees([(revision_in_repo, rev_tree),
106
 
            ('another-missing', None)])
107
 
        self.assertConsistentParents([revision_in_repo, 'another-missing'], t)
 
109
        if t._format.supports_righthand_parent_id_as_ghost:
 
110
            t.set_parent_trees([(revision_in_repo, rev_tree),
 
111
                ('another-missing', None)])
 
112
            self.assertConsistentParents([revision_in_repo, 'another-missing'], t)
 
113
        else:
 
114
            self.assertRaises(errors.GhostRevisionUnusableHere,
 
115
                t.set_parent_trees, [(revision_in_repo, rev_tree),
 
116
                ('another-missing', None)])
108
117
 
109
118
    def test_set_three_parents(self):
110
119
        t = self.make_branch_and_tree('.')
154
163
        # remove the tree's history
155
164
        uncommit(t.branch, tree=t)
156
165
        rev_tree = t.branch.repository.revision_tree(revision_in_repo)
157
 
        t.set_parent_ids([revision_in_repo, 'another-missing'])
158
 
        self.assertConsistentParents([revision_in_repo, 'another-missing'], t)
 
166
        if t._format.supports_righthand_parent_id_as_ghost:
 
167
            t.set_parent_ids([revision_in_repo, 'another-missing'])
 
168
            self.assertConsistentParents([revision_in_repo, 'another-missing'], t)
 
169
        else:
 
170
            self.assertRaises(errors.GhostRevisionUnusableHere,
 
171
                t.set_parent_ids, [revision_in_repo, 'another-missing'])
159
172
 
160
173
    def test_set_three_parents_ids(self):
161
174
        t = self.make_branch_and_tree('.')
316
329
        """Test adding the second parent id - as a ghost"""
317
330
        tree = self.make_branch_and_tree('.')
318
331
        first_revision = tree.commit('first post')
319
 
        tree.add_parent_tree_id('second')
320
 
        self.assertConsistentParents([first_revision, 'second'], tree)
 
332
        if tree._format.supports_righthand_parent_id_as_ghost:
 
333
            tree.add_parent_tree_id('second')
 
334
            self.assertConsistentParents([first_revision, 'second'], tree)
 
335
        else:
 
336
            self.assertRaises(errors.GhostRevisionUnusableHere,
 
337
                    tree.add_parent_tree_id, 'second')
321
338
 
322
339
    def test_add_first_parent_tree(self):
323
340
        """Test adding the first parent id"""
360
377
        """Test adding the second parent id - as a ghost"""
361
378
        tree = self.make_branch_and_tree('.')
362
379
        first_revision = tree.commit('first post')
363
 
        tree.add_parent_tree(('second', None))
364
 
        self.assertConsistentParents([first_revision, 'second'], tree)
 
380
        if tree._format.supports_righthand_parent_id_as_ghost:
 
381
            tree.add_parent_tree(('second', None))
 
382
            self.assertConsistentParents([first_revision, 'second'], tree)
 
383
        else:
 
384
            self.assertRaises(errors.GhostRevisionUnusableHere,
 
385
                    tree.add_parent_tree, ('second', None))
365
386
 
366
387
 
367
388
class UpdateToOneParentViaDeltaTests(TestCaseWithWorkingTree):
375
396
 
376
397
    def assertDeltaApplicationResultsInExpectedBasis(self, tree, revid, delta,
377
398
        expected_inventory):
378
 
        tree.lock_write()
379
 
        try:
 
399
        with tree.lock_write():
380
400
            tree.update_basis_by_delta(revid, delta)
381
 
        finally:
382
 
            tree.unlock()
383
401
        # check the last revision was adjusted to rev_id
384
402
        self.assertEqual(revid, tree.last_revision())
385
403
        # check the parents are what we expect
387
405
        # check that the basis tree has the inventory we expect from applying
388
406
        # the delta.
389
407
        result_basis = tree.basis_tree()
390
 
        result_basis.lock_read()
391
 
        try:
 
408
        with result_basis.lock_read():
392
409
            self.assertEqual(expected_inventory, result_basis.root_inventory)
393
 
        finally:
394
 
            result_basis.unlock()
395
410
 
396
411
    def make_inv_delta(self, old, new):
397
412
        """Make an inventory delta from two inventories."""
413
428
 
414
429
    def fake_up_revision(self, tree, revid, shape):
415
430
 
 
431
        if not isinstance(tree, InventoryTree):
 
432
            raise TestNotApplicable("test requires inventory tree")
 
433
 
416
434
        class ShapeTree(InventoryRevisionTree):
417
435
 
418
436
            def __init__(self, shape):