~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_symbol_versioning.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
76
76
        expected_warning = (
77
77
            "bzrlib.tests.test_symbol_versioning."
78
78
            "deprecated_static "
79
 
            "was deprecated in version 0.7.", DeprecationWarning, 2)
 
79
            "was deprecated in version 0.7.0.", DeprecationWarning, 2)
80
80
        expected_docstring = (
81
81
            'Deprecated static.\n'
82
82
            '\n'
83
 
            'This function was deprecated in version 0.7.\n'
 
83
            'This function was deprecated in version 0.7.0.\n'
84
84
            )
85
85
        self.check_deprecated_callable(
86
86
            expected_warning, expected_docstring,
92
92
        expected_warning = (
93
93
            "bzrlib.tests.test_symbol_versioning."
94
94
            "TestDeprecationWarnings.deprecated_method "
95
 
            "was deprecated in version 0.7.", DeprecationWarning, 2)
96
 
        expected_docstring = ('Deprecated method docstring.\n'
97
 
                              '\n'
98
 
                              '        This might explain stuff.\n'
99
 
                              '        \n'
100
 
                              '        This method was deprecated in version 0.7.\n'
101
 
                              '        ')
 
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
            '        ')
102
103
        self.check_deprecated_callable(expected_warning, expected_docstring,
103
104
                                       "deprecated_method",
104
105
                                       "bzrlib.tests.test_symbol_versioning",
107
108
    def test_deprecated_function(self):
108
109
        expected_warning = (
109
110
            "bzrlib.tests.test_symbol_versioning.sample_deprecated_function "
110
 
            "was deprecated in version 0.7.", DeprecationWarning, 2)
 
111
            "was deprecated in version 0.7.0.", DeprecationWarning, 2)
111
112
        expected_docstring = ('Deprecated function docstring.\n'
112
113
                              '\n'
113
 
                              'This function was deprecated in version 0.7.\n'
 
114
                              'This function was deprecated in version 0.7.0.\n'
114
115
                              )
115
116
        self.check_deprecated_callable(expected_warning, expected_docstring,
116
117
                                       "sample_deprecated_function",
119
120
 
120
121
    def test_deprecated_list(self):
121
122
        expected_warning = (
122
 
            "Modifying a_deprecated_list was deprecated in version 0.9."
 
123
            "Modifying a_deprecated_list was deprecated in version 0.9.0."
123
124
            " Don't use me", DeprecationWarning, 3)
124
125
        old_warning_method = symbol_versioning.warn
125
126
        try:
157
158
 
158
159
    def test_deprecated_dict(self):
159
160
        expected_warning = (
160
 
            "access to a_deprecated_dict was deprecated in version 0.14."
 
161
            "access to a_deprecated_dict was deprecated in version 0.14.0."
161
162
            " Pull the other one!", DeprecationWarning, 2)
162
163
        old_warning_method = symbol_versioning.warn
163
164
        try:
178
179
    def check_deprecated_callable(self, expected_warning, expected_docstring,
179
180
                                  expected_name, expected_module,
180
181
                                  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()
181
185
        old_warning_method = symbol_versioning.warn
182
186
        try:
183
187
            symbol_versioning.set_warning_method(self.capture_warning)
205
209
        """We can get a deprecation string for a method or function."""
206
210
        self.assertEqual('bzrlib.tests.test_symbol_versioning.'
207
211
            'TestDeprecationWarnings.test_deprecation_string was deprecated in '
208
 
            'version 0.11.',
 
212
            'version 0.11.0.',
209
213
            symbol_versioning.deprecation_string(
210
214
            self.test_deprecation_string,
211
215
            deprecated_in((0, 11, 0))))
212
216
        self.assertEqual('bzrlib.symbol_versioning.deprecated_function was '
213
 
            'deprecated in version 0.11.',
 
217
            'deprecated in version 0.11.0.',
214
218
            symbol_versioning.deprecation_string(
215
219
                symbol_versioning.deprecated_function,
216
220
                deprecated_in((0, 11, 0))))
237
241
        symbol_versioning.suppress_deprecation_warnings()
238
242
        self.assertFirstWarning('ignore', DeprecationWarning)
239
243
 
 
244
    def test_set_restore_filters(self):
 
245
        original_filters = warnings.filters[:]
 
246
        symbol_versioning.suppress_deprecation_warnings()()
 
247
        self.assertEqual(original_filters, warnings.filters)
 
248
 
240
249
    def test_suppress_deprecation_with_warning_filter(self):
241
250
        """don't suppress if we already have a filter"""
242
251
        warnings.filterwarnings('error', category=Warning)