~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: 2006-06-26 02:01:54 UTC
  • mfrom: (1756.2.29 log.perf)
  • Revision ID: pqm@pqm.ubuntu.com-20060626020154-5f3661f6a543d34d
Remove basis knit support

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
3
#
4
4
# This program is free software; you can redistribute it and/or modify
27
27
    return 1
28
28
 
29
29
 
30
 
a_deprecated_list = symbol_versioning.deprecated_list(symbol_versioning.zero_nine,
31
 
    'a_deprecated_list', ['one'], extra="Don't use me")
32
 
 
33
 
 
34
 
a_deprecated_dict = symbol_versioning.DeprecatedDict(
35
 
    symbol_versioning.zero_fourteen,
36
 
    'a_deprecated_dict',
37
 
    dict(a=42),
38
 
    advice='Pull the other one!',
39
 
    )
40
 
 
41
 
 
42
30
class TestDeprecationWarnings(TestCase):
43
31
 
44
32
    def capture_warning(self, message, category, stacklevel=None):
85
73
                                       "bzrlib.tests.test_symbol_versioning",
86
74
                                       deprecated_function)
87
75
 
88
 
    def test_deprecated_list(self):
89
 
        expected_warning = (
90
 
            "Modifying a_deprecated_list was deprecated in version 0.9."
91
 
            " Don't use me", DeprecationWarning, 3)
92
 
        old_warning_method = symbol_versioning.warn
93
 
        try:
94
 
            symbol_versioning.set_warning_method(self.capture_warning)
95
 
            self.assertEqual(['one'], a_deprecated_list)
96
 
            self.assertEqual([], self._warnings)
97
 
 
98
 
            a_deprecated_list.append('foo')
99
 
            self.assertEqual([expected_warning], self._warnings)
100
 
            self.assertEqual(['one', 'foo'], a_deprecated_list)
101
 
 
102
 
            a_deprecated_list.extend(['bar', 'baz'])
103
 
            self.assertEqual([expected_warning]*2, self._warnings)
104
 
            self.assertEqual(['one', 'foo', 'bar', 'baz'], a_deprecated_list)
105
 
 
106
 
            a_deprecated_list.insert(1, 'xxx')
107
 
            self.assertEqual([expected_warning]*3, self._warnings)
108
 
            self.assertEqual(['one', 'xxx', 'foo', 'bar', 'baz'], a_deprecated_list)
109
 
 
110
 
            a_deprecated_list.remove('foo')
111
 
            self.assertEqual([expected_warning]*4, self._warnings)
112
 
            self.assertEqual(['one', 'xxx', 'bar', 'baz'], a_deprecated_list)
113
 
 
114
 
            val = a_deprecated_list.pop()
115
 
            self.assertEqual([expected_warning]*5, self._warnings)
116
 
            self.assertEqual('baz', val)
117
 
            self.assertEqual(['one', 'xxx', 'bar'], a_deprecated_list)
118
 
 
119
 
            val = a_deprecated_list.pop(1)
120
 
            self.assertEqual([expected_warning]*6, self._warnings)
121
 
            self.assertEqual('xxx', val)
122
 
            self.assertEqual(['one', 'bar'], a_deprecated_list)
123
 
        finally:
124
 
            symbol_versioning.set_warning_method(old_warning_method)
125
 
 
126
 
    def test_deprecated_dict(self):
127
 
        expected_warning = (
128
 
            "access to a_deprecated_dict was deprecated in version 0.14."
129
 
            " Pull the other one!", DeprecationWarning, 2)
130
 
        old_warning_method = symbol_versioning.warn
131
 
        try:
132
 
            symbol_versioning.set_warning_method(self.capture_warning)
133
 
            self.assertEqual(len(a_deprecated_dict), 1)
134
 
            self.assertEqual([expected_warning], self._warnings)
135
 
 
136
 
            a_deprecated_dict['b'] = 42
137
 
            self.assertEqual(a_deprecated_dict['b'], 42)
138
 
            self.assertTrue('b' in a_deprecated_dict)
139
 
            del a_deprecated_dict['b']
140
 
            self.assertFalse('b' in a_deprecated_dict)
141
 
            self.assertEqual([expected_warning] * 6, self._warnings)
142
 
        finally:
143
 
            symbol_versioning.set_warning_method(old_warning_method)
144
 
 
145
 
 
146
76
    def check_deprecated_callable(self, expected_warning, expected_docstring,
147
77
                                  expected_name, expected_module,
148
78
                                  deprecated_callable):
168
98
        self.assertEqual(False,
169
99
                         symbol_versioning.deprecated_passed(
170
100
                            symbol_versioning.DEPRECATED_PARAMETER))
171
 
 
172
 
    def test_deprecation_string(self):
173
 
        """We can get a deprecation string for a method or function."""
174
 
        self.assertEqual('bzrlib.tests.test_symbol_versioning.'
175
 
            'TestDeprecationWarnings.test_deprecation_string was deprecated in '
176
 
            'version 0.11.',
177
 
            symbol_versioning.deprecation_string(
178
 
            self.test_deprecation_string, symbol_versioning.zero_eleven))
179
 
        self.assertEqual('bzrlib.symbol_versioning.deprecated_function was '
180
 
            'deprecated in version 0.11.',
181
 
            symbol_versioning.deprecation_string(
182
 
                symbol_versioning.deprecated_function,
183
 
                symbol_versioning.zero_eleven))