~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_sprout.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for Branch.sprout()"""
18
18
 
19
19
import os
20
20
from bzrlib import (
21
21
    branch as _mod_branch,
 
22
    errors,
22
23
    remote,
23
24
    revision as _mod_revision,
24
25
    tests,
25
26
    )
26
 
from bzrlib.tests import KnownFailure, SymlinkFeature, UnicodeFilenameFeature
27
27
from bzrlib.tests.branch_implementations import TestCaseWithBranch
28
28
 
29
29
 
70
70
            # did the right thing.
71
71
            target._ensure_real()
72
72
            target = target._real_branch
 
73
        if isinstance(result_format, remote.RemoteBranchFormat):
 
74
            # Unwrap a parameterised RemoteBranchFormat for comparison.
 
75
            result_format = result_format._custom_format
73
76
        self.assertIs(result_format.__class__, target._format.__class__)
74
77
 
75
78
    def test_sprout_partial(self):
128
131
        # Since the trigger function seems to be set_parent_trees, there exists
129
132
        # also a similar test, with name test_unicode_symlink, in class
130
133
        # TestSetParents at file workingtree_implementations/test_parents.py
131
 
        self.requireFeature(SymlinkFeature)
132
 
        self.requireFeature(UnicodeFilenameFeature)
 
134
        self.requireFeature(tests.SymlinkFeature)
 
135
        self.requireFeature(tests.UnicodeFilenameFeature)
133
136
 
134
137
        tree = self.make_branch_and_tree('tree1')
135
138
 
139
142
        os.symlink(u'\u03a9','tree1/link_name')
140
143
        tree.add(['link_name'],['link-id'])
141
144
 
 
145
        revision = tree.commit('added a link to a Unicode target')
 
146
        tree.bzrdir.sprout('target')
 
147
 
 
148
    def assertBranchHookBranchIsStacked(self, pre_change_params):
 
149
        # Just calling will either succeed or fail.
 
150
        pre_change_params.branch.get_stacked_on_url()
 
151
        self.hook_calls.append(pre_change_params)
 
152
 
 
153
    def test_sprout_stacked_hooks_get_stacked_branch(self):
 
154
        tree = self.make_branch_and_tree('source')
 
155
        tree.commit('a commit')
 
156
        revid = tree.commit('a second commit')
 
157
        source = tree.branch
 
158
        target_transport = self.get_transport('target')
 
159
        self.hook_calls = []
 
160
        _mod_branch.Branch.hooks.install_named_hook("pre_change_branch_tip",
 
161
            self.assertBranchHookBranchIsStacked, None)
142
162
        try:
143
 
            # python 2.7a0 failed on commit:
144
 
            revision = tree.commit('added a link to a Unicode target')
145
 
            # python 2.5 failed on sprout:
146
 
            tree.bzrdir.sprout('target')
147
 
        except UnicodeEncodeError, e:
148
 
            raise KnownFailure('there is no support for'
149
 
                               ' symlinks to non-ASCII targets (bug #272444)')
 
163
            dir = source.bzrdir.sprout(target_transport.base,
 
164
                source.last_revision(), possible_transports=[target_transport],
 
165
                source_branch=source, stacked=True)
 
166
        except errors.UnstackableBranchFormat:
 
167
            if isinstance(self.branch_format, _mod_branch.BzrBranchFormat4):
 
168
                raise tests.KnownFailure(
 
169
                    "Format 4 doesn't auto stack successfully.")
 
170
            else:
 
171
                raise
 
172
        result = dir.open_branch()
 
173
        self.assertEqual(revid, result.last_revision())
 
174
        self.assertEqual(source.base, result.get_stacked_on_url())
 
175
        # Smart servers invoke hooks on both sides
 
176
        if isinstance(result, remote.RemoteBranch):
 
177
            expected_calls = 2
 
178
        else:
 
179
            expected_calls = 1
 
180
        self.assertEqual(expected_calls, len(self.hook_calls))
150
181