/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_symbol_versioning.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-09 21:42:24 UTC
  • mto: This revision was merged to the branch mainline in revision 3543.
  • Revision ID: john@arbash-meinel.com-20080709214224-r75k87r6a01pfc3h
Restore a real weave merge to 'bzr merge --weave'.

To do so efficiently, we only add the simple LCAs to the final weave
object, unless we run into complexities with the merge graph.
This gives the same effective result as adding all the texts,
with the advantage of not having to extract all of them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 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!',
55
51
        super(TestDeprecationWarnings, self).setUp()
56
52
        self._warnings = []
57
53
    
58
 
    @deprecated_method(deprecated_in((0, 7, 0)))
 
54
    @symbol_versioning.deprecated_method(symbol_versioning.zero_seven)
59
55
    def deprecated_method(self):
60
56
        """Deprecated method docstring.
61
 
 
 
57
        
62
58
        This might explain stuff.
63
59
        """
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:
179
174
    def check_deprecated_callable(self, expected_warning, expected_docstring,
180
175
                                  expected_name, expected_module,
181
176
                                  deprecated_callable):
182
 
        if __doc__ is None:
183
 
            # With -OO the docstring should just be the deprecated version
184
 
            expected_docstring = expected_docstring.split('\n')[-2].lstrip()
185
177
        old_warning_method = symbol_versioning.warn
186
178
        try:
187
179
            symbol_versioning.set_warning_method(self.capture_warning)
196
188
            self.assertTrue(deprecated_callable.is_deprecated)
197
189
        finally:
198
190
            symbol_versioning.set_warning_method(old_warning_method)
199
 
 
 
191
    
200
192
    def test_deprecated_passed(self):
201
193
        self.assertEqual(True, symbol_versioning.deprecated_passed(None))
202
194
        self.assertEqual(True, symbol_versioning.deprecated_passed(True))
209
201
        """We can get a deprecation string for a method or function."""
210
202
        self.assertEqual('bzrlib.tests.test_symbol_versioning.'
211
203
            'TestDeprecationWarnings.test_deprecation_string was deprecated in '
212
 
            'version 0.11.0.',
 
204
            'version 0.11.',
213
205
            symbol_versioning.deprecation_string(
214
 
            self.test_deprecation_string,
215
 
            deprecated_in((0, 11, 0))))
 
206
            self.test_deprecation_string, symbol_versioning.zero_eleven))
216
207
        self.assertEqual('bzrlib.symbol_versioning.deprecated_function was '
217
 
            'deprecated in version 0.11.0.',
 
208
            'deprecated in version 0.11.',
218
209
            symbol_versioning.deprecation_string(
219
210
                symbol_versioning.deprecated_function,
220
 
                deprecated_in((0, 11, 0))))
 
211
                symbol_versioning.zero_eleven))
221
212
 
222
213
 
223
214
class TestSuppressAndActivate(TestCase):
224
215
 
225
216
    def setUp(self):
226
 
        TestCase.setUp(self)
227
217
        existing_filters = list(warnings.filters)
228
218
        def restore():
229
219
            warnings.filters[:] = existing_filters