~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_symbol_versioning.py

  • Committer: Martin Pool
  • Date: 2005-09-06 02:26:28 UTC
  • Revision ID: mbp@sourcefrog.net-20050906022628-66d65f0feb4a9e80
- implement version 5 xml storage, and tests

  This stores files identified by the version that introduced the 
  text, and the version that introduced the name.  Entry kinds are
  given by the xml tag not an explicit kind field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
2
 
#   Authors: Robert Collins <robert.collins@canonical.com>
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 
 
18
 
"""Symbol versioning tests."""
19
 
 
20
 
import bzrlib.symbol_versioning as symbol_versioning
21
 
from bzrlib.tests import TestCase
22
 
 
23
 
 
24
 
@symbol_versioning.deprecated_function(symbol_versioning.zero_seven)
25
 
def deprecated_function():
26
 
    """Deprecated function docstring."""
27
 
    return 1
28
 
 
29
 
 
30
 
class TestDeprecationWarnings(TestCase):
31
 
 
32
 
    def capture_warning(self, message, category, stacklevel=None):
33
 
        self._warnings.append((message, category, stacklevel))
34
 
 
35
 
    def setUp(self):
36
 
        super(TestDeprecationWarnings, self).setUp()
37
 
        self._warnings = []
38
 
    
39
 
    @symbol_versioning.deprecated_method(symbol_versioning.zero_seven)
40
 
    def deprecated_method(self):
41
 
        """Deprecated method docstring.
42
 
        
43
 
        This might explain stuff.
44
 
        """
45
 
        return 1
46
 
 
47
 
    def test_deprecated_method(self):
48
 
        expected_warning = (
49
 
            "bzrlib.tests.test_symbol_versioning."
50
 
            "TestDeprecationWarnings.deprecated_method "
51
 
            "was deprecated in version 0.7.", DeprecationWarning, 2)
52
 
        expected_docstring = ('Deprecated method docstring.\n'
53
 
                              '        \n'
54
 
                              '        This might explain stuff.\n'
55
 
                              '        \n'
56
 
                              '        This method was deprecated in version 0.7.\n'
57
 
                              '        ')
58
 
        self.check_deprecated_callable(expected_warning, expected_docstring,
59
 
                                       "deprecated_method",
60
 
                                       "bzrlib.tests.test_symbol_versioning",
61
 
                                       self.deprecated_method)
62
 
 
63
 
    def test_deprecated_function(self):
64
 
        expected_warning = (
65
 
            "bzrlib.tests.test_symbol_versioning.deprecated_function "
66
 
            "was deprecated in version 0.7.", DeprecationWarning, 2)
67
 
        expected_docstring = ('Deprecated function docstring.\n'
68
 
                              '\n'
69
 
                              'This function was deprecated in version 0.7.\n'
70
 
                              )
71
 
        self.check_deprecated_callable(expected_warning, expected_docstring,
72
 
                                       "deprecated_function",
73
 
                                       "bzrlib.tests.test_symbol_versioning",
74
 
                                       deprecated_function)
75
 
 
76
 
    def check_deprecated_callable(self, expected_warning, expected_docstring,
77
 
                                  expected_name, expected_module,
78
 
                                  deprecated_callable):
79
 
        old_warning_method = symbol_versioning.warn
80
 
        try:
81
 
            symbol_versioning.set_warning_method(self.capture_warning)
82
 
            self.assertEqual(1, deprecated_callable())
83
 
            self.assertEqual([expected_warning], self._warnings)
84
 
            deprecated_callable()
85
 
            self.assertEqual([expected_warning, expected_warning],
86
 
                             self._warnings)
87
 
            self.assertEqualDiff(expected_docstring, deprecated_callable.__doc__)
88
 
            self.assertEqualDiff(expected_name, deprecated_callable.__name__)
89
 
            self.assertEqualDiff(expected_module, deprecated_callable.__module__)
90
 
            self.assertTrue(deprecated_callable.is_deprecated)
91
 
        finally:
92
 
            symbol_versioning.set_warning_method(old_warning_method)
93
 
    
94
 
    def test_deprecated_passed(self):
95
 
        self.assertEqual(True, symbol_versioning.deprecated_passed(None))
96
 
        self.assertEqual(True, symbol_versioning.deprecated_passed(True))
97
 
        self.assertEqual(True, symbol_versioning.deprecated_passed(False))
98
 
        self.assertEqual(False,
99
 
                         symbol_versioning.deprecated_passed(
100
 
                            symbol_versioning.DEPRECATED_PARAMETER))