2833
2837
'bval', ['lca1val', 'lca2val', 'lca2val'], 'oval', 'tval')
2834
2838
self.assertLCAMultiWay('conflict',
2835
2839
'bval', ['lca1val', 'lca2val', 'lca3val'], 'oval', 'tval')
2842
class TestConfigurableFileMerger(tests.TestCaseWithTransport):
2845
super(TestConfigurableFileMerger, self).setUp()
2848
def get_merger_factory(self):
2849
# Allows the inner methods to access the test attributes
2852
class FooMerger(_mod_merge.ConfigurableFileMerger):
2854
default_files = ['bar']
2856
def merge_text(self, params):
2857
test.calls.append('merge_text')
2858
return ('not_applicable', None)
2860
def factory(merger):
2861
result = FooMerger(merger)
2862
# Make sure we start with a clean slate
2863
self.assertEqual(None, result.affected_files)
2864
# Track the original merger
2865
self.merger = result
2870
def _install_hook(self, factory):
2871
_mod_merge.Merger.hooks.install_named_hook('merge_file_content',
2872
factory, 'test factory')
2874
def make_builder(self):
2875
builder = test_merge_core.MergeBuilder(self.test_base_dir)
2876
self.addCleanup(builder.cleanup)
2879
def make_text_conflict(self, file_name='bar'):
2880
factory = self.get_merger_factory()
2881
self._install_hook(factory)
2882
builder = self.make_builder()
2883
builder.add_file('bar-id', builder.tree_root, file_name, 'text1', True)
2884
builder.change_contents('bar-id', other='text4', this='text3')
2887
def make_kind_change(self):
2888
factory = self.get_merger_factory()
2889
self._install_hook(factory)
2890
builder = self.make_builder()
2891
builder.add_file('bar-id', builder.tree_root, 'bar', 'text1', True,
2893
builder.add_dir('bar-dir', builder.tree_root, 'bar-id',
2894
base=False, other=False)
2897
def test_affected_files_cached(self):
2898
"""Ensures that the config variable is cached"""
2899
builder = self.make_text_conflict()
2900
conflicts = builder.merge()
2901
# The hook should set the variable
2902
self.assertEqual(['bar'], self.merger.affected_files)
2903
self.assertEqual(1, len(conflicts))
2905
def test_hook_called_for_text_conflicts(self):
2906
builder = self.make_text_conflict()
2907
conflicts = builder.merge()
2908
# The hook should call the merge_text() method
2909
self.assertEqual(['merge_text'], self.calls)
2911
def test_hook_not_called_for_kind_change(self):
2912
builder = self.make_kind_change()
2913
conflicts = builder.merge()
2914
# The hook should not call the merge_text() method
2915
self.assertEqual([], self.calls)
2917
def test_hook_not_called_for_other_files(self):
2918
builder = self.make_text_conflict('foobar')
2919
conflicts = builder.merge()
2920
# The hook should not call the merge_text() method
2921
self.assertEqual([], self.calls)