33
35
UnsupportedFormatError,
35
37
import bzrlib.repository as repository
36
from bzrlib.tests import TestCase, TestCaseWithTransport
38
from bzrlib.tests import TestCase, TestCaseWithTransport, test_sftp_transport
37
39
from bzrlib.tests.HttpServer import HttpServer
38
40
from bzrlib.transport import get_transport
39
41
from bzrlib.transport.memory import MemoryServer
422
424
get_transport(self.get_readonly_url('g/p/q')))
423
425
self.assertEqual('g/p/q', relpath)
427
def test_open_containing_tree_or_branch(self):
428
def local_branch_path(branch):
429
return os.path.realpath(
430
urlutils.local_path_from_url(branch.base))
432
self.make_branch_and_tree('topdir')
433
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
435
self.assertEqual(os.path.realpath('topdir'),
436
os.path.realpath(tree.basedir))
437
self.assertEqual(os.path.realpath('topdir'),
438
local_branch_path(branch))
439
self.assertIs(tree.bzrdir, branch.bzrdir)
440
self.assertEqual('foo', relpath)
441
self.make_branch('topdir/foo')
442
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
444
self.assertIs(tree, None)
445
self.assertEqual(os.path.realpath('topdir/foo'),
446
local_branch_path(branch))
447
self.assertEqual('', relpath)
425
449
def test_open_from_transport(self):
426
450
# transport pointing at bzrdir should give a bzrdir with root transport
427
451
# set to the given transport
645
669
result.open_branch()
646
670
result.open_repository()
673
class TestRemoteSFTP(test_sftp_transport.TestCaseWithSFTPServer):
675
def test_open_containing_tree_or_branch(self):
676
tree = self.make_branch_and_tree('tree')
677
bzrdir.BzrDir.open_containing_tree_or_branch(self.get_url('tree'))