/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 breezy/tests/test_symbol_versioning.py

  • Committer: Martin
  • Date: 2018-11-16 16:38:22 UTC
  • mto: This revision was merged to the branch mainline in revision 7172.
  • Revision ID: gzlist@googlemail.com-20181116163822-yg1h1cdng6w7w9kn
Make --profile-imports work on Python 3

Also tweak heading to line up correctly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
18
18
 
19
19
import warnings
20
20
 
21
 
from bzrlib import symbol_versioning
22
 
from bzrlib.symbol_versioning import (
 
21
from breezy import symbol_versioning
 
22
from breezy.sixish import PY3
 
23
from breezy.symbol_versioning import (
23
24
    deprecated_function,
24
25
    deprecated_in,
25
 
    deprecated_list,
26
26
    deprecated_method,
27
27
    )
28
 
from bzrlib.tests import TestCase
 
28
from breezy.tests import TestCase
29
29
 
30
30
 
31
31
@deprecated_function(deprecated_in((0, 7, 0)))
70
70
        return 1
71
71
 
72
72
    def test_deprecated_static(self):
73
 
        # XXX: The results are not quite right because the class name is not
74
 
        # shown - however it is enough to give people a good indication of
75
 
        # where the problem is.
76
 
        expected_warning = (
77
 
            "bzrlib.tests.test_symbol_versioning."
78
 
            "deprecated_static "
79
 
            "was deprecated in version 0.7.0.", DeprecationWarning, 2)
 
73
        if PY3:
 
74
            expected_warning = (
 
75
                "breezy.tests.test_symbol_versioning.TestDeprecationWarnings."
 
76
                "deprecated_static "
 
77
                "was deprecated in version 0.7.0.", DeprecationWarning, 2)
 
78
        else:
 
79
            # XXX: The results are not quite right because the class name is not
 
80
            # shown on Python 2- however it is enough to give people a good indication of
 
81
            # where the problem is.
 
82
            expected_warning = (
 
83
                "breezy.tests.test_symbol_versioning."
 
84
                "deprecated_static "
 
85
                "was deprecated in version 0.7.0.", DeprecationWarning, 2)
80
86
        expected_docstring = (
81
87
            'Deprecated static.\n'
82
88
            '\n'
85
91
        self.check_deprecated_callable(
86
92
            expected_warning, expected_docstring,
87
93
            "deprecated_static",
88
 
            "bzrlib.tests.test_symbol_versioning",
 
94
            "breezy.tests.test_symbol_versioning",
89
95
            self.deprecated_static)
90
96
 
91
97
    def test_deprecated_method(self):
92
98
        expected_warning = (
93
 
            "bzrlib.tests.test_symbol_versioning."
 
99
            "breezy.tests.test_symbol_versioning."
94
100
            "TestDeprecationWarnings.deprecated_method "
95
101
            "was deprecated in version 0.7.0.", DeprecationWarning, 2)
96
102
        expected_docstring = (
102
108
            '        ')
103
109
        self.check_deprecated_callable(expected_warning, expected_docstring,
104
110
                                       "deprecated_method",
105
 
                                       "bzrlib.tests.test_symbol_versioning",
 
111
                                       "breezy.tests.test_symbol_versioning",
106
112
                                       self.deprecated_method)
107
113
 
108
114
    def test_deprecated_function(self):
109
115
        expected_warning = (
110
 
            "bzrlib.tests.test_symbol_versioning.sample_deprecated_function "
 
116
            "breezy.tests.test_symbol_versioning.sample_deprecated_function "
111
117
            "was deprecated in version 0.7.0.", DeprecationWarning, 2)
112
118
        expected_docstring = ('Deprecated function docstring.\n'
113
119
                              '\n'
115
121
                              )
116
122
        self.check_deprecated_callable(expected_warning, expected_docstring,
117
123
                                       "sample_deprecated_function",
118
 
                                       "bzrlib.tests.test_symbol_versioning",
 
124
                                       "breezy.tests.test_symbol_versioning",
119
125
                                       sample_deprecated_function)
120
126
 
121
127
    def test_deprecated_list(self):
207
213
 
208
214
    def test_deprecation_string(self):
209
215
        """We can get a deprecation string for a method or function."""
210
 
        self.assertEqual('bzrlib.tests.test_symbol_versioning.'
211
 
            'TestDeprecationWarnings.test_deprecation_string was deprecated in '
212
 
            'version 0.11.0.',
213
 
            symbol_versioning.deprecation_string(
 
216
        err_message = symbol_versioning.deprecation_string(
214
217
            self.test_deprecation_string,
215
 
            deprecated_in((0, 11, 0))))
216
 
        self.assertEqual('bzrlib.symbol_versioning.deprecated_function was '
 
218
            deprecated_in((0, 11, 0)))
 
219
        self.assertEqual(err_message,
 
220
                 'breezy.tests.test_symbol_versioning.TestDeprecationWarnings.'
 
221
                 'test_deprecation_string was deprecated in '
 
222
                 'version 0.11.0.')
 
223
 
 
224
        self.assertEqual('breezy.symbol_versioning.deprecated_function was '
217
225
            'deprecated in version 0.11.0.',
218
226
            symbol_versioning.deprecation_string(
219
227
                symbol_versioning.deprecated_function,
223
231
class TestSuppressAndActivate(TestCase):
224
232
 
225
233
    def setUp(self):
226
 
        TestCase.setUp(self)
 
234
        super(TestSuppressAndActivate, self).setUp()
227
235
        existing_filters = list(warnings.filters)
228
236
        def restore():
229
237
            warnings.filters[:] = existing_filters
241
249
        symbol_versioning.suppress_deprecation_warnings()
242
250
        self.assertFirstWarning('ignore', DeprecationWarning)
243
251
 
 
252
    def test_set_restore_filters(self):
 
253
        original_filters = warnings.filters[:]
 
254
        symbol_versioning.suppress_deprecation_warnings()()
 
255
        self.assertEqual(original_filters, warnings.filters)
 
256
 
244
257
    def test_suppress_deprecation_with_warning_filter(self):
245
258
        """don't suppress if we already have a filter"""
246
259
        warnings.filterwarnings('error', category=Warning)