/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 bzrlib/tests/test_errors.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-11-03 02:35:48 UTC
  • mfrom: (2067.3.7 cleanup-errors)
  • Revision ID: pqm@pqm.ubuntu.com-20061103023548-12e702bb911c4be2
(mbp) deprecate BzrNewError, change to using .internal_error on exceptions, etc

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
from bzrlib.tests import TestCase, TestCaseWithTransport
25
25
 
26
26
 
 
27
# TODO: Make sure builtin exception class formats are consistent - e.g. should
 
28
# or shouldn't end with a full stop, etc.
 
29
 
 
30
 
27
31
class TestErrors(TestCaseWithTransport):
28
32
 
29
33
    def test_inventory_modified(self):
84
88
                             repo.bzrdir.root_transport.base,
85
89
                             str(error))
86
90
 
 
91
    def test_bzrnewerror_is_deprecated(self):
 
92
        class DeprecatedError(errors.BzrNewError):
 
93
            pass
 
94
        self.callDeprecated(['BzrNewError was deprecated in bzr 0.13; '
 
95
             'please convert DeprecatedError to use BzrError instead'],
 
96
            DeprecatedError)
 
97
 
 
98
    def test_bzrerror_from_literal_string(self):
 
99
        # Some code constructs BzrError from a literal string, in which case
 
100
        # no further formatting is done.  (I'm not sure raising the base class
 
101
        # is a great idea, but if the exception is not intended to be caught
 
102
        # perhaps no more is needed.)
 
103
        try:
 
104
            raise errors.BzrError('this is my errors; %d is not expanded')
 
105
        except errors.BzrError, e:
 
106
            self.assertEqual('this is my errors; %d is not expanded', str(e))
 
107
 
87
108
    def test_reading_completed(self):
88
109
        error = errors.ReadingCompleted("a request")
89
110
        self.assertEqualDiff("The MediumRequest 'a request' has already had "
106
127
            str(error))
107
128
 
108
129
 
109
 
class PassThroughError(errors.BzrNewError):
110
 
    """Pass through %(foo)s and %(bar)s"""
 
130
class PassThroughError(errors.BzrError):
 
131
    
 
132
    _fmt = """Pass through %(foo)s and %(bar)s"""
111
133
 
112
134
    def __init__(self, foo, bar):
113
 
        errors.BzrNewError.__init__(self, foo=foo, bar=bar)
114
 
 
115
 
 
116
 
class ErrorWithBadFormat(errors.BzrNewError):
117
 
    """One format specifier: %(thing)s"""
 
135
        errors.BzrError.__init__(self, foo=foo, bar=bar)
 
136
 
 
137
 
 
138
class ErrorWithBadFormat(errors.BzrError):
 
139
 
 
140
    _fmt = """One format specifier: %(thing)s"""
 
141
 
 
142
 
 
143
class ErrorWithNoFormat(errors.BzrError):
 
144
    """This class has a docstring but no format string."""
118
145
 
119
146
 
120
147
class TestErrorFormatting(TestCase):
129
156
        s = str(e)
130
157
        self.assertEqual('Pass through \xc2\xb5 and bar', s)
131
158
 
 
159
    def test_missing_format_string(self):
 
160
        e = ErrorWithNoFormat(param='randomvalue')
 
161
        s = self.callDeprecated(
 
162
                ['ErrorWithNoFormat uses its docstring as a format, it should use _fmt instead'],
 
163
                lambda x: str(x), e)
 
164
        ## s = str(e)
 
165
        self.assertEqual(s, 
 
166
                "This class has a docstring but no format string.")
 
167
 
132
168
    def test_mismatched_format_args(self):
133
169
        # Even though ErrorWithBadFormat's format string does not match the
134
170
        # arguments we constructing it with, we can still stringify an instance
135
171
        # of this exception. The resulting string will say its unprintable.
136
172
        e = ErrorWithBadFormat(not_thing='x')
137
173
        self.assertStartsWith(
138
 
            str(e), 'Unprintable exception ErrorWithBadFormat(')
 
174
            str(e), 'Unprintable exception ErrorWithBadFormat')
139
175
 
140
176
 
141
177
class TestSpecificErrors(TestCase):