Rev 4678: Split out the get_deltas_for_revision into a separate test module. in http://bazaar.launchpad.net/~jameinel/bzr/2.0.1-faster-get-deltas-bug374730

John Arbash Meinel john at arbash-meinel.com
Thu Sep 24 22:14:49 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.0.1-faster-get-deltas-bug374730

------------------------------------------------------------
revno: 4678
revision-id: john at arbash-meinel.com-20090924211435-xtaqufvae4gwfims
parent: john at arbash-meinel.com-20090924200936-g1iyerqko1bb6tel
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.0.1-faster-get-deltas-bug374730
timestamp: Thu 2009-09-24 16:14:35 -0500
message:
  Split out the get_deltas_for_revision into a separate test module.
-------------- next part --------------
=== modified file 'bzrlib/tests/per_repository/__init__.py'
--- a/bzrlib/tests/per_repository/__init__.py	2009-07-22 17:22:06 +0000
+++ b/bzrlib/tests/per_repository/__init__.py	2009-09-24 21:14:35 +0000
@@ -862,6 +862,7 @@
         'test_fileid_involved',
         'test_find_text_key_references',
         'test__generate_text_key_index',
+        'test_get_deltas_for_revisions',
         'test_get_parent_map',
         'test_has_same_location',
         'test_has_revisions',

=== added file 'bzrlib/tests/per_repository/test_get_deltas_for_revisions.py'
--- a/bzrlib/tests/per_repository/test_get_deltas_for_revisions.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/per_repository/test_get_deltas_for_revisions.py	2009-09-24 21:14:35 +0000
@@ -0,0 +1,105 @@
+# Copyright (C) 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
+
+
+from bzrlib.transport.memory import MemoryServer
+from bzrlib.tests.per_repository import TestCaseWithRepository
+
+
+class TestGetDeltasForRevisions(TestCaseWithRepository):
+
+    def setUp(self):
+        # All of our tests will be run out of the MemoryServer, not just the
+        # Remote ones
+        self.transport_server = MemoryServer
+        self.vfs_transport_factory = MemoryServer
+        super(TestGetDeltasForRevisions, self).setUp()
+
+    def make_repo_with_history(self):
+        builder = self.make_branch_builder('source',
+                                           format=self.bzrdir_format)
+        builder.start_series()
+        builder.build_snapshot('rev1', None, [
+            ('add', ('', 'TREE_ROOT', 'directory', None)),
+            ('add', ('file', 'file-id', 'file', 'content\n')),
+            ('add', ('dir', 'dir-id', 'directory', None)),
+            ('add', ('dir/subfile', 'subfile-id', 'file', 'content\n')),
+            ('add', ('dir/dir', 'dirdir-id', 'directory', None)),
+            ('add', ('dir/dir/subsubfile', 'subsubfile-id', 'file',
+                     'content\n'))
+            ])
+        builder.build_snapshot('rev2', ['rev1'], [
+            ('modify', ('file-id', 'new file content\n'))])
+        rev3_delta = [('add', ('dir/dir/newsubsubfile', 'newsubsubfile-id',
+                               'file', 'newsubsub content\n')),
+                      ('modify', ('subsubfile-id', 'subsub file content\n')),
+                     ]
+        builder.build_snapshot('rev3', ['rev1'], rev3_delta)
+        builder.build_snapshot('rev4', ['rev2', 'rev3'], rev3_delta)
+        builder.build_snapshot('rev5', ['rev4'], [
+            ('unversion', 'subfile-id')])
+        builder.build_snapshot('rev6', ['rev5'], [
+            ('rename', ('dir/dir', 'dir/newsubdir'))])
+        builder.finish_series()
+        b = builder.get_branch()
+        repo = b.repository
+        repo.lock_read()
+        self.addCleanup(repo.unlock)
+        return repo
+
+    def test_all_changes(self):
+        repo = self.make_repo_with_history()
+        revisions = [repo.get_revision(r) for r in
+                     ['rev1', 'rev2', 'rev3', 'rev4', 'rev5', 'rev6']]
+        deltas1 = list(repo.get_deltas_for_revisions(revisions))
+        # TODO: this is a bad test, as 'get_revision_delta()' is
+        #       implemented in terms of get_deltas_for_revisions()...
+        #       but it is the test we had before
+        deltas2 = [repo.get_revision_delta(r.revision_id) for r in revisions]
+        self.assertEqual(deltas1, deltas2)
+        for delta in deltas1:
+            self.assertTrue(delta.has_changed())
+        delta = deltas1[1]
+        self.assertEqual([('file', 'file-id', 'file', True, False)],
+                         delta.modified)
+
+    def test_filtered_file_changes(self):
+        repo = self.make_repo_with_history()
+        revisions = [repo.get_revision(r) for r in
+                     ['rev1', 'rev2', 'rev3', 'rev4', 'rev5', 'rev6']]
+        deltas = list(repo.get_deltas_for_revisions(revisions,
+                      specific_fileids=['subfile-id']))
+        # Only modified in rev1 and rev5
+        self.assertTrue(deltas[0].has_changed())
+        self.assertFalse(deltas[1].has_changed())
+        self.assertFalse(deltas[2].has_changed())
+        self.assertFalse(deltas[3].has_changed())
+        self.assertTrue(deltas[4].has_changed())
+        self.assertFalse(deltas[5].has_changed())
+
+    def test_filtered_dirs_include_children(self):
+        repo = self.make_repo_with_history()
+        revisions = [repo.get_revision(r) for r in
+                     ['rev1', 'rev2', 'rev3', 'rev4', 'rev5', 'rev6']]
+        deltas = list(repo.get_deltas_for_revisions(revisions,
+                      specific_fileids=['dir-id']))
+        # child modified in all but rev2
+        self.assertTrue(deltas[0].has_changed())
+        self.assertFalse(deltas[1].has_changed())
+        self.assertTrue(deltas[2].has_changed())
+        self.assertTrue(deltas[3].has_changed())
+        self.assertTrue(deltas[4].has_changed())
+        self.assertTrue(deltas[5].has_changed())

=== modified file 'bzrlib/tests/per_repository/test_repository.py'
--- a/bzrlib/tests/per_repository/test_repository.py	2009-09-08 11:32:53 +0000
+++ b/bzrlib/tests/per_repository/test_repository.py	2009-09-24 21:14:35 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006, 2007 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007, 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
@@ -1173,17 +1173,6 @@
         for tree1, tree2 in zip(trees1, trees2):
             self.assertFalse(tree2.changes_from(tree1).has_changed())
 
-    def test_get_deltas_for_revisions(self):
-        repository = self.bzrdir.open_repository()
-        repository.lock_read()
-        self.addCleanup(repository.unlock)
-        revisions = [repository.get_revision(r) for r in
-                     ['rev1', 'rev2', 'rev3', 'rev4']]
-        deltas1 = list(repository.get_deltas_for_revisions(revisions))
-        deltas2 = [repository.get_revision_delta(r.revision_id) for r in
-                   revisions]
-        self.assertEqual(deltas1, deltas2)
-
     def test_all_revision_ids(self):
         # all_revision_ids -> all revisions
         self.assertEqual(set(['rev1', 'rev2', 'rev3', 'rev4']),



More information about the bazaar-commits mailing list