Exemplo n.º 1
0
 def test_close_idempotent(self):
     req = self.make_request("GET", "/")
     ws = WebSocketResponse()
     self.loop.run_until_complete(ws.prepare(req))
     writer = mock.Mock()
     ws._writer = writer
     self.assertTrue(self.loop.run_until_complete(ws.close(code=1, message="message1")))
     self.assertTrue(ws.closed)
     self.assertFalse(self.loop.run_until_complete(ws.close(code=2, message="message2")))
Exemplo n.º 2
0
 def test_close_idempotent(self):
     req = self.make_request('GET', '/')
     ws = WebSocketResponse()
     ws.start(req)
     writer = mock.Mock()
     ws._writer = writer
     self.assertTrue(
         self.loop.run_until_complete(ws.close(code=1, message='message1')))
     self.assertTrue(ws.closed)
     self.assertFalse(
         self.loop.run_until_complete(ws.close(code=2, message='message2')))
Exemplo n.º 3
0
 def test_double_close(self):
     req = self.make_request('GET', '/')
     ws = WebSocketResponse()
     ws.start(req)
     writer = mock.Mock()
     ws._writer = writer
     ws.close(code=1, message='message1')
     self.assertTrue(ws.closing)
     with self.assertRaisesRegex(RuntimeError, 'Already closing'):
         ws.close(code=2, message='message2')
     self.assertTrue(ws.closing)
     writer.close.assert_called_once_with(1, 'message1')
Exemplo n.º 4
0
def function113(function271):
    var2027 = function271('GET', '/')
    var2897 = WebSocketResponse()
    yield from var2897.prepare(var2027)
    var962 = ValueError()
    var2897._writer = mock.Mock()
    var2897._writer.close.side_effect = var962
    yield from var2897.close()
    assert var2897.closed
    assert (var2897.exception() is var962)
    var2897._closed = False
    var2897._writer.close.side_effect = asyncio.CancelledError()
    with pytest.raises(asyncio.CancelledError):
        yield from var2897.close()
Exemplo n.º 5
0
    def test_close_exc2(self):
        req = self.make_request("GET", "/")
        ws = WebSocketResponse()
        self.loop.run_until_complete(ws.prepare(req))

        exc = ValueError()
        self.writer.close.side_effect = exc
        ws._writer = self.writer

        self.loop.run_until_complete(ws.close())
        self.assertTrue(ws.closed)
        self.assertIs(ws.exception(), exc)

        ws._closed = False
        self.writer.close.side_effect = asyncio.CancelledError()
        self.assertRaises(asyncio.CancelledError, self.loop.run_until_complete, ws.close())
Exemplo n.º 6
0
async def test_close_exc2(make_request):

    req = make_request('GET', '/')
    ws = WebSocketResponse()
    await ws.prepare(req)

    exc = ValueError()
    ws._writer = mock.Mock()
    ws._writer.close.side_effect = exc
    await ws.close()
    assert ws.closed
    assert ws.exception() is exc

    ws._closed = False
    ws._writer.close.side_effect = asyncio.CancelledError()
    with pytest.raises(asyncio.CancelledError):
        await ws.close()
Exemplo n.º 7
0
async def test_close_exc2(make_request):

    req = make_request('GET', '/')
    ws = WebSocketResponse()
    await ws.prepare(req)

    exc = ValueError()
    ws._writer = mock.Mock()
    ws._writer.close.side_effect = exc
    await ws.close()
    assert ws.closed
    assert ws.exception() is exc

    ws._closed = False
    ws._writer.close.side_effect = asyncio.CancelledError()
    with pytest.raises(asyncio.CancelledError):
        await ws.close()
Exemplo n.º 8
0
    def test_close_exc2(self):
        req = self.make_request('GET', '/')
        ws = WebSocketResponse()
        ws.start(req)

        exc = ValueError()
        self.writer.close.side_effect = exc
        ws._writer = self.writer

        self.loop.run_until_complete(ws.close())
        self.assertTrue(ws.closed)
        self.assertIs(ws.exception(), exc)

        ws._closed = False
        self.writer.close.side_effect = asyncio.CancelledError()
        self.assertRaises(asyncio.CancelledError,
                          self.loop.run_until_complete, ws.close())