/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1534.2.1 by Robert Collins
Implement deprecated_method
1
# Copyright (C) 2006 by Canonical Ltd
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
#
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.
8
#
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.
13
#
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
17
18
"""Symbol versioning tests."""
19
20
import bzrlib.symbol_versioning as symbol_versioning
21
from bzrlib.tests import TestCase
22
23
1534.2.2 by Robert Collins
Implement deprecated_function.
24
@symbol_versioning.deprecated_function(symbol_versioning.zero_seven)
25
def deprecated_function():
1534.2.3 by Robert Collins
decorate docstrings in deprecated functions.
26
    """Deprecated function docstring."""
1534.2.2 by Robert Collins
Implement deprecated_function.
27
    return 1
28
1534.2.1 by Robert Collins
Implement deprecated_method
29
30
class TestDeprecationWarnings(TestCase):
31
32
    def capture_warning(self, message, category):
33
        self._warnings.append((message, category))
34
35
    def setUp(self):
36
        super(TestDeprecationWarnings, self).setUp()
37
        self._warnings = []
38
    
39
    @symbol_versioning.deprecated_method(symbol_versioning.zero_seven)
40
    def deprecated_method(self):
1534.2.3 by Robert Collins
decorate docstrings in deprecated functions.
41
        """Deprecated method docstring.
42
        
43
        This might explain stuff.
44
        """
1534.2.2 by Robert Collins
Implement deprecated_function.
45
        return 1
1534.2.1 by Robert Collins
Implement deprecated_method
46
47
    def test_deprecated_method(self):
1534.2.2 by Robert Collins
Implement deprecated_function.
48
        expected_warning = (
49
            "bzrlib.tests.test_symbol_versioning."
50
            "TestDeprecationWarnings.deprecated_method "
1534.2.3 by Robert Collins
decorate docstrings in deprecated functions.
51
            "was deprecated in version 0.7.", DeprecationWarning)
52
        expected_docstring = ('Deprecated method docstring.\n'
53
                              '        \n'
54
                              '        This might explain stuff.\n'
55
                              '        \n'
56
                              '        This method was deprecated in version 0.7.\n'
57
                              '        ')
58
        self.check_deprecated_callable(expected_warning, expected_docstring,
1534.2.5 by Robert Collins
Set the __name__ attribute on decorated methods and functions.
59
                                       "deprecated_method",
1534.1.3 by Robert Collins
Bugfix the symbol_versioning deprecation decorators to update the
60
                                       "bzrlib.tests.test_symbol_versioning",
1534.2.2 by Robert Collins
Implement deprecated_function.
61
                                       self.deprecated_method)
62
63
    def test_deprecated_function(self):
64
        expected_warning = (
65
            "bzrlib.tests.test_symbol_versioning.deprecated_function "
1534.2.3 by Robert Collins
decorate docstrings in deprecated functions.
66
            "was deprecated in version 0.7.", DeprecationWarning)
67
        expected_docstring = ('Deprecated function docstring.\n'
68
                              '\n'
69
                              'This function was deprecated in version 0.7.\n'
70
                              )
71
        self.check_deprecated_callable(expected_warning, expected_docstring,
1534.2.5 by Robert Collins
Set the __name__ attribute on decorated methods and functions.
72
                                       "deprecated_function",
1534.1.3 by Robert Collins
Bugfix the symbol_versioning deprecation decorators to update the
73
                                       "bzrlib.tests.test_symbol_versioning",
1534.2.2 by Robert Collins
Implement deprecated_function.
74
                                       deprecated_function)
75
1534.2.3 by Robert Collins
decorate docstrings in deprecated functions.
76
    def check_deprecated_callable(self, expected_warning, expected_docstring,
1534.1.3 by Robert Collins
Bugfix the symbol_versioning deprecation decorators to update the
77
                                  expected_name, expected_module,
1534.2.3 by Robert Collins
decorate docstrings in deprecated functions.
78
                                  deprecated_callable):
1534.2.1 by Robert Collins
Implement deprecated_method
79
        old_warning_method = symbol_versioning.warn
80
        try:
81
            symbol_versioning.set_warning_method(self.capture_warning)
1534.2.2 by Robert Collins
Implement deprecated_function.
82
            self.assertEqual(1, deprecated_callable())
1534.2.1 by Robert Collins
Implement deprecated_method
83
            self.assertEqual([expected_warning], self._warnings)
1534.2.2 by Robert Collins
Implement deprecated_function.
84
            deprecated_callable()
1534.2.1 by Robert Collins
Implement deprecated_method
85
            self.assertEqual([expected_warning, expected_warning],
86
                             self._warnings)
1534.2.3 by Robert Collins
decorate docstrings in deprecated functions.
87
            self.assertEqualDiff(expected_docstring, deprecated_callable.__doc__)
1534.2.5 by Robert Collins
Set the __name__ attribute on decorated methods and functions.
88
            self.assertEqualDiff(expected_name, deprecated_callable.__name__)
1534.1.3 by Robert Collins
Bugfix the symbol_versioning deprecation decorators to update the
89
            self.assertEqualDiff(expected_module, deprecated_callable.__module__)
1534.2.1 by Robert Collins
Implement deprecated_method
90
        finally:
91
            symbol_versioning.set_warning_method(old_warning_method)