Rev 5861: Create a direct helper for testing UpdateBasisByDelta cases. in http://bazaar.launchpad.net/~jameinel/bzr/2.4-set-parent-trees-delta-282941
John Arbash Meinel
john at arbash-meinel.com
Thu May 19 08:33:11 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/2.4-set-parent-trees-delta-282941
------------------------------------------------------------
revno: 5861
revision-id: john at arbash-meinel.com-20110519083301-7pqmtsnqzgjvwqie
parent: john at arbash-meinel.com-20110518192837-k6v99s5145tea46w
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.4-set-parent-trees-delta-282941
timestamp: Thu 2011-05-19 10:33:01 +0200
message:
Create a direct helper for testing UpdateBasisByDelta cases.
Hopefully this will be simpler to manage, and set up the edge cases.
It also allows us to directly inspect the dirstate object.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_dirstate.py'
--- a/bzrlib/tests/test_dirstate.py 2011-04-22 14:12:22 +0000
+++ b/bzrlib/tests/test_dirstate.py 2011-05-19 08:33:01 +0000
@@ -26,7 +26,9 @@
osutils,
revision as _mod_revision,
tests,
+ workingtree_4,
)
+from bzrlib.transport import memory
from bzrlib.tests import test_osutils
from bzrlib.tests.scenarios import load_tests_apply_scenarios
@@ -2421,3 +2423,62 @@
self.assertTrue(len(statvalue) >= 10)
self.assertEqual(len(text), statvalue.st_size)
self.assertEqual(expected_sha, sha1)
+
+
+class TestUpdateBasisByDelta(TestCaseWithDirState):
+
+ def create_rev_from_shape(self, builder, name, shape):
+ builder_commands = []
+ for path, file_id in shape:
+ if path.endswith('/'):
+ builder_commands.append(('add',
+ (path[:1], file_id, 'directory', None)))
+ else:
+ content = 'content\n%s\n%s\n' % (path, file_id)
+ builder_commands.append(('add',
+ (path, file_id, 'file', content)))
+ builder.build_snapshot(name, ['root'], builder_commands)
+
+ def create_revs(self, active_shape, basis_shape, target_shape):
+ self.vfs_transport_factory = memory.MemoryServer
+ builder = self.make_branch_builder('builder')
+ builder.start_series()
+ self.addCleanup(builder.finish_series)
+ builder.build_snapshot('root', [], [
+ ('add', ('', 'root-id', 'directory', None))])
+ self.create_rev_from_shape(builder, 'active', active_shape)
+ self.create_rev_from_shape(builder, 'basis', basis_shape)
+ self.create_rev_from_shape(builder, 'target', target_shape)
+ repo = builder.get_branch().repository
+ active_tree, basis_tree, target_tree = repo.revision_trees(
+ ['active', 'basis', 'target'])
+ return repo, active_tree, basis_tree, target_tree
+
+ def assertUpdate(self, active_shape, basis_shape, target_shape):
+ """Assert that update_basis_by_delta works how we want.
+
+ Set up a DirState object with active_shape for tree 0, basis_shape for
+ tree 1. Then apply the delta from basis_shape to target_shape,
+ and assert that the DirState is still valid, and that its stored
+ content matches the target_shape.
+ """
+ (repo, active_tree, basis_tree,
+ target_tree) = self.create_revs(active_shape, basis_shape, target_shape)
+ dirstate = self.create_empty_dirstate()
+ self.addCleanup(dirstate.unlock)
+ dirstate.set_state_from_scratch(active_tree.inventory,
+ [('basis', basis_tree)], [])
+ delta = target_tree.inventory._make_delta(basis_tree.inventory)
+ dirstate.update_basis_by_delta(delta, 'target')
+ dirstate._validate()
+ dirstate_tree = workingtree_4.DirStateRevisionTree(dirstate,
+ 'target', repo)
+ self.assertEqual([], list(dirstate_tree.iter_changes(target_tree)))
+ return dirstate
+
+ def test_add_file_matching_active_state(self):
+ self.assertUpdate([('file', 'file-id')],
+ [],
+ [('file', 'file-id')],
+ )
+
More information about the bazaar-commits
mailing list