1
# Copyright (C) 2006, 2007, 2009 Canonical Ltd
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
# Authors: Robert Collins <robert.collins@canonical.com>
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
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
17
19
"""Symbol versioning tests."""
21
23
from bzrlib import symbol_versioning
22
from bzrlib.symbol_versioning import (
28
24
from bzrlib.tests import TestCase
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."""
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")
41
37
a_deprecated_dict = symbol_versioning.DeprecatedDict(
42
deprecated_in((0, 14, 0)),
38
symbol_versioning.zero_fourteen,
43
39
'a_deprecated_dict',
45
41
advice='Pull the other one!',
55
51
super(TestDeprecationWarnings, self).setUp()
56
52
self._warnings = []
58
@deprecated_method(deprecated_in((0, 7, 0)))
54
@symbol_versioning.deprecated_method(symbol_versioning.zero_seven)
59
55
def deprecated_method(self):
60
56
"""Deprecated method docstring.
76
72
expected_warning = (
77
73
"bzrlib.tests.test_symbol_versioning."
78
74
"deprecated_static "
79
"was deprecated in version 0.7.0.", DeprecationWarning, 2)
75
"was deprecated in version 0.7.", DeprecationWarning, 2)
80
76
expected_docstring = (
81
77
'Deprecated static.\n'
83
'This function was deprecated in version 0.7.0.\n'
79
'This function was deprecated in version 0.7.\n'
85
81
self.check_deprecated_callable(
86
82
expected_warning, expected_docstring,
92
88
expected_warning = (
93
89
"bzrlib.tests.test_symbol_versioning."
94
90
"TestDeprecationWarnings.deprecated_method "
95
"was deprecated in version 0.7.0.", DeprecationWarning, 2)
96
expected_docstring = (
97
'Deprecated method docstring.\n'
99
' This might explain stuff.\n'
101
' This method was deprecated in version 0.7.0.\n'
91
"was deprecated in version 0.7.", DeprecationWarning, 2)
92
expected_docstring = ('Deprecated method docstring.\n'
94
' This might explain stuff.\n'
96
' This method was deprecated in version 0.7.\n'
103
98
self.check_deprecated_callable(expected_warning, expected_docstring,
104
99
"deprecated_method",
105
100
"bzrlib.tests.test_symbol_versioning",
108
103
def test_deprecated_function(self):
109
104
expected_warning = (
110
"bzrlib.tests.test_symbol_versioning.sample_deprecated_function "
111
"was deprecated in version 0.7.0.", DeprecationWarning, 2)
105
"bzrlib.tests.test_symbol_versioning.deprecated_function "
106
"was deprecated in version 0.7.", DeprecationWarning, 2)
112
107
expected_docstring = ('Deprecated function docstring.\n'
114
'This function was deprecated in version 0.7.0.\n'
109
'This function was deprecated in version 0.7.\n'
116
111
self.check_deprecated_callable(expected_warning, expected_docstring,
117
"sample_deprecated_function",
112
"deprecated_function",
118
113
"bzrlib.tests.test_symbol_versioning",
119
sample_deprecated_function)
121
116
def test_deprecated_list(self):
122
117
expected_warning = (
123
"Modifying a_deprecated_list was deprecated in version 0.9.0."
118
"Modifying a_deprecated_list was deprecated in version 0.9."
124
119
" Don't use me", DeprecationWarning, 3)
125
120
old_warning_method = symbol_versioning.warn
159
154
def test_deprecated_dict(self):
160
155
expected_warning = (
161
"access to a_deprecated_dict was deprecated in version 0.14.0."
156
"access to a_deprecated_dict was deprecated in version 0.14."
162
157
" Pull the other one!", DeprecationWarning, 2)
163
158
old_warning_method = symbol_versioning.warn
206
201
"""We can get a deprecation string for a method or function."""
207
202
self.assertEqual('bzrlib.tests.test_symbol_versioning.'
208
203
'TestDeprecationWarnings.test_deprecation_string was deprecated in '
210
205
symbol_versioning.deprecation_string(
211
self.test_deprecation_string,
212
deprecated_in((0, 11, 0))))
206
self.test_deprecation_string, symbol_versioning.zero_eleven))
213
207
self.assertEqual('bzrlib.symbol_versioning.deprecated_function was '
214
'deprecated in version 0.11.0.',
208
'deprecated in version 0.11.',
215
209
symbol_versioning.deprecation_string(
216
210
symbol_versioning.deprecated_function,
217
deprecated_in((0, 11, 0))))
211
symbol_versioning.zero_eleven))
220
214
class TestSuppressAndActivate(TestCase):
224
217
existing_filters = list(warnings.filters)
226
219
warnings.filters[:] = existing_filters