Beispiel #1
0
    def test_sync_call(self):
        def send(chunk):
            ident = self.requester._requests.keys()[0]
            self.requester.handle_response(ident, result='world')

        self.requester = jsonrpc.Requester(send)
        assert self.requester.sync_call('hello') == 'world'
Beispiel #2
0
    def setup(self):
        self.outgoing = []
        self.callback_called = False

        def send_request(request):
            self.outgoing.append(request)

        self.requester = jsonrpc.Requester(send_request)
Beispiel #3
0
    def test_send_failure(self):
        def send(chunk):
            raise ValueError('test send failure')

        self.requester = jsonrpc.Requester(send)
        cb = lambda **kw: None
        ident = '{:x}'.format(id(cb))
        try:
            self.requester.async_request(cb, 'hello')
        except ValueError as e:
            assert str(e) == 'test send failure'
        assert not self.requester._requests
Beispiel #4
0
    def test_sync_call_error(self):
        def send(chunk):
            ident = self.requester._requests.keys()[0]
            self.requester.handle_response(ident,
                                           error=ValueError('test error'))

        self.requester = jsonrpc.Requester(send)
        try:
            self.requester.sync_call('hello')
        except ValueError as e:
            assert str(e) == 'test error'
        else:
            assert False