~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_symbol_versioning.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 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
31
31
    'a_deprecated_list', ['one'], extra="Don't use me")
32
32
 
33
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
 
34
42
class TestDeprecationWarnings(TestCase):
35
43
 
36
44
    def capture_warning(self, message, category, stacklevel=None):
81
89
        expected_warning = (
82
90
            "Modifying a_deprecated_list was deprecated in version 0.9."
83
91
            " Don't use me", DeprecationWarning, 3)
84
 
        expected_doctstring = ('appending to a_deprecated_list is deprecated')
85
 
 
86
92
        old_warning_method = symbol_versioning.warn
87
93
        try:
88
94
            symbol_versioning.set_warning_method(self.capture_warning)
117
123
        finally:
118
124
            symbol_versioning.set_warning_method(old_warning_method)
119
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
 
120
146
    def check_deprecated_callable(self, expected_warning, expected_docstring,
121
147
                                  expected_name, expected_module,
122
148
                                  deprecated_callable):