25
from bzrlib import osutils
25
from bzrlib import osutils, memorytree
27
27
from bzrlib.progress import _BaseProgressBar
28
28
from bzrlib.tests import (
32
TestCaseWithMemoryTransport,
32
33
TestCaseWithTransport,
38
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
37
39
from bzrlib.tests.TestUtil import _load_module_by_name
38
40
import bzrlib.errors as errors
39
41
from bzrlib import symbol_versioning
40
42
from bzrlib.symbol_versioning import zero_ten, zero_eleven
41
43
from bzrlib.trace import note
44
from bzrlib.transport.memory import MemoryServer, MemoryTransport
42
45
from bzrlib.version import _get_bzr_source_tree
430
433
self.assertEqual(self.test_home_dir, os.environ['HOME'])
436
class TestTestCaseWithMemoryTransport(TestCaseWithMemoryTransport):
438
def test_home_is_non_existant_dir_under_root(self):
439
"""The test_home_dir for TestCaseWithMemoryTransport is missing.
441
This is because TestCaseWithMemoryTransport is for tests that do not
442
need any disk resources: they should be hooked into bzrlib in such a
443
way that no global settings are being changed by the test (only a
444
few tests should need to do that), and having a missing dir as home is
445
an effective way to ensure that this is the case.
447
self.assertEqual(self.TEST_ROOT + "/MemoryTransportMissingHomeDir",
449
self.assertEqual(self.test_home_dir, os.environ['HOME'])
451
def test_cwd_is_TEST_ROOT(self):
452
self.assertEqual(self.test_dir, self.TEST_ROOT)
453
cwd = osutils.getcwd()
454
self.assertEqual(self.test_dir, cwd)
456
def test_make_branch_and_memory_tree(self):
457
"""In TestCaseWithMemoryTransport we should not make the branch on disk.
459
This is hard to comprehensively robustly test, so we settle for making
460
a branch and checking no directory was created at its relpath.
462
tree = self.make_branch_and_memory_tree('dir')
463
self.failIfExists('dir')
464
self.assertIsInstance(tree, memorytree.MemoryTree)
433
467
class TestTestCaseWithTransport(TestCaseWithTransport):
434
468
"""Tests for the convenience functions TestCaseWithTransport introduces."""
474
508
self.assertRaises(AssertionError, self.assertIsDirectory, 'not_here', t)
511
class TestTestCaseTransports(TestCaseWithTransport):
514
super(TestTestCaseTransports, self).setUp()
515
self.transport_server = MemoryServer
517
def test_make_bzrdir_preserves_transport(self):
518
t = self.get_transport()
519
result_bzrdir = self.make_bzrdir('subdir')
520
self.assertIsInstance(result_bzrdir.transport,
522
# should not be on disk, should only be in memory
523
self.failIfExists('subdir')
477
526
class TestChrootedTest(ChrootedTestCase):
479
528
def test_root_is_root(self):
729
778
output_string = output.getvalue()
730
779
self.assertContainsRe(output_string, "--date [0-9.]+")
731
780
if workingtree is not None:
732
revision_id = workingtree.last_revision()
781
revision_id = workingtree.get_parent_ids()[0]
733
782
self.assertEndsWith(output_string.rstrip(), revision_id)
910
959
self.assertIsInstance(tree, bzrlib.memorytree.MemoryTree)
962
class TestSFTPMakeBranchAndTree(TestCaseWithSFTPServer):
964
def test_make_tree_for_sftp_branch(self):
965
"""Transports backed by local directories create local trees."""
967
tree = self.make_branch_and_tree('t1')
968
base = tree.bzrdir.root_transport.base
969
self.failIf(base.startswith('sftp'),
970
'base %r is on sftp but should be local' % base)
971
self.assertEquals(tree.bzrdir.root_transport,
972
tree.branch.bzrdir.root_transport)
973
self.assertEquals(tree.bzrdir.root_transport,
974
tree.branch.repository.bzrdir.root_transport)
913
977
class TestSelftest(TestCase):
914
978
"""Tests of bzrlib.tests.selftest."""