/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 breezy/tests/test_smart_request.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
 
51
51
class ChunkErrorRequest(request.SmartServerRequest):
52
52
    """A request that raises an error from self.do_chunk()."""
53
 
    
 
53
 
54
54
    def do(self):
55
55
        """No-op."""
56
56
        pass
61
61
 
62
62
class EndErrorRequest(request.SmartServerRequest):
63
63
    """A request that raises an error from self.do_end()."""
64
 
    
 
64
 
65
65
    def do(self):
66
66
        """No-op."""
67
67
        pass
69
69
    def do_chunk(self, bytes):
70
70
        """No-op."""
71
71
        pass
72
 
        
 
72
 
73
73
    def do_end(self):
74
74
        raise errors.NoSuchFile('xyzzy')
75
75
 
135
135
                unclassified_requests.append(key)
136
136
        if unclassified_requests:
137
137
            self.fail('These requests were not categorized as safe/unsafe'
138
 
                      ' to retry: %s'  % (unclassified_requests,))
 
138
                      ' to retry: %s' % (unclassified_requests,))
139
139
 
140
140
 
141
141
class TestSmartRequestHandlerErrorTranslation(TestCase):
215
215
 
216
216
    def test_generic_Exception(self):
217
217
        self.assertTranslationEqual((b'error', b'Exception', b""),
218
 
            Exception())
 
218
                                    Exception())
219
219
 
220
220
    def test_generic_BzrError(self):
221
221
        self.assertTranslationEqual((b'error', b'BzrError', b"some text"),
222
 
            errors.BzrError(msg="some text"))
 
222
                                    errors.BzrError(msg="some text"))
223
223
 
224
224
    def test_generic_zlib_error(self):
225
225
        from zlib import error
226
226
        msg = "Error -3 while decompressing data: incorrect data check"
227
227
        self.assertTranslationEqual((b'error', b'zlib.error', msg.encode('utf-8')),
228
 
            error(msg))
 
228
                                    error(msg))
229
229
 
230
230
 
231
231
class TestRequestJail(TestCaseWithMemoryTransport):
244
244
 
245
245
    def setUp(self):
246
246
        super(TestJailHook, self).setUp()
 
247
 
247
248
        def clear_jail_info():
248
249
            request.jail_info.transports = None
249
250
        self.addCleanup(clear_jail_info)
267
268
 
268
269
    def test_open_bzrdir_in_non_main_thread(self):
269
270
        """Opening a bzrdir in a non-main thread should work ok.
270
 
        
 
271
 
271
272
        This makes sure that the globally-installed
272
273
        breezy.bzr.smart.request._pre_open_hook, which uses a threading.local(),
273
274
        works in a newly created thread.
275
276
        bzrdir = self.make_controldir('.')
276
277
        transport = bzrdir.root_transport
277
278
        thread_result = []
 
279
 
278
280
        def t():
279
281
            BzrDir.open_from_transport(transport)
280
282
            thread_result.append('ok')
282
284
        thread.start()
283
285
        thread.join()
284
286
        self.assertEqual(['ok'], thread_result)
285