Rev 5861: Remove duplication. in file:///home/vila/src/bzr/reviews/per-workingtree-inv-delta/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri May 13 17:13:07 UTC 2011


At file:///home/vila/src/bzr/reviews/per-workingtree-inv-delta/

------------------------------------------------------------
revno: 5861
revision-id: v.ladeuil+lp at free.fr-20110513171306-5lr4nkdq5teqpkvx
parent: jelmer at samba.org-20110513152644-nteloa7n0045i3h1
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: per-workingtree-inv-delta
timestamp: Fri 2011-05-13 19:13:06 +0200
message:
  Remove duplication.
-------------- next part --------------
=== modified file 'bzrlib/tests/per_workingtree/test_inv.py'
--- a/bzrlib/tests/per_workingtree/test_inv.py	2011-05-13 15:26:44 +0000
+++ b/bzrlib/tests/per_workingtree/test_inv.py	2011-05-13 17:13:06 +0000
@@ -41,81 +41,58 @@
 
 class TestApplyInventoryDelta(TestCaseWithWorkingTree):
 
+    def setUp(self):
+        super(TestApplyInventoryDelta, self).setUp()
+        self.wt = self.make_branch_and_tree('.')
+        if not self.wt.branch.repository._format.supports_full_versioned_files:
+            raise tests.TestNotApplicable(
+                "format does not support inventory deltas")
+        self.wt.lock_write()
+        self.addCleanup(self.wt.unlock)
+        self.root_id = self.wt.get_root_id()
+
     def test_add(self):
-        wt = self.make_branch_and_tree('.')
-        if not wt.branch.repository._format.supports_full_versioned_files:
-            raise tests.TestNotApplicable(
-                "format does not support inventory deltas")
-        wt.lock_write()
-        self.addCleanup(wt.unlock)
-        root_id = wt.get_root_id()
-        wt.apply_inventory_delta([(None, 'bar/foo', 'foo-id',
+        self.wt.apply_inventory_delta([(None, 'bar/foo', 'foo-id',
             inventory.InventoryFile('foo-id', 'foo', parent_id='bar-id')),
             (None, 'bar', 'bar-id', inventory.InventoryDirectory('bar-id',
-            'bar', parent_id=root_id))])
-        self.assertEqual('bar/foo', wt.inventory.id2path('foo-id'))
-        self.assertEqual('bar', wt.inventory.id2path('bar-id'))
+            'bar', parent_id=self.root_id))])
+        self.assertEqual('bar/foo', self.wt.inventory.id2path('foo-id'))
+        self.assertEqual('bar', self.wt.inventory.id2path('bar-id'))
 
     def test_remove(self):
-        wt = self.make_branch_and_tree('.')
-        if not wt.branch.repository._format.supports_full_versioned_files:
-            raise tests.TestNotApplicable(
-                "format does not support inventory deltas")
-        wt.lock_write()
-        self.addCleanup(wt.unlock)
         self.build_tree(['foo/', 'foo/bar'])
-        wt.add(['foo', 'foo/bar'], ['foo-id', 'bar-id'])
-        wt.apply_inventory_delta([('foo', None, 'foo-id', None),
+        self.wt.add(['foo', 'foo/bar'], ['foo-id', 'bar-id'])
+        self.wt.apply_inventory_delta([('foo', None, 'foo-id', None),
                                   ('foo/bar', None, 'bar-id', None)])
-        self.assertIs(None, wt.path2id('foo'))
+        self.assertIs(None, self.wt.path2id('foo'))
 
     def test_rename_dir_with_children(self):
-        wt = self.make_branch_and_tree('.')
-        if not wt.branch.repository._format.supports_full_versioned_files:
-            raise tests.TestNotApplicable(
-                "format does not support inventory deltas")
-        wt.lock_write()
-        root_id = wt.get_root_id()
-        self.addCleanup(wt.unlock)
         self.build_tree(['foo/', 'foo/bar'])
-        wt.add(['foo', 'foo/bar'],
+        self.wt.add(['foo', 'foo/bar'],
                ['foo-id', 'bar-id'])
-        wt.apply_inventory_delta([('foo', 'baz', 'foo-id',
-            inventory.InventoryDirectory('foo-id', 'baz', root_id))])
+        self.wt.apply_inventory_delta([('foo', 'baz', 'foo-id',
+            inventory.InventoryDirectory('foo-id', 'baz', self.root_id))])
         # foo/bar should have been followed the rename of its parent to baz/bar
-        self.assertEqual('baz', wt.id2path('foo-id'))
-        self.assertEqual('baz/bar', wt.id2path('bar-id'))
+        self.assertEqual('baz', self.wt.id2path('foo-id'))
+        self.assertEqual('baz/bar', self.wt.id2path('bar-id'))
 
     def test_rename_dir_with_children_with_children(self):
-        wt = self.make_branch_and_tree('.')
-        if not wt.branch.repository._format.supports_full_versioned_files:
-            raise tests.TestNotApplicable(
-                "format does not support inventory deltas")
-        wt.lock_write()
-        root_id = wt.get_root_id()
-        self.addCleanup(wt.unlock)
         self.build_tree(['foo/', 'foo/bar/', 'foo/bar/baz'])
-        wt.add(['foo', 'foo/bar', 'foo/bar/baz'],
+        self.wt.add(['foo', 'foo/bar', 'foo/bar/baz'],
                ['foo-id', 'bar-id', 'baz-id'])
-        wt.apply_inventory_delta([('foo', 'quux', 'foo-id',
-            inventory.InventoryDirectory('foo-id', 'quux', root_id))])
+        self.wt.apply_inventory_delta([('foo', 'quux', 'foo-id',
+            inventory.InventoryDirectory('foo-id', 'quux', self.root_id))])
         # foo/bar/baz should have been followed the rename of its parent's
         # parent to quux/bar/baz
-        self.assertEqual('quux/bar/baz', wt.id2path('baz-id'))
+        self.assertEqual('quux/bar/baz', self.wt.id2path('baz-id'))
 
     def test_rename_file(self):
-        wt = self.make_branch_and_tree('.')
-        if not wt.branch.repository._format.supports_full_versioned_files:
-            raise tests.TestNotApplicable(
-                "format does not support inventory deltas")
-        wt.lock_write()
-        self.addCleanup(wt.unlock)
         self.build_tree(['foo/', 'foo/bar', 'baz/'])
-        wt.add(['foo', 'foo/bar', 'baz'],
+        self.wt.add(['foo', 'foo/bar', 'baz'],
                ['foo-id', 'bar-id', 'baz-id'])
-        wt.apply_inventory_delta([('foo/bar', 'baz/bar', 'bar-id',
+        self.wt.apply_inventory_delta([('foo/bar', 'baz/bar', 'bar-id',
             inventory.InventoryFile('bar-id', 'bar', 'baz-id'))])
-        self.assertEqual('baz/bar', wt.id2path('bar-id'))
+        self.assertEqual('baz/bar', self.wt.id2path('bar-id'))
 
     def test_rename_swap(self):
         """Test the swap-names edge case.
@@ -123,22 +100,15 @@
         foo and bar should swap names, but retain their children.  If this
         works, any simpler rename ought to work.
         """
-        wt = self.make_branch_and_tree('.')
-        if not wt.branch.repository._format.supports_full_versioned_files:
-            raise tests.TestNotApplicable(
-                "format does not support inventory deltas")
-        wt.lock_write()
-        root_id = wt.get_root_id()
-        self.addCleanup(wt.unlock)
         self.build_tree(['foo/', 'foo/bar', 'baz/', 'baz/qux'])
-        wt.add(['foo', 'foo/bar', 'baz', 'baz/qux'],
+        self.wt.add(['foo', 'foo/bar', 'baz', 'baz/qux'],
                ['foo-id', 'bar-id', 'baz-id', 'qux-id'])
-        wt.apply_inventory_delta([('foo', 'baz', 'foo-id',
-            inventory.InventoryDirectory('foo-id', 'baz', root_id)),
+        self.wt.apply_inventory_delta([('foo', 'baz', 'foo-id',
+            inventory.InventoryDirectory('foo-id', 'baz', self.root_id)),
             ('baz', 'foo', 'baz-id',
-            inventory.InventoryDirectory('baz-id', 'foo', root_id))])
-        self.assertEqual('baz/bar', wt.id2path('bar-id'))
-        self.assertEqual('foo/qux', wt.id2path('qux-id'))
+            inventory.InventoryDirectory('baz-id', 'foo', self.root_id))])
+        self.assertEqual('baz/bar', self.wt.id2path('bar-id'))
+        self.assertEqual('foo/qux', self.wt.id2path('qux-id'))
 
     def test_child_rename_ordering(self):
         """Test the rename-parent, move child edge case.
@@ -146,33 +116,20 @@
         (A naive implementation may move the parent first, and then be
          unable to find the child.)
         """
-        wt = self.make_branch_and_tree('.')
-        if not wt.branch.repository._format.supports_full_versioned_files:
-            raise tests.TestNotApplicable(
-                "format does not support inventory deltas")
-        root_id = wt.get_root_id()
         self.build_tree(['dir/', 'dir/child', 'other/'])
-        wt.add(['dir', 'dir/child', 'other'],
+        self.wt.add(['dir', 'dir/child', 'other'],
                ['dir-id', 'child-id', 'other-id'])
         # this delta moves dir-id to dir2 and reparents
         # child-id to a parent of other-id
-        wt.apply_inventory_delta([('dir', 'dir2', 'dir-id',
-            inventory.InventoryDirectory('dir-id', 'dir2', root_id)),
+        self.wt.apply_inventory_delta([('dir', 'dir2', 'dir-id',
+            inventory.InventoryDirectory('dir-id', 'dir2', self.root_id)),
             ('dir/child', 'other/child', 'child-id',
              inventory.InventoryFile('child-id', 'child', 'other-id'))])
-        self.assertEqual('dir2', wt.id2path('dir-id'))
-        self.assertEqual('other/child', wt.id2path('child-id'))
+        self.assertEqual('dir2', self.wt.id2path('dir-id'))
+        self.assertEqual('other/child', self.wt.id2path('child-id'))
 
     def test_replace_root(self):
-        wt = self.make_branch_and_tree('.')
-        if not wt.branch.repository._format.supports_full_versioned_files:
-            raise tests.TestNotApplicable(
-                "format does not support inventory deltas")
-        wt.lock_write()
-        self.addCleanup(wt.unlock)
-
-        root_id = wt.get_root_id()
-        wt.apply_inventory_delta([('', None, root_id, None),
+        self.wt.apply_inventory_delta([('', None, self.root_id, None),
             (None, '', 'root-id',
              inventory.InventoryDirectory('root-id', '', None))])
 



More information about the bazaar-commits mailing list