63
@symbol_versioning.deprecated_function(symbol_versioning.zero_seven)
64
def deprecated_static():
65
"""Deprecated static."""
68
def test_deprecated_static(self):
69
# XXX: The results are not quite right because the class name is not
70
# shown - however it is enough to give people a good indication of
71
# where the problem is.
73
"bzrlib.tests.test_symbol_versioning."
75
"was deprecated in version 0.7.", DeprecationWarning, 2)
76
expected_docstring = (
77
'Deprecated static.\n'
79
'This function was deprecated in version 0.7.\n'
81
self.check_deprecated_callable(
82
expected_warning, expected_docstring,
84
"bzrlib.tests.test_symbol_versioning",
85
self.deprecated_static)
59
87
def test_deprecated_method(self):
60
88
expected_warning = (
61
89
"bzrlib.tests.test_symbol_versioning."
181
209
symbol_versioning.deprecation_string(
182
210
symbol_versioning.deprecated_function,
183
211
symbol_versioning.zero_eleven))
214
class TestSuppressAndActivate(TestCase):
217
existing_filters = list(warnings.filters)
219
warnings.filters[:] = existing_filters
220
self.addCleanup(restore)
221
# Clean out the filters so we have a clean slate.
222
warnings.resetwarnings()
224
def assertFirstWarning(self, action, category):
225
"""Test the first warning in the filters is correct"""
226
first = warnings.filters[0]
227
self.assertEqual((action, category), (first[0], first[2]))
229
def test_suppress_deprecation_warnings(self):
230
"""suppress_deprecation_warnings sets DeprecationWarning to ignored."""
231
symbol_versioning.suppress_deprecation_warnings()
232
self.assertFirstWarning('ignore', DeprecationWarning)
234
def test_suppress_deprecation_with_warning_filter(self):
235
"""don't suppress if we already have a filter"""
236
warnings.filterwarnings('error', category=Warning)
237
self.assertFirstWarning('error', Warning)
238
self.assertEqual(1, len(warnings.filters))
239
symbol_versioning.suppress_deprecation_warnings(override=False)
240
self.assertFirstWarning('error', Warning)
241
self.assertEqual(1, len(warnings.filters))
243
def test_suppress_deprecation_with_filter(self):
244
"""don't suppress if we already have a filter"""
245
warnings.filterwarnings('error', category=DeprecationWarning)
246
self.assertFirstWarning('error', DeprecationWarning)
247
self.assertEqual(1, len(warnings.filters))
248
symbol_versioning.suppress_deprecation_warnings(override=False)
249
self.assertFirstWarning('error', DeprecationWarning)
250
self.assertEqual(1, len(warnings.filters))
251
symbol_versioning.suppress_deprecation_warnings(override=True)
252
self.assertFirstWarning('ignore', DeprecationWarning)
253
self.assertEqual(2, len(warnings.filters))
255
def test_activate_deprecation_no_error(self):
256
# First nuke the filters, so we know it is clean
257
symbol_versioning.activate_deprecation_warnings()
258
self.assertFirstWarning('default', DeprecationWarning)
260
def test_activate_deprecation_with_error(self):
261
# First nuke the filters, so we know it is clean
262
# Add a warning == error rule
263
warnings.filterwarnings('error', category=Warning)
264
self.assertFirstWarning('error', Warning)
265
self.assertEqual(1, len(warnings.filters))
266
symbol_versioning.activate_deprecation_warnings(override=False)
267
# There should not be a new warning
268
self.assertFirstWarning('error', Warning)
269
self.assertEqual(1, len(warnings.filters))
271
def test_activate_deprecation_with_DW_error(self):
272
# First nuke the filters, so we know it is clean
273
# Add a warning == error rule
274
warnings.filterwarnings('error', category=DeprecationWarning)
275
self.assertFirstWarning('error', DeprecationWarning)
276
self.assertEqual(1, len(warnings.filters))
277
symbol_versioning.activate_deprecation_warnings(override=False)
278
# There should not be a new warning
279
self.assertFirstWarning('error', DeprecationWarning)
280
self.assertEqual(1, len(warnings.filters))
281
symbol_versioning.activate_deprecation_warnings(override=True)
282
self.assertFirstWarning('default', DeprecationWarning)
283
self.assertEqual(2, len(warnings.filters))