~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_symbol_versioning.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-11-04 18:51:39 UTC
  • mfrom: (2961.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20071104185139-kaio3sneodg2kp71
Authentication ring implementation (read-only)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
"""Symbol versioning tests."""
20
20
 
21
 
import warnings
22
 
 
23
 
from bzrlib import symbol_versioning
 
21
import bzrlib.symbol_versioning as symbol_versioning
24
22
from bzrlib.tests import TestCase
25
23
 
26
24
 
209
207
            symbol_versioning.deprecation_string(
210
208
                symbol_versioning.deprecated_function,
211
209
                symbol_versioning.zero_eleven))
212
 
 
213
 
 
214
 
class TestSuppressAndActivate(TestCase):
215
 
 
216
 
    def setUp(self):
217
 
        existing_filters = list(warnings.filters)
218
 
        def restore():
219
 
            warnings.filters[:] = existing_filters
220
 
        self.addCleanup(restore)
221
 
        # Clean out the filters so we have a clean slate.
222
 
        warnings.resetwarnings()
223
 
 
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]))
228
 
 
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)
233
 
 
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))
242
 
 
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))
254
 
 
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)
259
 
 
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))
270
 
 
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))