~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_symbol_versioning.py

  • Committer: Aaron Bentley
  • Date: 2007-02-06 14:52:16 UTC
  • mfrom: (2266 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2268.
  • Revision ID: abentley@panoramicfeedback.com-20070206145216-fcpi8o3ufvuzwbp9
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
 
#   and others
4
3
#
5
4
# This program is free software; you can redistribute it and/or modify
6
5
# it under the terms of the GNU General Public License as published by
18
17
 
19
18
"""Symbol versioning tests."""
20
19
 
21
 
import warnings
22
 
 
23
 
from bzrlib import symbol_versioning
 
20
import bzrlib.symbol_versioning as symbol_versioning
24
21
from bzrlib.tests import TestCase
25
22
 
26
23
 
59
56
        """
60
57
        return 1
61
58
 
62
 
    @staticmethod
63
 
    @symbol_versioning.deprecated_function(symbol_versioning.zero_seven)
64
 
    def deprecated_static():
65
 
        """Deprecated static."""
66
 
        return 1
67
 
 
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.
72
 
        expected_warning = (
73
 
            "bzrlib.tests.test_symbol_versioning."
74
 
            "deprecated_static "
75
 
            "was deprecated in version 0.7.", DeprecationWarning, 2)
76
 
        expected_docstring = (
77
 
            'Deprecated static.\n'
78
 
            '\n'
79
 
            'This function was deprecated in version 0.7.\n'
80
 
            )
81
 
        self.check_deprecated_callable(
82
 
            expected_warning, expected_docstring,
83
 
            "deprecated_static",
84
 
            "bzrlib.tests.test_symbol_versioning",
85
 
            self.deprecated_static)
86
 
 
87
59
    def test_deprecated_method(self):
88
60
        expected_warning = (
89
61
            "bzrlib.tests.test_symbol_versioning."
209
181
            symbol_versioning.deprecation_string(
210
182
                symbol_versioning.deprecated_function,
211
183
                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))