Rev 4808: More tests. in file:///home/vila/src/bzr/bugs/515597-merge-hook/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Feb 2 08:36:12 GMT 2010


At file:///home/vila/src/bzr/bugs/515597-merge-hook/

------------------------------------------------------------
revno: 4808
revision-id: v.ladeuil+lp at free.fr-20100202083612-eckp9epabk9arhwu
parent: v.ladeuil+lp at free.fr-20100201172944-u41q2lw8jehlojv5
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 515597-merge-hook
timestamp: Tue 2010-02-02 09:36:12 +0100
message:
  More tests.
  
  * bzrlib/tests/test_merge_core.py:
  (MergeBuilder.add_dir): Allows adding a directory in some trees
  only.
  
  * bzrlib/tests/test_merge.py:
  (TestConfigurableFileMerger): Add more tests.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2010-02-01 17:29:44 +0000
+++ b/NEWS	2010-02-02 08:36:12 +0000
@@ -28,7 +28,7 @@
 
 * The new ``merge_file_content`` should now be ok with tests to avoid
   regressions.
-  (Vincent Ladeuil)
+  (Vincent Ladeuil, #515597)
 
 bzr 2.1.0rc2
 ############

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2010-01-20 16:31:24 +0000
+++ b/bzrlib/tests/__init__.py	2010-02-02 08:36:12 +0000
@@ -921,7 +921,7 @@
             self._lock_check_thorough = False
         else:
             self._lock_check_thorough = True
-            
+
         self.addCleanup(self._check_locks)
         _mod_lock.Lock.hooks.install_named_hook('lock_acquired',
                                                 self._lock_acquired, None)

=== modified file 'bzrlib/tests/test_merge.py'
--- a/bzrlib/tests/test_merge.py	2010-02-01 17:29:44 +0000
+++ b/bzrlib/tests/test_merge.py	2010-02-02 08:36:12 +0000
@@ -2841,24 +2841,81 @@
 
 class TestConfigurableFileMerger(tests.TestCaseWithTransport):
 
-    def test_affected_files_cached(self):
-        """Ensures that the config variable is cached"""
-        class SimplePlan(_mod_merge.ConfigurableFileMerger):
+    def setUp(self):
+        super(TestConfigurableFileMerger, self).setUp()
+        self.calls = []
+
+    def get_merger_factory(self):
+        # Allows  the inner methods to access the test attributes
+        test = self
+
+        class FooMerger(_mod_merge.ConfigurableFileMerger):
             name_prefix = "foo"
             default_files = ['bar']
+
             def merge_text(self, params):
+                test.calls.append('merge_text')
                 return ('not_applicable', None)
+
         def factory(merger):
-            result = SimplePlan(merger)
+            result = FooMerger(merger)
+            # Make sure we start with a clean slate
             self.assertEqual(None, result.affected_files)
+            # Track the original merger
             self.merger = result
             return result
+
+        return factory
+
+    def _install_hook(self, factory):
         _mod_merge.Merger.hooks.install_named_hook('merge_file_content',
                                                    factory, 'test factory')
+
+    def make_builder(self):
         builder = test_merge_core.MergeBuilder(self.test_base_dir)
         self.addCleanup(builder.cleanup)
-        builder.add_file('bar-id', builder.tree_root, 'bar', 'text1', True)
+        return builder
+
+    def make_text_conflict(self, file_name='bar'):
+        factory = self.get_merger_factory()
+        self._install_hook(factory)
+        builder = self.make_builder()
+        builder.add_file('bar-id', builder.tree_root, file_name, 'text1', True)
         builder.change_contents('bar-id', other='text4', this='text3')
+        return builder
+
+    def make_kind_change(self):
+        factory = self.get_merger_factory()
+        self._install_hook(factory)
+        builder = self.make_builder()
+        builder.add_file('bar-id', builder.tree_root, 'bar', 'text1', True,
+                         this=False)
+        builder.add_dir('bar-dir', builder.tree_root, 'bar-id',
+                        base=False, other=False)
+        return builder
+
+    def test_affected_files_cached(self):
+        """Ensures that the config variable is cached"""
+        builder = self.make_text_conflict()
         conflicts = builder.merge()
         # The hook should set the variable
         self.assertEqual(['bar'], self.merger.affected_files)
+        self.assertEqual(1, len(conflicts))
+
+    def test_hook_called_for_text_conflicts(self):
+        builder = self.make_text_conflict()
+        conflicts = builder.merge()
+        # The hook should call the merge_text() method
+        self.assertEqual(['merge_text'], self.calls)
+
+    def test_hook_not_called_for_kind_change(self):
+        builder = self.make_kind_change()
+        conflicts = builder.merge()
+        # The hook should not call the merge_text() method
+        self.assertEqual([], self.calls)
+
+    def test_hook_not_called_for_other_files(self):
+        builder = self.make_text_conflict('foobar')
+        conflicts = builder.merge()
+        # The hook should not call the merge_text() method
+        self.assertEqual([], self.calls)

=== modified file 'bzrlib/tests/test_merge_core.py'
--- a/bzrlib/tests/test_merge_core.py	2010-01-15 03:58:20 +0000
+++ b/bzrlib/tests/test_merge_core.py	2010-02-02 08:36:12 +0000
@@ -114,10 +114,11 @@
                 tt.cancel_versioning(trans_id)
                 tt.set_executability(None, trans_id)
 
-    def add_dir(self, file_id, parent, name):
-        for tt in self.list_transforms():
-            parent_id = tt.trans_id_file_id(parent)
-            tt.new_directory(name, parent_id, file_id)
+    def add_dir(self, file_id, parent, name, this=True, base=True, other=True):
+        for option, tt in self.selected_transforms(this, base, other):
+            if option is True:
+                parent_id = tt.trans_id_file_id(parent)
+                tt.new_directory(name, parent_id, file_id)
 
     def change_name(self, id, base=None, this=None, other=None):
         for val, tt in ((base, self.base_tt), (this, self.this_tt),



More information about the bazaar-commits mailing list