diff options
author | John Arbash Meinel <john@arbash-meinel.com> | 2009-12-11 08:55:04 -0600 |
---|---|---|
committer | John Arbash Meinel <john@arbash-meinel.com> | 2009-12-11 08:55:04 -0600 |
commit | de9899249e5625c20f9287c4e36cb519eb504cf2 (patch) | |
tree | 323b44044e9951f7f4c21a2dcf9316da9a5c4c0b /tests | |
parent | 79a478182a34c34bc983eb2474e002909ad101d6 (diff) | |
parent | 5ff6d451b0f69149b4fba0e98abdfbc8c584fa79 (diff) | |
download | bzr-fastimport-de9899249e5625c20f9287c4e36cb519eb504cf2.tar.gz |
Switch to using CommitBuilder
Rather than holding most of the logic ourselves.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/__init__.py | 21 | ||||
-rw-r--r-- | tests/test_generic_processor.py | 51 | ||||
-rw-r--r-- | tests/test_revision_store.py | 147 |
3 files changed, 209 insertions, 10 deletions
diff --git a/tests/__init__.py b/tests/__init__.py index 711b605..cda5705 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -21,15 +21,16 @@ from bzrlib.tests.TestUtil import TestLoader, TestSuite def test_suite(): - module_names = [ - 'bzrlib.plugins.fastimport.tests.test_branch_mapper', - 'bzrlib.plugins.fastimport.tests.test_commands', - 'bzrlib.plugins.fastimport.tests.test_errors', - 'bzrlib.plugins.fastimport.tests.test_filter_processor', - 'bzrlib.plugins.fastimport.tests.test_generic_processor', - 'bzrlib.plugins.fastimport.tests.test_head_tracking', - 'bzrlib.plugins.fastimport.tests.test_helpers', - 'bzrlib.plugins.fastimport.tests.test_parser', - ] + module_names = [__name__ + '.' + x for x in [ + 'test_branch_mapper', + 'test_commands', + 'test_errors', + 'test_filter_processor', + 'test_generic_processor', + 'test_head_tracking', + 'test_helpers', + 'test_parser', + 'test_revision_store', + ]] loader = TestLoader() return loader.loadTestsFromModuleNames(module_names) diff --git a/tests/test_generic_processor.py b/tests/test_generic_processor.py index 21fb003..778a4aa 100644 --- a/tests/test_generic_processor.py +++ b/tests/test_generic_processor.py @@ -1832,3 +1832,54 @@ class TestImportToPackFileKinds(TestCaseForGenericProcessor): def test_import_symlink(self): handler, branch = self.get_handler() handler.process(self.get_command_iter('foo', 'symlink', 'bar')) + + +class TestModifyRevertInBranch(TestCaseForGenericProcessor): + + def file_command_iter(self): + # A add 'foo' + # |\ + # | B modify 'foo' + # | | + # | C revert 'foo' back to A + # |/ + # D merge 'foo' + def command_list(): + committer_a = ['', 'a@elmer.com', time.time(), time.timezone] + committer_b = ['', 'b@elmer.com', time.time(), time.timezone] + committer_c = ['', 'c@elmer.com', time.time(), time.timezone] + committer_d = ['', 'd@elmer.com', time.time(), time.timezone] + def files_one(): + yield commands.FileModifyCommand('foo', 'file', False, + None, "content A\n") + yield commands.CommitCommand('head', '1', None, + committer_a, "commit 1", None, [], files_one) + def files_two(): + yield commands.FileModifyCommand('foo', 'file', False, + None, "content B\n") + yield commands.CommitCommand('head', '2', None, + committer_b, "commit 2", ":1", [], files_two) + def files_three(): + yield commands.FileModifyCommand('foo', 'file', False, + None, "content A\n") + yield commands.CommitCommand('head', '3', None, + committer_c, "commit 3", ":2", [], files_three) + yield commands.CommitCommand('head', '4', None, + committer_d, "commit 4", ":1", [':3'], lambda: []) + return command_list + + def test_modify_revert(self): + handler, branch = self.get_handler() + handler.process(self.file_command_iter()) + branch.lock_read() + self.addCleanup(branch.unlock) + rev_d = branch.last_revision() + rev_a, rev_c = branch.repository.get_parent_map([rev_d])[rev_d] + rev_b = branch.repository.get_parent_map([rev_c])[rev_c][0] + rtree_a, rtree_b, rtree_c, rtree_d = branch.repository.revision_trees([ + rev_a, rev_b, rev_c, rev_d]) + foo_id = rtree_a.path2id('foo') + self.assertEqual(rev_a, rtree_a.inventory[foo_id].revision) + self.assertEqual(rev_b, rtree_b.inventory[foo_id].revision) + self.assertEqual(rev_c, rtree_c.inventory[foo_id].revision) + self.assertEqual(rev_c, rtree_d.inventory[foo_id].revision) diff --git a/tests/test_revision_store.py b/tests/test_revision_store.py new file mode 100644 index 0000000..d850c95 --- /dev/null +++ b/tests/test_revision_store.py @@ -0,0 +1,147 @@ +# Copyright (C) 2008, 2009 Canonical Ltd +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +"""Direct tests of the revision_store classes.""" + +from bzrlib import ( + branch, + errors, + inventory, + osutils, + tests, + ) + +from bzrlib.plugins.fastimport import ( + revision_store, + ) + + +class Test_TreeShim(tests.TestCase): + + def invAddEntry(self, inv, path, file_id=None): + if path.endswith('/'): + path = path[:-1] + kind = 'directory' + else: + kind = 'file' + parent_path, basename = osutils.split(path) + parent_id = inv.path2id(parent_path) + inv.add(inventory.make_entry(kind, basename, parent_id, file_id)) + + def make_trivial_basis_inv(self): + basis_inv = inventory.Inventory('TREE_ROOT') + self.invAddEntry(basis_inv, 'foo', 'foo-id') + self.invAddEntry(basis_inv, 'bar/', 'bar-id') + self.invAddEntry(basis_inv, 'bar/baz', 'baz-id') + return basis_inv + + def test_id2path_no_delta(self): + basis_inv = self.make_trivial_basis_inv() + shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv, + inv_delta=[], content_provider=None) + self.assertEqual('', shim.id2path('TREE_ROOT')) + self.assertEqual('foo', shim.id2path('foo-id')) + self.assertEqual('bar', shim.id2path('bar-id')) + self.assertEqual('bar/baz', shim.id2path('baz-id')) + self.assertRaises(errors.NoSuchId, shim.id2path, 'qux-id') + + def test_id2path_with_delta(self): + basis_inv = self.make_trivial_basis_inv() + foo_entry = inventory.make_entry('file', 'foo2', 'TREE_ROOT', 'foo-id') + inv_delta = [('foo', 'foo2', 'foo-id', foo_entry), + ('bar/baz', None, 'baz-id', None), + ] + + shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv, + inv_delta=inv_delta, + content_provider=None) + self.assertEqual('', shim.id2path('TREE_ROOT')) + self.assertEqual('foo2', shim.id2path('foo-id')) + self.assertEqual('bar', shim.id2path('bar-id')) + self.assertRaises(errors.NoSuchId, shim.id2path, 'baz-id') + + def test_path2id(self): + basis_inv = self.make_trivial_basis_inv() + shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv, + inv_delta=[], content_provider=None) + self.assertEqual('TREE_ROOT', shim.path2id('')) + # We don't want to ever give a wrong value, so for now we just raise + # NotImplementedError + self.assertRaises(NotImplementedError, shim.path2id, 'bar') + + def test_get_file_with_stat_content_in_stream(self): + basis_inv = self.make_trivial_basis_inv() + + def content_provider(file_id): + return 'content of\n' + file_id + '\n' + + shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv, + inv_delta=[], + content_provider=content_provider) + f_obj, stat_val = shim.get_file_with_stat('baz-id') + self.assertIs(None, stat_val) + self.assertEqualDiff('content of\nbaz-id\n', f_obj.read()) + + # TODO: Test when the content isn't in the stream, and we fall back to the + # repository that was passed in + + def test_get_symlink_target(self): + basis_inv = self.make_trivial_basis_inv() + ie = inventory.make_entry('symlink', 'link', 'TREE_ROOT', 'link-id') + ie.symlink_target = u'link-target' + basis_inv.add(ie) + shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv, + inv_delta=[], content_provider=None) + self.assertEqual(u'link-target', shim.get_symlink_target('link-id')) + + def test_get_symlink_target_from_delta(self): + basis_inv = self.make_trivial_basis_inv() + ie = inventory.make_entry('symlink', 'link', 'TREE_ROOT', 'link-id') + ie.symlink_target = u'link-target' + inv_delta = [(None, 'link', 'link-id', ie)] + shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv, + inv_delta=inv_delta, + content_provider=None) + self.assertEqual(u'link-target', shim.get_symlink_target('link-id')) + + def test__delta_to_iter_changes(self): + basis_inv = self.make_trivial_basis_inv() + foo_entry = inventory.make_entry('file', 'foo2', 'bar-id', 'foo-id') + link_entry = inventory.make_entry('symlink', 'link', 'TREE_ROOT', + 'link-id') + link_entry.symlink_target = u'link-target' + inv_delta = [('foo', 'bar/foo2', 'foo-id', foo_entry), + ('bar/baz', None, 'baz-id', None), + (None, 'link', 'link-id', link_entry), + ] + shim = revision_store._TreeShim(repo=None, basis_inv=basis_inv, + inv_delta=inv_delta, + content_provider=None) + changes = list(shim._delta_to_iter_changes()) + expected = [('foo-id', ('foo', 'bar/foo2'), False, (True, True), + ('TREE_ROOT', 'bar-id'), ('foo', 'foo2'), + ('file', 'file'), (False, False)), + ('baz-id', ('bar/baz', None), True, (True, False), + ('bar-id', None), ('baz', None), + ('file', None), (False, None)), + ('link-id', (None, 'link'), True, (False, True), + (None, 'TREE_ROOT'), (None, 'link'), + (None, 'symlink'), (None, False)), + ] + # from pprint import pformat + # self.assertEqualDiff(pformat(expected), pformat(changes)) + self.assertEqual(expected, changes) + |