37
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
37
38
from bzrlib.tests.TestUtil import _load_module_by_name
38
39
import bzrlib.errors as errors
39
40
from bzrlib import symbol_versioning
41
from bzrlib.symbol_versioning import zero_ten, zero_eleven
40
42
from bzrlib.trace import note
43
from bzrlib.transport.memory import MemoryServer, MemoryTransport
41
44
from bzrlib.version import _get_bzr_source_tree
419
422
self.assertEqual(tests[1].transport_server, server1)
420
423
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'])
422
435
class TestTestCaseWithTransport(TestCaseWithTransport):
423
436
"""Tests for the convenience functions TestCaseWithTransport introduces."""
463
476
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')
466
494
class TestChrootedTest(ChrootedTestCase):
468
496
def test_root_is_root(self):
718
746
output_string = output.getvalue()
719
747
self.assertContainsRe(output_string, "--date [0-9.]+")
720
748
if workingtree is not None:
721
revision_id = workingtree.last_revision()
749
revision_id = workingtree.get_parent_ids()[0]
722
750
self.assertEndsWith(output_string.rstrip(), revision_id)
798
826
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()
801
855
class TestExtraAssertions(TestCase):
802
856
"""Tests for new test assertions in bzrlib test suite"""
811
865
self.assertEndsWith('foo', 'oo')
812
866
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))
814
897
def test_callDeprecated(self):
815
898
def testfunc(be_deprecated, result=None):
816
899
if be_deprecated is True:
821
904
self.assertIs(None, result)
822
905
result = self.callDeprecated([], testfunc, False, 'result')
823
906
self.assertEqual('result', result)
824
self.callDeprecated(['i am deprecated'], testfunc,
907
self.callDeprecated(['i am deprecated'], testfunc, be_deprecated=True)
826
908
self.callDeprecated([], testfunc, be_deprecated=False)
839
921
bzrlib.bzrdir.BzrDirFormat6)
924
class TestSFTPMakeBranchAndTree(TestCaseWithSFTPServer):
926
def test_make_tree_for_sftp_branch(self):
927
"""Transports backed by local directories create local trees."""
929
tree = self.make_branch_and_tree('t1')
930
base = tree.bzrdir.root_transport.base
931
self.failIf(base.startswith('sftp'),
932
'base %r is on sftp but should be local' % base)
933
self.assertEquals(tree.bzrdir.root_transport,
934
tree.branch.bzrdir.root_transport)
935
self.assertEquals(tree.bzrdir.root_transport,
936
tree.branch.repository.bzrdir.root_transport)
842
939
class TestSelftest(TestCase):
843
940
"""Tests of bzrlib.tests.selftest."""