30
a_deprecated_list = symbol_versioning.deprecated_list(symbol_versioning.zero_nine,
31
'a_deprecated_list', ['one'], extra="Don't use me")
34
a_deprecated_dict = symbol_versioning.DeprecatedDict(
35
symbol_versioning.zero_fourteen,
38
advice='Pull the other one!',
42
30
class TestDeprecationWarnings(TestCase):
44
32
def capture_warning(self, message, category, stacklevel=None):
85
73
"bzrlib.tests.test_symbol_versioning",
86
74
deprecated_function)
88
def test_deprecated_list(self):
90
"Modifying a_deprecated_list was deprecated in version 0.9."
91
" Don't use me", DeprecationWarning, 3)
92
old_warning_method = symbol_versioning.warn
94
symbol_versioning.set_warning_method(self.capture_warning)
95
self.assertEqual(['one'], a_deprecated_list)
96
self.assertEqual([], self._warnings)
98
a_deprecated_list.append('foo')
99
self.assertEqual([expected_warning], self._warnings)
100
self.assertEqual(['one', 'foo'], a_deprecated_list)
102
a_deprecated_list.extend(['bar', 'baz'])
103
self.assertEqual([expected_warning]*2, self._warnings)
104
self.assertEqual(['one', 'foo', 'bar', 'baz'], a_deprecated_list)
106
a_deprecated_list.insert(1, 'xxx')
107
self.assertEqual([expected_warning]*3, self._warnings)
108
self.assertEqual(['one', 'xxx', 'foo', 'bar', 'baz'], a_deprecated_list)
110
a_deprecated_list.remove('foo')
111
self.assertEqual([expected_warning]*4, self._warnings)
112
self.assertEqual(['one', 'xxx', 'bar', 'baz'], a_deprecated_list)
114
val = a_deprecated_list.pop()
115
self.assertEqual([expected_warning]*5, self._warnings)
116
self.assertEqual('baz', val)
117
self.assertEqual(['one', 'xxx', 'bar'], a_deprecated_list)
119
val = a_deprecated_list.pop(1)
120
self.assertEqual([expected_warning]*6, self._warnings)
121
self.assertEqual('xxx', val)
122
self.assertEqual(['one', 'bar'], a_deprecated_list)
124
symbol_versioning.set_warning_method(old_warning_method)
126
def test_deprecated_dict(self):
128
"access to a_deprecated_dict was deprecated in version 0.14."
129
" Pull the other one!", DeprecationWarning, 2)
130
old_warning_method = symbol_versioning.warn
132
symbol_versioning.set_warning_method(self.capture_warning)
133
self.assertEqual(len(a_deprecated_dict), 1)
134
self.assertEqual([expected_warning], self._warnings)
136
a_deprecated_dict['b'] = 42
137
self.assertEqual(a_deprecated_dict['b'], 42)
138
self.assertTrue('b' in a_deprecated_dict)
139
del a_deprecated_dict['b']
140
self.assertFalse('b' in a_deprecated_dict)
141
self.assertEqual([expected_warning] * 6, self._warnings)
143
symbol_versioning.set_warning_method(old_warning_method)
146
76
def check_deprecated_callable(self, expected_warning, expected_docstring,
147
77
expected_name, expected_module,
148
78
deprecated_callable):
168
98
self.assertEqual(False,
169
99
symbol_versioning.deprecated_passed(
170
100
symbol_versioning.DEPRECATED_PARAMETER))
172
def test_deprecation_string(self):
173
"""We can get a deprecation string for a method or function."""
174
self.assertEqual('bzrlib.tests.test_symbol_versioning.'
175
'TestDeprecationWarnings.test_deprecation_string was deprecated in '
177
symbol_versioning.deprecation_string(
178
self.test_deprecation_string, symbol_versioning.zero_eleven))
179
self.assertEqual('bzrlib.symbol_versioning.deprecated_function was '
180
'deprecated in version 0.11.',
181
symbol_versioning.deprecation_string(
182
symbol_versioning.deprecated_function,
183
symbol_versioning.zero_eleven))