~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_symbol_versioning.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-06 20:42:40 UTC
  • mto: This revision was merged to the branch mainline in revision 4088.
  • Revision ID: john@arbash-meinel.com-20090306204240-mzjavv31z3gu1x7i
Fix a small bug in setup.py when an extension fails to build

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
 
2
#   Authors: Robert Collins <robert.collins@canonical.com>
 
3
#   and others
2
4
#
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
12
14
#
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
16
18
 
17
19
"""Symbol versioning tests."""
18
20
 
19
21
import warnings
20
22
 
21
23
from bzrlib import symbol_versioning
22
 
from bzrlib.symbol_versioning import (
23
 
    deprecated_function,
24
 
    deprecated_in,
25
 
    deprecated_list,
26
 
    deprecated_method,
27
 
    )
28
24
from bzrlib.tests import TestCase
29
25
 
30
26
 
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."""
34
30
    return 1
35
31
 
36
32
 
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")
39
35
 
40
36
 
41
37
a_deprecated_dict = symbol_versioning.DeprecatedDict(
42
 
    deprecated_in((0, 14, 0)),
 
38
    symbol_versioning.zero_fourteen,
43
39
    'a_deprecated_dict',
44
40
    dict(a=42),
45
41
    advice='Pull the other one!',
54
50
    def setUp(self):
55
51
        super(TestDeprecationWarnings, self).setUp()
56
52
        self._warnings = []
57
 
    
58
 
    @deprecated_method(deprecated_in((0, 7, 0)))
 
53
 
 
54
    @symbol_versioning.deprecated_method(symbol_versioning.zero_seven)
59
55
    def deprecated_method(self):
60
56
        """Deprecated method docstring.
61
57
 
64
60
        return 1
65
61
 
66
62
    @staticmethod
67
 
    @deprecated_function(deprecated_in((0, 7, 0)))
 
63
    @symbol_versioning.deprecated_function(symbol_versioning.zero_seven)
68
64
    def deprecated_static():
69
65
        """Deprecated static."""
70
66
        return 1
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'
82
78
            '\n'
83
 
            'This function was deprecated in version 0.7.0.\n'
 
79
            'This function was deprecated in version 0.7.\n'
84
80
            )
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'
98
 
            '\n'
99
 
            '        This might explain stuff.\n'
100
 
            '        \n'
101
 
            '        This method was deprecated in version 0.7.0.\n'
102
 
            '        ')
 
91
            "was deprecated in version 0.7.", DeprecationWarning, 2)
 
92
        expected_docstring = ('Deprecated method docstring.\n'
 
93
                              '\n'
 
94
                              '        This might explain stuff.\n'
 
95
                              '        \n'
 
96
                              '        This method was deprecated in version 0.7.\n'
 
97
                              '        ')
103
98
        self.check_deprecated_callable(expected_warning, expected_docstring,
104
99
                                       "deprecated_method",
105
100
                                       "bzrlib.tests.test_symbol_versioning",
107
102
 
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'
113
108
                              '\n'
114
 
                              'This function was deprecated in version 0.7.0.\n'
 
109
                              'This function was deprecated in version 0.7.\n'
115
110
                              )
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)
 
114
                                       deprecated_function)
120
115
 
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
126
121
        try:
158
153
 
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
164
159
        try:
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 '
209
 
            'version 0.11.0.',
 
204
            'version 0.11.',
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))
218
212
 
219
213
 
220
214
class TestSuppressAndActivate(TestCase):
221
215
 
222
216
    def setUp(self):
223
 
        TestCase.setUp(self)
224
217
        existing_filters = list(warnings.filters)
225
218
        def restore():
226
219
            warnings.filters[:] = existing_filters