1
# Copyright (C) 2006 by Canonical Ltd
2
# Authors: Robert Collins <robert.collins@canonical.com>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
"""Symbol versioning tests."""
20
import bzrlib.symbol_versioning as symbol_versioning
21
from bzrlib.tests import TestCase
24
@symbol_versioning.deprecated_function(symbol_versioning.zero_seven)
25
def deprecated_function():
26
"""Deprecated function docstring."""
30
class TestDeprecationWarnings(TestCase):
32
def capture_warning(self, message, category, stacklevel=None):
33
self._warnings.append((message, category, stacklevel))
36
super(TestDeprecationWarnings, self).setUp()
39
@symbol_versioning.deprecated_method(symbol_versioning.zero_seven)
40
def deprecated_method(self):
41
"""Deprecated method docstring.
43
This might explain stuff.
47
def test_deprecated_method(self):
49
"bzrlib.tests.test_symbol_versioning."
50
"TestDeprecationWarnings.deprecated_method "
51
"was deprecated in version 0.7.", DeprecationWarning, 2)
52
expected_docstring = ('Deprecated method docstring.\n'
54
' This might explain stuff.\n'
56
' This method was deprecated in version 0.7.\n'
58
self.check_deprecated_callable(expected_warning, expected_docstring,
60
"bzrlib.tests.test_symbol_versioning",
61
self.deprecated_method)
63
def test_deprecated_function(self):
65
"bzrlib.tests.test_symbol_versioning.deprecated_function "
66
"was deprecated in version 0.7.", DeprecationWarning, 2)
67
expected_docstring = ('Deprecated function docstring.\n'
69
'This function was deprecated in version 0.7.\n'
71
self.check_deprecated_callable(expected_warning, expected_docstring,
72
"deprecated_function",
73
"bzrlib.tests.test_symbol_versioning",
76
def check_deprecated_callable(self, expected_warning, expected_docstring,
77
expected_name, expected_module,
79
old_warning_method = symbol_versioning.warn
81
symbol_versioning.set_warning_method(self.capture_warning)
82
self.assertEqual(1, deprecated_callable())
83
self.assertEqual([expected_warning], self._warnings)
85
self.assertEqual([expected_warning, expected_warning],
87
self.assertEqualDiff(expected_docstring, deprecated_callable.__doc__)
88
self.assertEqualDiff(expected_name, deprecated_callable.__name__)
89
self.assertEqualDiff(expected_module, deprecated_callable.__module__)
90
self.assertTrue(deprecated_callable.is_deprecated)
92
symbol_versioning.set_warning_method(old_warning_method)
94
def test_deprecated_passed(self):
95
self.assertEqual(True, symbol_versioning.deprecated_passed(None))
96
self.assertEqual(True, symbol_versioning.deprecated_passed(True))
97
self.assertEqual(True, symbol_versioning.deprecated_passed(False))
98
self.assertEqual(False,
99
symbol_versioning.deprecated_passed(
100
symbol_versioning.DEPRECATED_PARAMETER))