14
13
# You should have received a copy of the GNU General Public License
15
14
# along with this program; if not, write to the Free Software
16
# 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
18
17
"""Symbol versioning tests."""
20
import bzrlib.symbol_versioning as symbol_versioning
21
from bzrlib import symbol_versioning
22
from bzrlib.symbol_versioning import (
21
28
from bzrlib.tests import TestCase
24
@symbol_versioning.deprecated_function(symbol_versioning.zero_seven)
25
def deprecated_function():
31
@deprecated_function(deprecated_in((0, 7, 0)))
32
def sample_deprecated_function():
26
33
"""Deprecated function docstring."""
30
a_deprecated_list = symbol_versioning.deprecated_list(symbol_versioning.zero_nine,
37
a_deprecated_list = symbol_versioning.deprecated_list(deprecated_in((0, 9, 0)),
31
38
'a_deprecated_list', ['one'], extra="Don't use me")
34
41
a_deprecated_dict = symbol_versioning.DeprecatedDict(
35
symbol_versioning.zero_fourteen,
42
deprecated_in((0, 14, 0)),
36
43
'a_deprecated_dict',
38
45
advice='Pull the other one!',
48
55
super(TestDeprecationWarnings, self).setUp()
49
56
self._warnings = []
51
@symbol_versioning.deprecated_method(symbol_versioning.zero_seven)
58
@deprecated_method(deprecated_in((0, 7, 0)))
52
59
def deprecated_method(self):
53
60
"""Deprecated method docstring.
55
62
This might explain stuff.
67
@deprecated_function(deprecated_in((0, 7, 0)))
68
def deprecated_static():
69
"""Deprecated static."""
72
def test_deprecated_static(self):
73
# XXX: The results are not quite right because the class name is not
74
# shown - however it is enough to give people a good indication of
75
# where the problem is.
77
"bzrlib.tests.test_symbol_versioning."
79
"was deprecated in version 0.7.", DeprecationWarning, 2)
80
expected_docstring = (
81
'Deprecated static.\n'
83
'This function was deprecated in version 0.7.\n'
85
self.check_deprecated_callable(
86
expected_warning, expected_docstring,
88
"bzrlib.tests.test_symbol_versioning",
89
self.deprecated_static)
59
91
def test_deprecated_method(self):
60
92
expected_warning = (
61
93
"bzrlib.tests.test_symbol_versioning."
62
94
"TestDeprecationWarnings.deprecated_method "
63
95
"was deprecated in version 0.7.", DeprecationWarning, 2)
64
96
expected_docstring = ('Deprecated method docstring.\n'
66
98
' This might explain stuff.\n'
68
100
' This method was deprecated in version 0.7.\n'
175
207
'TestDeprecationWarnings.test_deprecation_string was deprecated in '
177
209
symbol_versioning.deprecation_string(
178
self.test_deprecation_string, symbol_versioning.zero_eleven))
210
self.test_deprecation_string,
211
deprecated_in((0, 11, 0))))
179
212
self.assertEqual('bzrlib.symbol_versioning.deprecated_function was '
180
213
'deprecated in version 0.11.',
181
214
symbol_versioning.deprecation_string(
182
215
symbol_versioning.deprecated_function,
183
symbol_versioning.zero_eleven))
216
deprecated_in((0, 11, 0))))
219
class TestSuppressAndActivate(TestCase):
223
existing_filters = list(warnings.filters)
225
warnings.filters[:] = existing_filters
226
self.addCleanup(restore)
227
# Clean out the filters so we have a clean slate.
228
warnings.resetwarnings()
230
def assertFirstWarning(self, action, category):
231
"""Test the first warning in the filters is correct"""
232
first = warnings.filters[0]
233
self.assertEqual((action, category), (first[0], first[2]))
235
def test_suppress_deprecation_warnings(self):
236
"""suppress_deprecation_warnings sets DeprecationWarning to ignored."""
237
symbol_versioning.suppress_deprecation_warnings()
238
self.assertFirstWarning('ignore', DeprecationWarning)
240
def test_suppress_deprecation_with_warning_filter(self):
241
"""don't suppress if we already have a filter"""
242
warnings.filterwarnings('error', category=Warning)
243
self.assertFirstWarning('error', Warning)
244
self.assertEqual(1, len(warnings.filters))
245
symbol_versioning.suppress_deprecation_warnings(override=False)
246
self.assertFirstWarning('error', Warning)
247
self.assertEqual(1, len(warnings.filters))
249
def test_suppress_deprecation_with_filter(self):
250
"""don't suppress if we already have a filter"""
251
warnings.filterwarnings('error', category=DeprecationWarning)
252
self.assertFirstWarning('error', DeprecationWarning)
253
self.assertEqual(1, len(warnings.filters))
254
symbol_versioning.suppress_deprecation_warnings(override=False)
255
self.assertFirstWarning('error', DeprecationWarning)
256
self.assertEqual(1, len(warnings.filters))
257
symbol_versioning.suppress_deprecation_warnings(override=True)
258
self.assertFirstWarning('ignore', DeprecationWarning)
259
self.assertEqual(2, len(warnings.filters))
261
def test_activate_deprecation_no_error(self):
262
# First nuke the filters, so we know it is clean
263
symbol_versioning.activate_deprecation_warnings()
264
self.assertFirstWarning('default', DeprecationWarning)
266
def test_activate_deprecation_with_error(self):
267
# First nuke the filters, so we know it is clean
268
# Add a warning == error rule
269
warnings.filterwarnings('error', category=Warning)
270
self.assertFirstWarning('error', Warning)
271
self.assertEqual(1, len(warnings.filters))
272
symbol_versioning.activate_deprecation_warnings(override=False)
273
# There should not be a new warning
274
self.assertFirstWarning('error', Warning)
275
self.assertEqual(1, len(warnings.filters))
277
def test_activate_deprecation_with_DW_error(self):
278
# First nuke the filters, so we know it is clean
279
# Add a warning == error rule
280
warnings.filterwarnings('error', category=DeprecationWarning)
281
self.assertFirstWarning('error', DeprecationWarning)
282
self.assertEqual(1, len(warnings.filters))
283
symbol_versioning.activate_deprecation_warnings(override=False)
284
# There should not be a new warning
285
self.assertFirstWarning('error', DeprecationWarning)
286
self.assertEqual(1, len(warnings.filters))
287
symbol_versioning.activate_deprecation_warnings(override=True)
288
self.assertFirstWarning('default', DeprecationWarning)
289
self.assertEqual(2, len(warnings.filters))