30
a_deprecated_list = symbol_versioning.deprecated_list(symbol_versioning.zero_nine,
31
'a_deprecated_list', ['one'], extra="Don't use me")
30
34
class TestDeprecationWarnings(TestCase):
32
def capture_warning(self, message, category):
33
self._warnings.append((message, category))
36
def capture_warning(self, message, category, stacklevel=None):
37
self._warnings.append((message, category, stacklevel))
36
40
super(TestDeprecationWarnings, self).setUp()
48
52
expected_warning = (
49
53
"bzrlib.tests.test_symbol_versioning."
50
54
"TestDeprecationWarnings.deprecated_method "
51
"was deprecated in version 0.7.", DeprecationWarning)
55
"was deprecated in version 0.7.", DeprecationWarning, 2)
52
56
expected_docstring = ('Deprecated method docstring.\n'
54
58
' This might explain stuff.\n'
63
67
def test_deprecated_function(self):
64
68
expected_warning = (
65
69
"bzrlib.tests.test_symbol_versioning.deprecated_function "
66
"was deprecated in version 0.7.", DeprecationWarning)
70
"was deprecated in version 0.7.", DeprecationWarning, 2)
67
71
expected_docstring = ('Deprecated function docstring.\n'
69
73
'This function was deprecated in version 0.7.\n'
73
77
"bzrlib.tests.test_symbol_versioning",
74
78
deprecated_function)
80
def test_deprecated_list(self):
82
"Modifying a_deprecated_list was deprecated in version 0.9."
83
" Don't use me", DeprecationWarning, 3)
84
expected_doctstring = ('appending to a_deprecated_list is deprecated')
86
old_warning_method = symbol_versioning.warn
88
symbol_versioning.set_warning_method(self.capture_warning)
89
self.assertEqual(['one'], a_deprecated_list)
90
self.assertEqual([], self._warnings)
92
a_deprecated_list.append('foo')
93
self.assertEqual([expected_warning], self._warnings)
94
self.assertEqual(['one', 'foo'], a_deprecated_list)
96
a_deprecated_list.extend(['bar', 'baz'])
97
self.assertEqual([expected_warning]*2, self._warnings)
98
self.assertEqual(['one', 'foo', 'bar', 'baz'], a_deprecated_list)
100
a_deprecated_list.insert(1, 'xxx')
101
self.assertEqual([expected_warning]*3, self._warnings)
102
self.assertEqual(['one', 'xxx', 'foo', 'bar', 'baz'], a_deprecated_list)
104
a_deprecated_list.remove('foo')
105
self.assertEqual([expected_warning]*4, self._warnings)
106
self.assertEqual(['one', 'xxx', 'bar', 'baz'], a_deprecated_list)
108
val = a_deprecated_list.pop()
109
self.assertEqual([expected_warning]*5, self._warnings)
110
self.assertEqual('baz', val)
111
self.assertEqual(['one', 'xxx', 'bar'], a_deprecated_list)
113
val = a_deprecated_list.pop(1)
114
self.assertEqual([expected_warning]*6, self._warnings)
115
self.assertEqual('xxx', val)
116
self.assertEqual(['one', 'bar'], a_deprecated_list)
118
symbol_versioning.set_warning_method(old_warning_method)
76
120
def check_deprecated_callable(self, expected_warning, expected_docstring,
77
121
expected_name, expected_module,
78
122
deprecated_callable):
87
131
self.assertEqualDiff(expected_docstring, deprecated_callable.__doc__)
88
132
self.assertEqualDiff(expected_name, deprecated_callable.__name__)
89
133
self.assertEqualDiff(expected_module, deprecated_callable.__module__)
134
self.assertTrue(deprecated_callable.is_deprecated)
91
136
symbol_versioning.set_warning_method(old_warning_method)
138
def test_deprecated_passed(self):
139
self.assertEqual(True, symbol_versioning.deprecated_passed(None))
140
self.assertEqual(True, symbol_versioning.deprecated_passed(True))
141
self.assertEqual(True, symbol_versioning.deprecated_passed(False))
142
self.assertEqual(False,
143
symbol_versioning.deprecated_passed(
144
symbol_versioning.DEPRECATED_PARAMETER))