~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import os
21
21
 
22
22
import bzrlib
 
23
from bzrlib import (
 
24
    bzrdir,
 
25
    )
23
26
from bzrlib.branch import Branch
24
27
from bzrlib.bzrdir import (BzrDir,
25
28
                           BzrDirFormat,
27
30
                           BzrDirMetaFormat1,
28
31
                           )
29
32
import bzrlib.errors as errors
30
 
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer, paramiko_loaded
31
 
 
32
 
 
33
 
class BoundSFTPBranch(TestCaseWithSFTPServer):
 
33
from bzrlib.tests import TestSkipped
 
34
from bzrlib.tests import TestCaseWithTransport
 
35
from bzrlib.transport.local import LocalURLServer
 
36
from bzrlib.transport.memory import MemoryServer
 
37
 
 
38
 
 
39
class BoundSFTPBranch(TestCaseWithTransport):
 
40
 
 
41
    def setUp(self):
 
42
        TestCaseWithTransport.setUp(self)
 
43
        self.vfs_transport_factory = MemoryServer
 
44
        if self.transport_server is LocalURLServer:
 
45
            self.transport_server = None
34
46
 
35
47
    def create_branches(self):
36
48
        self.build_tree(['base/', 'base/a', 'base/b'])
37
 
        old_format = BzrDirFormat.get_default_format()
38
 
        BzrDirFormat.set_default_format(BzrDirMetaFormat1())
 
49
        format = bzrdir.format_registry.make_bzrdir('knit')
39
50
        try:
40
 
            wt_base = BzrDir.create_standalone_workingtree('base')
41
 
        finally:
42
 
            BzrDirFormat.set_default_format(old_format)
 
51
            wt_base = BzrDir.create_standalone_workingtree(
 
52
                self.get_url('base'), format=format)
 
53
        except errors.NotLocalUrl:
 
54
            raise TestSkipped('Not a local URL')
43
55
    
44
56
        b_base = wt_base.branch
45
57
 
55
67
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
56
68
        return b_base, wt_child
57
69
 
58
 
    def tearDown(self):
59
 
        self.sftp_base = None
60
 
        bzrlib.transport.sftp.clear_connection_cache()
61
 
        super(BoundSFTPBranch, self).tearDown()
62
 
 
63
70
    def test_simple_binding(self):
64
71
        self.build_tree(['base/', 'base/a', 'base/b', 'child/'])
65
 
        wt_base = BzrDir.create_standalone_workingtree('base')
 
72
        try:
 
73
            wt_base = BzrDir.create_standalone_workingtree(self.get_url('base'))
 
74
        except errors.NotLocalUrl:
 
75
            raise TestSkipped('Not a local URL')
66
76
 
67
77
        wt_base.add('a')
68
78
        wt_base.add('b')
72
82
        # manually make a branch we can bind, because the default format
73
83
        # may not be bindable-from, and we want to test the side effects etc
74
84
        # of bondage.
75
 
        old_format = BzrDirFormat.get_default_format()
76
 
        BzrDirFormat.set_default_format(BzrDirMetaFormat1())
77
 
        try:
78
 
            b_child = BzrDir.create_branch_convenience('child')
79
 
        finally:
80
 
            BzrDirFormat.set_default_format(old_format)
 
85
        format = bzrdir.format_registry.make_bzrdir('knit')
 
86
        b_child = BzrDir.create_branch_convenience('child', format=format)
81
87
        self.assertEqual(None, b_child.get_bound_location())
82
88
        self.assertEqual(None, b_child.get_master_branch())
83
89
 
188
194
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
189
195
        self.assertEqual(['r@b-1'], sftp_b_newbase.revision_history())
190
196
 
191
 
    def test_pull_updates_both(self):
192
 
        b_base, wt_child = self.create_branches()
193
 
 
194
 
        wt_newchild = b_base.bzrdir.sprout('newchild').open_workingtree()
195
 
        open('newchild/b', 'wb').write('newchild b contents\n')
196
 
        wt_newchild.commit('newchild', rev_id='r@d-2')
197
 
        self.assertEqual(['r@b-1', 'r@d-2'], wt_newchild.branch.revision_history())
198
 
 
199
 
        wt_child.pull(wt_newchild.branch)
200
 
        self.assertEqual(['r@b-1', 'r@d-2'], wt_child.branch.revision_history())
201
 
        self.assertEqual(['r@b-1', 'r@d-2'], b_base.revision_history())
202
 
 
203
197
    def test_bind_diverged(self):
204
198
        from bzrlib.builtins import merge
205
199
 
337
331
        self.assertRaises(errors.BoundBranchConnectionFailure,
338
332
                wt_child.commit, 'added text', rev_id='r@c-2')
339
333
 
340
 
    def test_pull_fails(self):
341
 
        b_base, wt_child = self.create_branches()
342
 
 
343
 
        wt_other = wt_child.bzrdir.sprout('other').open_workingtree()
344
 
        open('other/a', 'wb').write('new contents\n')
345
 
        wt_other.commit('changed a', rev_id='r@d-2')
346
 
 
347
 
        self.assertEqual(['r@b-1'], b_base.revision_history())
348
 
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
349
 
        self.assertEqual(['r@b-1', 'r@d-2'], wt_other.branch.revision_history())
350
 
 
351
 
        # this deletes the branch from memory
352
 
        del b_base
353
 
        # and this moves it out of the way on disk
354
 
        os.rename('base', 'hidden_base')
355
 
 
356
 
        self.assertRaises(errors.BoundBranchConnectionFailure,
357
 
                wt_child.pull, wt_other.branch)
358
 
 
359
334
    # TODO: jam 20051231 We need invasive failure tests, so that we can show
360
335
    #       performance even when something fails.
361
336
 
362
337
 
363
 
if not paramiko_loaded:
364
 
    del BoundSFTPBranch
365