219
219
warnings.filters[:] = existing_filters
220
220
self.addCleanup(restore)
221
# Clean out the filters so we have a clean slate.
222
warnings.resetwarnings()
222
224
def assertFirstWarning(self, action, category):
223
225
"""Test the first warning in the filters is correct"""
229
231
symbol_versioning.suppress_deprecation_warnings()
230
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('ignore', category=Warning)
237
self.assertFirstWarning('ignore', Warning)
238
self.assertEqual(1, len(warnings.filters))
239
symbol_versioning.suppress_deprecation_warnings()
240
self.assertFirstWarning('ignore', 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('ignore', category=DeprecationWarning)
246
self.assertFirstWarning('ignore', DeprecationWarning)
247
self.assertEqual(1, len(warnings.filters))
248
symbol_versioning.suppress_deprecation_warnings()
249
self.assertFirstWarning('ignore', DeprecationWarning)
250
self.assertEqual(1, len(warnings.filters))
232
252
def test_activate_deprecation_warnings(self):
233
253
symbol_versioning.activate_deprecation_warnings(always=True)
234
254
self.assertFirstWarning('default', DeprecationWarning)
236
256
def test_activate_deprecation_no_error(self):
237
257
# First nuke the filters, so we know it is clean
238
warnings.resetwarnings()
239
258
symbol_versioning.activate_deprecation_warnings(always=False)
240
259
self.assertFirstWarning('default', DeprecationWarning)
242
261
def test_activate_deprecation_with_error(self):
243
262
# First nuke the filters, so we know it is clean
244
warnings.resetwarnings()
245
263
# Add a warning == error rule
246
264
warnings.filterwarnings('error', category=Warning)
247
265
self.assertFirstWarning('error', Warning)
254
272
def test_activate_deprecation_with_DW_error(self):
255
273
# First nuke the filters, so we know it is clean
256
warnings.resetwarnings()
257
274
# Add a warning == error rule
258
275
warnings.filterwarnings('error', category=DeprecationWarning)
259
276
self.assertFirstWarning('error', DeprecationWarning)