~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

  • Committer: John Arbash Meinel
  • Date: 2010-02-04 16:06:36 UTC
  • mfrom: (5007 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5023.
  • Revision ID: john@arbash-meinel.com-20100204160636-xqeuwz8bwt8bbts4
Merge bzr.dev 5007, resolve conflict, update NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
33
33
from bzrlib.errors import UnrelatedBranches, NoCommits
34
34
from bzrlib.merge import transform_tree, merge_inner, _PlanMerge
35
35
from bzrlib.osutils import pathjoin, file_kind
36
 
from bzrlib.tests import TestCaseWithTransport, TestCaseWithMemoryTransport
 
36
from bzrlib.tests import (
 
37
    TestCaseWithMemoryTransport,
 
38
    TestCaseWithTransport,
 
39
    test_merge_core,
 
40
    )
37
41
from bzrlib.workingtree import WorkingTree
38
42
 
39
43
 
2833
2837
            'bval', ['lca1val', 'lca2val', 'lca2val'], 'oval', 'tval')
2834
2838
        self.assertLCAMultiWay('conflict',
2835
2839
            'bval', ['lca1val', 'lca2val', 'lca3val'], 'oval', 'tval')
 
2840
 
 
2841
 
 
2842
class TestConfigurableFileMerger(tests.TestCaseWithTransport):
 
2843
 
 
2844
    def setUp(self):
 
2845
        super(TestConfigurableFileMerger, self).setUp()
 
2846
        self.calls = []
 
2847
 
 
2848
    def get_merger_factory(self):
 
2849
        # Allows  the inner methods to access the test attributes
 
2850
        test = self
 
2851
 
 
2852
        class FooMerger(_mod_merge.ConfigurableFileMerger):
 
2853
            name_prefix = "foo"
 
2854
            default_files = ['bar']
 
2855
 
 
2856
            def merge_text(self, params):
 
2857
                test.calls.append('merge_text')
 
2858
                return ('not_applicable', None)
 
2859
 
 
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
 
2866
            return result
 
2867
 
 
2868
        return factory
 
2869
 
 
2870
    def _install_hook(self, factory):
 
2871
        _mod_merge.Merger.hooks.install_named_hook('merge_file_content',
 
2872
                                                   factory, 'test factory')
 
2873
 
 
2874
    def make_builder(self):
 
2875
        builder = test_merge_core.MergeBuilder(self.test_base_dir)
 
2876
        self.addCleanup(builder.cleanup)
 
2877
        return builder
 
2878
 
 
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')
 
2885
        return builder
 
2886
 
 
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,
 
2892
                         this=False)
 
2893
        builder.add_dir('bar-dir', builder.tree_root, 'bar-id',
 
2894
                        base=False, other=False)
 
2895
        return builder
 
2896
 
 
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))
 
2904
 
 
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)
 
2910
 
 
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)
 
2916
 
 
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)