1
# Copyright (C) 2006, 2007 Canonical Ltd
2
# Authors: Robert Collins <robert.collins@canonical.com>
1
# Copyright (C) 2006, 2007, 2009 Canonical Ltd
5
3
# This program is free software; you can redistribute it and/or modify
6
4
# it under the terms of the GNU General Public License as published by
15
13
# You should have received a copy of the GNU General Public License
16
14
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
17
"""Symbol versioning tests."""
23
21
from bzrlib import symbol_versioning
22
from bzrlib.symbol_versioning import (
24
28
from bzrlib.tests import TestCase
27
@symbol_versioning.deprecated_function(symbol_versioning.zero_seven)
28
def deprecated_function():
31
@deprecated_function(deprecated_in((0, 7, 0)))
32
def sample_deprecated_function():
29
33
"""Deprecated function docstring."""
33
a_deprecated_list = symbol_versioning.deprecated_list(symbol_versioning.zero_nine,
37
a_deprecated_list = symbol_versioning.deprecated_list(deprecated_in((0, 9, 0)),
34
38
'a_deprecated_list', ['one'], extra="Don't use me")
37
41
a_deprecated_dict = symbol_versioning.DeprecatedDict(
38
symbol_versioning.zero_fourteen,
42
deprecated_in((0, 14, 0)),
39
43
'a_deprecated_dict',
41
45
advice='Pull the other one!',
51
55
super(TestDeprecationWarnings, self).setUp()
52
56
self._warnings = []
54
@symbol_versioning.deprecated_method(symbol_versioning.zero_seven)
58
@deprecated_method(deprecated_in((0, 7, 0)))
55
59
def deprecated_method(self):
56
60
"""Deprecated method docstring.
58
62
This might explain stuff.
63
@symbol_versioning.deprecated_function(symbol_versioning.zero_seven)
67
@deprecated_function(deprecated_in((0, 7, 0)))
64
68
def deprecated_static():
65
69
"""Deprecated static."""
72
76
expected_warning = (
73
77
"bzrlib.tests.test_symbol_versioning."
74
78
"deprecated_static "
75
"was deprecated in version 0.7.", DeprecationWarning, 2)
79
"was deprecated in version 0.7.0.", DeprecationWarning, 2)
76
80
expected_docstring = (
77
81
'Deprecated static.\n'
79
'This function was deprecated in version 0.7.\n'
83
'This function was deprecated in version 0.7.0.\n'
81
85
self.check_deprecated_callable(
82
86
expected_warning, expected_docstring,
88
92
expected_warning = (
89
93
"bzrlib.tests.test_symbol_versioning."
90
94
"TestDeprecationWarnings.deprecated_method "
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'
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'
98
103
self.check_deprecated_callable(expected_warning, expected_docstring,
99
104
"deprecated_method",
100
105
"bzrlib.tests.test_symbol_versioning",
103
108
def test_deprecated_function(self):
104
109
expected_warning = (
105
"bzrlib.tests.test_symbol_versioning.deprecated_function "
106
"was deprecated in version 0.7.", DeprecationWarning, 2)
110
"bzrlib.tests.test_symbol_versioning.sample_deprecated_function "
111
"was deprecated in version 0.7.0.", DeprecationWarning, 2)
107
112
expected_docstring = ('Deprecated function docstring.\n'
109
'This function was deprecated in version 0.7.\n'
114
'This function was deprecated in version 0.7.0.\n'
111
116
self.check_deprecated_callable(expected_warning, expected_docstring,
112
"deprecated_function",
117
"sample_deprecated_function",
113
118
"bzrlib.tests.test_symbol_versioning",
119
sample_deprecated_function)
116
121
def test_deprecated_list(self):
117
122
expected_warning = (
118
"Modifying a_deprecated_list was deprecated in version 0.9."
123
"Modifying a_deprecated_list was deprecated in version 0.9.0."
119
124
" Don't use me", DeprecationWarning, 3)
120
125
old_warning_method = symbol_versioning.warn
154
159
def test_deprecated_dict(self):
155
160
expected_warning = (
156
"access to a_deprecated_dict was deprecated in version 0.14."
161
"access to a_deprecated_dict was deprecated in version 0.14.0."
157
162
" Pull the other one!", DeprecationWarning, 2)
158
163
old_warning_method = symbol_versioning.warn
188
193
self.assertTrue(deprecated_callable.is_deprecated)
190
195
symbol_versioning.set_warning_method(old_warning_method)
192
197
def test_deprecated_passed(self):
193
198
self.assertEqual(True, symbol_versioning.deprecated_passed(None))
194
199
self.assertEqual(True, symbol_versioning.deprecated_passed(True))
201
206
"""We can get a deprecation string for a method or function."""
202
207
self.assertEqual('bzrlib.tests.test_symbol_versioning.'
203
208
'TestDeprecationWarnings.test_deprecation_string was deprecated in '
205
210
symbol_versioning.deprecation_string(
206
self.test_deprecation_string, symbol_versioning.zero_eleven))
211
self.test_deprecation_string,
212
deprecated_in((0, 11, 0))))
207
213
self.assertEqual('bzrlib.symbol_versioning.deprecated_function was '
208
'deprecated in version 0.11.',
214
'deprecated in version 0.11.0.',
209
215
symbol_versioning.deprecation_string(
210
216
symbol_versioning.deprecated_function,
211
symbol_versioning.zero_eleven))
217
deprecated_in((0, 11, 0))))
214
220
class TestSuppressAndActivate(TestCase):
217
224
existing_filters = list(warnings.filters)
219
226
warnings.filters[:] = existing_filters