37
37
from bzrlib.tests.TestUtil import _load_module_by_name
38
38
import bzrlib.errors as errors
39
39
from bzrlib import symbol_versioning
40
from bzrlib.symbol_versioning import zero_ten, zero_eleven
40
41
from bzrlib.trace import note
41
42
from bzrlib.version import _get_bzr_source_tree
798
799
self.assertIsInstance(self._benchcalls[1][1], bzrlib.lsprof.Stats)
802
@symbol_versioning.deprecated_function(zero_eleven)
803
def sample_deprecated_function():
804
"""A deprecated function to test applyDeprecated with."""
808
def sample_undeprecated_function(a_param):
809
"""A undeprecated function to test applyDeprecated with."""
812
class ApplyDeprecatedHelper(object):
813
"""A helper class for ApplyDeprecated tests."""
815
@symbol_versioning.deprecated_method(zero_eleven)
816
def sample_deprecated_method(self, param_one):
817
"""A deprecated method for testing with."""
820
def sample_normal_method(self):
821
"""A undeprecated method."""
823
@symbol_versioning.deprecated_method(zero_ten)
824
def sample_nested_deprecation(self):
825
return sample_deprecated_function()
801
828
class TestExtraAssertions(TestCase):
802
829
"""Tests for new test assertions in bzrlib test suite"""
811
838
self.assertEndsWith('foo', 'oo')
812
839
self.assertRaises(AssertionError, self.assertEndsWith, 'o', 'oo')
841
def test_applyDeprecated_not_deprecated(self):
842
sample_object = ApplyDeprecatedHelper()
843
# calling an undeprecated callable raises an assertion
844
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
845
sample_object.sample_normal_method)
846
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
847
sample_undeprecated_function, "a param value")
848
# calling a deprecated callable (function or method) with the wrong
849
# expected deprecation fails.
850
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
851
sample_object.sample_deprecated_method, "a param value")
852
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
853
sample_deprecated_function)
854
# calling a deprecated callable (function or method) with the right
855
# expected deprecation returns the functions result.
856
self.assertEqual("a param value", self.applyDeprecated(zero_eleven,
857
sample_object.sample_deprecated_method, "a param value"))
858
self.assertEqual(2, self.applyDeprecated(zero_eleven,
859
sample_deprecated_function))
860
# calling a nested deprecation with the wrong deprecation version
861
# fails even if a deeper nested function was deprecated with the
863
self.assertRaises(AssertionError, self.applyDeprecated,
864
zero_eleven, sample_object.sample_nested_deprecation)
865
# calling a nested deprecation with the right deprecation value
866
# returns the calls result.
867
self.assertEqual(2, self.applyDeprecated(zero_ten,
868
sample_object.sample_nested_deprecation))
814
870
def test_callDeprecated(self):
815
871
def testfunc(be_deprecated, result=None):
816
872
if be_deprecated is True:
821
877
self.assertIs(None, result)
822
878
result = self.callDeprecated([], testfunc, False, 'result')
823
879
self.assertEqual('result', result)
824
self.callDeprecated(['i am deprecated'], testfunc,
880
self.callDeprecated(['i am deprecated'], testfunc, be_deprecated=True)
826
881
self.callDeprecated([], testfunc, be_deprecated=False)