~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_request.py

(gz) Fix test failure on alpha by correcting format string for
 gc_chk_sha1_record (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
        raise errors.NoSuchFile('xyzzy')
42
42
 
43
43
 
44
 
class DoUnexpectedErrorRequest(request.SmartServerRequest):
45
 
    """A request that encounters a generic error in self.do()"""
46
 
 
47
 
    def do(self):
48
 
        dict()[1]
49
 
 
50
 
 
51
44
class ChunkErrorRequest(request.SmartServerRequest):
52
45
    """A request that raises an error from self.do_chunk()."""
53
46
    
156
149
        handler.end_received()
157
150
        self.assertResponseIsTranslatedError(handler)
158
151
 
159
 
    def test_unexpected_error_translation(self):
160
 
        handler = request.SmartServerRequestHandler(
161
 
            None, {'foo': DoUnexpectedErrorRequest}, '/')
162
 
        handler.args_received(('foo',))
163
 
        self.assertEqual(
164
 
            request.FailedSmartServerResponse(('error', 'KeyError', "1")),
165
 
            handler.response)
166
 
 
167
152
 
168
153
class TestRequestHanderErrorTranslation(TestCase):
169
154
    """Tests for bzrlib.smart.request._translate_error."""
187
172
            ('TokenMismatch', 'some-token', 'actual-token'),
188
173
            errors.TokenMismatch('some-token', 'actual-token'))
189
174
 
190
 
    def test_MemoryError(self):
191
 
        self.assertTranslationEqual(("MemoryError",), MemoryError())
192
 
 
193
 
    def test_generic_Exception(self):
194
 
        self.assertTranslationEqual(('error', 'Exception', ""),
195
 
            Exception())
196
 
 
197
 
    def test_generic_BzrError(self):
198
 
        self.assertTranslationEqual(('error', 'BzrError', "some text"),
199
 
            errors.BzrError(msg="some text"))
200
 
 
201
 
    def test_generic_zlib_error(self):
202
 
        from zlib import error
203
 
        msg = "Error -3 while decompressing data: incorrect data check"
204
 
        self.assertTranslationEqual(('error', 'zlib.error', msg),
205
 
            error(msg))
206
 
 
207
175
 
208
176
class TestRequestJail(TestCaseWithMemoryTransport):
209
177
 
240
208
        self.assertRaises(errors.JailBreak, _pre_open_hook, t.clone('..'))
241
209
        # A completely unrelated transport is not allowed
242
210
        self.assertRaises(errors.JailBreak, _pre_open_hook,
243
 
                          transport.get_transport_from_url('http://host/'))
 
211
                          transport.get_transport('http://host/'))
244
212
 
245
213
    def test_open_bzrdir_in_non_main_thread(self):
246
214
        """Opening a bzrdir in a non-main thread should work ok.