2842
2842
class TestConfigurableFileMerger(tests.TestCaseWithTransport):
2844
def test_affected_files_cached(self):
2845
"""Ensures that the config variable is cached"""
2846
class SimplePlan(_mod_merge.ConfigurableFileMerger):
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):
2847
2853
name_prefix = "foo"
2848
default_files = ["my default"]
2854
default_files = ['bar']
2849
2856
def merge_text(self, params):
2850
return ('not applicable', None)
2857
test.calls.append('merge_text')
2858
return ('not_applicable', None)
2851
2860
def factory(merger):
2852
result = SimplePlan(merger)
2861
result = FooMerger(merger)
2862
# Make sure we start with a clean slate
2853
2863
self.assertEqual(None, result.affected_files)
2864
# Track the original merger
2854
2865
self.merger = result
2870
def _install_hook(self, factory):
2856
2871
_mod_merge.Merger.hooks.install_named_hook('merge_file_content',
2857
factory, 'test factory')
2872
factory, 'test factory')
2874
def make_builder(self):
2858
2875
builder = test_merge_core.MergeBuilder(self.test_base_dir)
2859
2876
self.addCleanup(builder.cleanup)
2860
builder.add_file('NEWS', builder.tree_root, 'name1', 'text1', True)
2861
builder.change_contents('NEWS', other='text4', this='text3')
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()
2862
2900
conflicts = builder.merge()
2863
2901
# The hook should set the variable
2864
self.assertEqual(["my default"], self.merger.affected_files)
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)