37
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
38
37
from bzrlib.tests.TestUtil import _load_module_by_name
39
38
import bzrlib.errors as errors
40
39
from bzrlib import symbol_versioning
41
from bzrlib.symbol_versioning import zero_ten, zero_eleven
42
40
from bzrlib.trace import note
43
from bzrlib.transport.memory import MemoryServer, MemoryTransport
44
41
from bzrlib.version import _get_bzr_source_tree
422
419
self.assertEqual(tests[1].transport_server, server1)
423
420
self.assertEqual(tests[1].transport_readonly_server, server2)
426
class TestTestCaseInTempDir(TestCaseInTempDir):
428
def test_home_is_not_working(self):
429
self.assertNotEqual(self.test_dir, self.test_home_dir)
430
cwd = osutils.getcwd()
431
self.assertEqual(self.test_dir, cwd)
432
self.assertEqual(self.test_home_dir, os.environ['HOME'])
435
422
class TestTestCaseWithTransport(TestCaseWithTransport):
436
423
"""Tests for the convenience functions TestCaseWithTransport introduces."""
476
463
self.assertRaises(AssertionError, self.assertIsDirectory, 'not_here', t)
479
class TestTestCaseTransports(TestCaseWithTransport):
482
super(TestTestCaseTransports, self).setUp()
483
self.transport_server = MemoryServer
485
def test_make_bzrdir_preserves_transport(self):
486
t = self.get_transport()
487
result_bzrdir = self.make_bzrdir('subdir')
488
self.assertIsInstance(result_bzrdir.transport,
490
# should not be on disk, should only be in memory
491
self.failIfExists('subdir')
494
466
class TestChrootedTest(ChrootedTestCase):
496
468
def test_root_is_root(self):
746
718
output_string = output.getvalue()
747
719
self.assertContainsRe(output_string, "--date [0-9.]+")
748
720
if workingtree is not None:
749
revision_id = workingtree.get_parent_ids()[0]
721
revision_id = workingtree.last_revision()
750
722
self.assertEndsWith(output_string.rstrip(), revision_id)
826
798
self.assertIsInstance(self._benchcalls[1][1], bzrlib.lsprof.Stats)
829
@symbol_versioning.deprecated_function(zero_eleven)
830
def sample_deprecated_function():
831
"""A deprecated function to test applyDeprecated with."""
835
def sample_undeprecated_function(a_param):
836
"""A undeprecated function to test applyDeprecated with."""
839
class ApplyDeprecatedHelper(object):
840
"""A helper class for ApplyDeprecated tests."""
842
@symbol_versioning.deprecated_method(zero_eleven)
843
def sample_deprecated_method(self, param_one):
844
"""A deprecated method for testing with."""
847
def sample_normal_method(self):
848
"""A undeprecated method."""
850
@symbol_versioning.deprecated_method(zero_ten)
851
def sample_nested_deprecation(self):
852
return sample_deprecated_function()
855
801
class TestExtraAssertions(TestCase):
856
802
"""Tests for new test assertions in bzrlib test suite"""
865
811
self.assertEndsWith('foo', 'oo')
866
812
self.assertRaises(AssertionError, self.assertEndsWith, 'o', 'oo')
868
def test_applyDeprecated_not_deprecated(self):
869
sample_object = ApplyDeprecatedHelper()
870
# calling an undeprecated callable raises an assertion
871
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
872
sample_object.sample_normal_method)
873
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
874
sample_undeprecated_function, "a param value")
875
# calling a deprecated callable (function or method) with the wrong
876
# expected deprecation fails.
877
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
878
sample_object.sample_deprecated_method, "a param value")
879
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
880
sample_deprecated_function)
881
# calling a deprecated callable (function or method) with the right
882
# expected deprecation returns the functions result.
883
self.assertEqual("a param value", self.applyDeprecated(zero_eleven,
884
sample_object.sample_deprecated_method, "a param value"))
885
self.assertEqual(2, self.applyDeprecated(zero_eleven,
886
sample_deprecated_function))
887
# calling a nested deprecation with the wrong deprecation version
888
# fails even if a deeper nested function was deprecated with the
890
self.assertRaises(AssertionError, self.applyDeprecated,
891
zero_eleven, sample_object.sample_nested_deprecation)
892
# calling a nested deprecation with the right deprecation value
893
# returns the calls result.
894
self.assertEqual(2, self.applyDeprecated(zero_ten,
895
sample_object.sample_nested_deprecation))
897
814
def test_callDeprecated(self):
898
815
def testfunc(be_deprecated, result=None):
899
816
if be_deprecated is True:
904
821
self.assertIs(None, result)
905
822
result = self.callDeprecated([], testfunc, False, 'result')
906
823
self.assertEqual('result', result)
907
self.callDeprecated(['i am deprecated'], testfunc, be_deprecated=True)
824
self.callDeprecated(['i am deprecated'], testfunc,
908
826
self.callDeprecated([], testfunc, be_deprecated=False)
920
838
self.assertIsInstance(bzrlib.bzrdir.BzrDir.open('b')._format,
921
839
bzrlib.bzrdir.BzrDirFormat6)
923
def test_make_branch_and_mutable_tree(self):
924
# we should be able to get a new branch and a mutable tree from
925
# TestCaseWithTransport
926
tree = self.make_branch_and_memory_tree('a')
927
self.assertIsInstance(tree, bzrlib.memorytree.MemoryTree)
930
class TestSFTPMakeBranchAndTree(TestCaseWithSFTPServer):
932
def test_make_tree_for_sftp_branch(self):
933
"""Transports backed by local directories create local trees."""
935
tree = self.make_branch_and_tree('t1')
936
base = tree.bzrdir.root_transport.base
937
self.failIf(base.startswith('sftp'),
938
'base %r is on sftp but should be local' % base)
939
self.assertEquals(tree.bzrdir.root_transport,
940
tree.branch.bzrdir.root_transport)
941
self.assertEquals(tree.bzrdir.root_transport,
942
tree.branch.repository.bzrdir.root_transport)
945
842
class TestSelftest(TestCase):
946
843
"""Tests of bzrlib.tests.selftest."""