~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: 2009-03-06 06:48:25 UTC
  • mfrom: (4070.8.6 debug-config)
  • Revision ID: pqm@pqm.ubuntu.com-20090306064825-kbpwggw21dygeix6
(mbp) debug_flags configuration option

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
 
2
#   Authors: Robert Collins <robert.collins@canonical.com>
 
3
#   and others
2
4
#
3
5
# This program is free software; you can redistribute it and/or modify
4
6
# it under the terms of the GNU General Public License as published by
12
14
#
13
15
# You should have received a copy of the GNU General Public License
14
16
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
18
 
17
19
"""Symbol versioning tests."""
18
20
 
19
21
import warnings
20
22
 
21
23
from bzrlib import symbol_versioning
22
 
from bzrlib.symbol_versioning import (
23
 
    deprecated_function,
24
 
    deprecated_in,
25
 
    deprecated_list,
26
 
    deprecated_method,
27
 
    )
28
24
from bzrlib.tests import TestCase
29
25
 
30
26
 
31
 
@deprecated_function(deprecated_in((0, 7, 0)))
32
 
def sample_deprecated_function():
 
27
@symbol_versioning.deprecated_function(symbol_versioning.zero_seven)
 
28
def deprecated_function():
33
29
    """Deprecated function docstring."""
34
30
    return 1
35
31
 
36
32
 
37
 
a_deprecated_list = symbol_versioning.deprecated_list(deprecated_in((0, 9, 0)),
 
33
a_deprecated_list = symbol_versioning.deprecated_list(symbol_versioning.zero_nine,
38
34
    'a_deprecated_list', ['one'], extra="Don't use me")
39
35
 
40
36
 
41
37
a_deprecated_dict = symbol_versioning.DeprecatedDict(
42
 
    deprecated_in((0, 14, 0)),
 
38
    symbol_versioning.zero_fourteen,
43
39
    'a_deprecated_dict',
44
40
    dict(a=42),
45
41
    advice='Pull the other one!',
54
50
    def setUp(self):
55
51
        super(TestDeprecationWarnings, self).setUp()
56
52
        self._warnings = []
57
 
    
58
 
    @deprecated_method(deprecated_in((0, 7, 0)))
 
53
 
 
54
    @symbol_versioning.deprecated_method(symbol_versioning.zero_seven)
59
55
    def deprecated_method(self):
60
56
        """Deprecated method docstring.
61
57
 
64
60
        return 1
65
61
 
66
62
    @staticmethod
67
 
    @deprecated_function(deprecated_in((0, 7, 0)))
 
63
    @symbol_versioning.deprecated_function(symbol_versioning.zero_seven)
68
64
    def deprecated_static():
69
65
        """Deprecated static."""
70
66
        return 1
106
102
 
107
103
    def test_deprecated_function(self):
108
104
        expected_warning = (
109
 
            "bzrlib.tests.test_symbol_versioning.sample_deprecated_function "
 
105
            "bzrlib.tests.test_symbol_versioning.deprecated_function "
110
106
            "was deprecated in version 0.7.", DeprecationWarning, 2)
111
107
        expected_docstring = ('Deprecated function docstring.\n'
112
108
                              '\n'
113
109
                              'This function was deprecated in version 0.7.\n'
114
110
                              )
115
111
        self.check_deprecated_callable(expected_warning, expected_docstring,
116
 
                                       "sample_deprecated_function",
 
112
                                       "deprecated_function",
117
113
                                       "bzrlib.tests.test_symbol_versioning",
118
 
                                       sample_deprecated_function)
 
114
                                       deprecated_function)
119
115
 
120
116
    def test_deprecated_list(self):
121
117
        expected_warning = (
207
203
            'TestDeprecationWarnings.test_deprecation_string was deprecated in '
208
204
            'version 0.11.',
209
205
            symbol_versioning.deprecation_string(
210
 
            self.test_deprecation_string,
211
 
            deprecated_in((0, 11, 0))))
 
206
            self.test_deprecation_string, symbol_versioning.zero_eleven))
212
207
        self.assertEqual('bzrlib.symbol_versioning.deprecated_function was '
213
208
            'deprecated in version 0.11.',
214
209
            symbol_versioning.deprecation_string(
215
210
                symbol_versioning.deprecated_function,
216
 
                deprecated_in((0, 11, 0))))
 
211
                symbol_versioning.zero_eleven))
217
212
 
218
213
 
219
214
class TestSuppressAndActivate(TestCase):
220
215
 
221
216
    def setUp(self):
222
 
        TestCase.setUp(self)
223
217
        existing_filters = list(warnings.filters)
224
218
        def restore():
225
219
            warnings.filters[:] = existing_filters