~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_symbol_versioning.py

  • Committer: Alexander Belchenko
  • Date: 2006-10-14 08:51:07 UTC
  • mto: (2080.1.1 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 2081.
  • Revision ID: bialix@ukr.net-20061014085107-8dff865674eed30a
win32 installer: make short info page instead of full GPL license text

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2006 by Canonical Ltd
2
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
 
#   and others
4
3
#
5
4
# This program is free software; you can redistribute it and/or modify
6
5
# it under the terms of the GNU General Public License as published by
32
31
    'a_deprecated_list', ['one'], extra="Don't use me")
33
32
 
34
33
 
35
 
a_deprecated_dict = symbol_versioning.DeprecatedDict(
36
 
    symbol_versioning.zero_fourteen,
37
 
    'a_deprecated_dict',
38
 
    dict(a=42),
39
 
    advice='Pull the other one!',
40
 
    )
41
 
 
42
 
 
43
34
class TestDeprecationWarnings(TestCase):
44
35
 
45
36
    def capture_warning(self, message, category, stacklevel=None):
57
48
        """
58
49
        return 1
59
50
 
60
 
    @staticmethod
61
 
    @symbol_versioning.deprecated_function(symbol_versioning.zero_seven)
62
 
    def deprecated_static():
63
 
        """Deprecated static."""
64
 
        return 1
65
 
 
66
 
    def test_deprecated_static(self):
67
 
        # XXX: The results are not quite right because the class name is not
68
 
        # shown - however it is enough to give people a good indication of
69
 
        # where the problem is.
70
 
        expected_warning = (
71
 
            "bzrlib.tests.test_symbol_versioning."
72
 
            "deprecated_static "
73
 
            "was deprecated in version 0.7.", DeprecationWarning, 2)
74
 
        expected_docstring = (
75
 
            'Deprecated static.\n'
76
 
            '\n'
77
 
            'This function was deprecated in version 0.7.\n'
78
 
            )
79
 
        self.check_deprecated_callable(
80
 
            expected_warning, expected_docstring,
81
 
            "deprecated_static",
82
 
            "bzrlib.tests.test_symbol_versioning",
83
 
            self.deprecated_static)
84
 
 
85
51
    def test_deprecated_method(self):
86
52
        expected_warning = (
87
53
            "bzrlib.tests.test_symbol_versioning."
115
81
        expected_warning = (
116
82
            "Modifying a_deprecated_list was deprecated in version 0.9."
117
83
            " Don't use me", DeprecationWarning, 3)
 
84
        expected_doctstring = ('appending to a_deprecated_list is deprecated')
 
85
 
118
86
        old_warning_method = symbol_versioning.warn
119
87
        try:
120
88
            symbol_versioning.set_warning_method(self.capture_warning)
149
117
        finally:
150
118
            symbol_versioning.set_warning_method(old_warning_method)
151
119
 
152
 
    def test_deprecated_dict(self):
153
 
        expected_warning = (
154
 
            "access to a_deprecated_dict was deprecated in version 0.14."
155
 
            " Pull the other one!", DeprecationWarning, 2)
156
 
        old_warning_method = symbol_versioning.warn
157
 
        try:
158
 
            symbol_versioning.set_warning_method(self.capture_warning)
159
 
            self.assertEqual(len(a_deprecated_dict), 1)
160
 
            self.assertEqual([expected_warning], self._warnings)
161
 
 
162
 
            a_deprecated_dict['b'] = 42
163
 
            self.assertEqual(a_deprecated_dict['b'], 42)
164
 
            self.assertTrue('b' in a_deprecated_dict)
165
 
            del a_deprecated_dict['b']
166
 
            self.assertFalse('b' in a_deprecated_dict)
167
 
            self.assertEqual([expected_warning] * 6, self._warnings)
168
 
        finally:
169
 
            symbol_versioning.set_warning_method(old_warning_method)
170
 
 
171
 
 
172
120
    def check_deprecated_callable(self, expected_warning, expected_docstring,
173
121
                                  expected_name, expected_module,
174
122
                                  deprecated_callable):