/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: John Arbash Meinel
  • Date: 2006-11-10 22:23:15 UTC
  • mfrom: (2129 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2131.
  • Revision ID: john@arbash-meinel.com-20061110222315-07f2336970e50698
[merge] bzr.dev 2129

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):
93
97
                             repo.bzrdir.root_transport.base,
94
98
                             str(error))
95
99
 
 
100
    def test_bzrnewerror_is_deprecated(self):
 
101
        class DeprecatedError(errors.BzrNewError):
 
102
            pass
 
103
        self.callDeprecated(['BzrNewError was deprecated in bzr 0.13; '
 
104
             'please convert DeprecatedError to use BzrError instead'],
 
105
            DeprecatedError)
 
106
 
 
107
    def test_bzrerror_from_literal_string(self):
 
108
        # Some code constructs BzrError from a literal string, in which case
 
109
        # no further formatting is done.  (I'm not sure raising the base class
 
110
        # is a great idea, but if the exception is not intended to be caught
 
111
        # perhaps no more is needed.)
 
112
        try:
 
113
            raise errors.BzrError('this is my errors; %d is not expanded')
 
114
        except errors.BzrError, e:
 
115
            self.assertEqual('this is my errors; %d is not expanded', str(e))
 
116
 
96
117
    def test_reading_completed(self):
97
118
        error = errors.ReadingCompleted("a request")
98
119
        self.assertEqualDiff("The MediumRequest 'a request' has already had "
164
185
 
165
186
 
166
187
 
167
 
class PassThroughError(errors.BzrNewError):
168
 
    """Pass through %(foo)s and %(bar)s"""
 
188
class PassThroughError(errors.BzrError):
 
189
    
 
190
    _fmt = """Pass through %(foo)s and %(bar)s"""
169
191
 
170
192
    def __init__(self, foo, bar):
171
 
        errors.BzrNewError.__init__(self, foo=foo, bar=bar)
172
 
 
173
 
 
174
 
class ErrorWithBadFormat(errors.BzrNewError):
175
 
    """One format specifier: %(thing)s"""
 
193
        errors.BzrError.__init__(self, foo=foo, bar=bar)
 
194
 
 
195
 
 
196
class ErrorWithBadFormat(errors.BzrError):
 
197
 
 
198
    _fmt = """One format specifier: %(thing)s"""
 
199
 
 
200
 
 
201
class ErrorWithNoFormat(errors.BzrError):
 
202
    """This class has a docstring but no format string."""
176
203
 
177
204
 
178
205
class TestErrorFormatting(TestCase):
187
214
        s = str(e)
188
215
        self.assertEqual('Pass through \xc2\xb5 and bar', s)
189
216
 
 
217
    def test_missing_format_string(self):
 
218
        e = ErrorWithNoFormat(param='randomvalue')
 
219
        s = self.callDeprecated(
 
220
                ['ErrorWithNoFormat uses its docstring as a format, it should use _fmt instead'],
 
221
                lambda x: str(x), e)
 
222
        ## s = str(e)
 
223
        self.assertEqual(s, 
 
224
                "This class has a docstring but no format string.")
 
225
 
190
226
    def test_mismatched_format_args(self):
191
227
        # Even though ErrorWithBadFormat's format string does not match the
192
228
        # arguments we constructing it with, we can still stringify an instance
193
229
        # of this exception. The resulting string will say its unprintable.
194
230
        e = ErrorWithBadFormat(not_thing='x')
195
231
        self.assertStartsWith(
196
 
            str(e), 'Unprintable exception ErrorWithBadFormat(')
197
 
 
 
232
            str(e), 'Unprintable exception ErrorWithBadFormat')
198
233