async def test_on_eof_empty_reader() -> None: reader = streams.EmptyStreamReader() on_eof = mock.Mock() reader.on_eof(on_eof) assert on_eof.called
def create_request(raw_request_lines): """ :param raw_request_lines: HTTP Request lines without line ends :type raw_request_lines: list(str) :rtype: Request """ class ParserOut: """ :param message: :type message: protocol.RawRequestMessage """ def feed_data(po, m, _): po.message = m def feed_eof(po, *args): pass raw_request = "\r\n".join(raw_request_lines + ["\r\n"]).encode("utf-8") po = ParserOut() p = protocol.HttpRequestParser() asyncio.get_event_loop() \ .run_until_complete(p(po, parsers.ParserBuffer(raw_request))) return Request(None, po.message, streams.EmptyStreamReader(), None, None, None)
async def test_on_eof_exc_in_callback_empty_stream_reader() -> None: reader = streams.EmptyStreamReader() on_eof = mock.Mock() on_eof.side_effect = ValueError reader.on_eof(on_eof) assert on_eof.called
def test_empty_stream_reader(self): s = streams.EmptyStreamReader() self.assertIsNone(s.set_exception(ValueError())) self.assertIsNone(s.exception()) self.assertIsNone(s.feed_eof()) self.assertIsNone(s.feed_data(b'data')) self.assertTrue(s.at_eof()) self.assertIsNone(self.loop.run_until_complete(s.wait_eof())) self.assertEqual(self.loop.run_until_complete(s.read()), b'') self.assertEqual(self.loop.run_until_complete(s.readline()), b'') self.assertEqual(self.loop.run_until_complete(s.readany()), b'') self.assertRaises(asyncio.IncompleteReadError, self.loop.run_until_complete, s.readexactly(10)) self.assertEqual(s.read_nowait(), b'')
async def test_empty_stream_reader() -> None: s = streams.EmptyStreamReader() assert s.set_exception(ValueError()) is None assert s.exception() is None assert s.feed_eof() is None assert s.feed_data(b"data") is None assert s.at_eof() assert (await s.wait_eof()) is None assert await s.read() == b"" assert await s.readline() == b"" assert await s.readany() == b"" assert await s.readchunk() == (b"", True) with pytest.raises(asyncio.IncompleteReadError): await s.readexactly(10) assert s.read_nowait() == b""
def function2520(self): var1588 = streams.EmptyStreamReader() self.assertIsNone(var1588.set_exception(ValueError())) self.assertIsNone(var1588.exception()) self.assertIsNone(var1588.feed_eof()) self.assertIsNone(var1588.feed_data(b'data')) self.assertTrue(var1588.at_eof()) self.assertIsNone( self.attribute836.run_until_complete(var1588.wait_eof())) self.assertEqual(self.attribute836.run_until_complete(var1588.read()), b'') self.assertEqual( self.attribute836.run_until_complete(var1588.readline()), b'') self.assertEqual( self.attribute836.run_until_complete(var1588.readany()), b'') self.assertEqual( self.attribute836.run_until_complete(var1588.readchunk()), b'') self.assertRaises(asyncio.IncompleteReadError, self.attribute836.run_until_complete, var1588.readexactly(10)) self.assertEqual(var1588.read_nowait(), b'')
{message} </body> </html>""" if hasattr(socket, 'SO_KEEPALIVE'): def tcp_keepalive(server, transport): sock = transport.get_extra_info('socket') sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) else: def tcp_keepalive(server, transport): # pragma: no cover pass EMPTY_PAYLOAD = streams.EmptyStreamReader() class ServerHttpProtocol(aiohttp.StreamProtocol): """Simple HTTP protocol implementation. ServerHttpProtocol handles incoming HTTP request. It reads request line, request headers and request payload and calls handle_request() method. By default it always returns with 404 response. ServerHttpProtocol handles errors in incoming request, like bad status line, bad headers or incomplete payload. If any error occurs, connection gets closed. :param keepalive_timeout: number of seconds before closing keep-alive connection
def function605(arg276): var3909 = streams.EmptyStreamReader() var2028 = mock.Mock() var2028.side_effect = ValueError var3909.var2028(var2028) assert var2028.called
def function2864(arg2074): var2958 = streams.EmptyStreamReader() var506 = mock.Mock() var2958.var506(var506) assert var506.called