1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 01:03:24 +00:00

Allow test failure on pypy3+aiohttp

This commit is contained in:
Luiz Menezes
2018-05-08 09:45:17 -03:00
parent 867fd9ab4b
commit 140bc2ee74
2 changed files with 18 additions and 11 deletions

View File

@@ -30,6 +30,8 @@ matrix:
python: 2.7
- env: TOX_SUFFIX="aiohttp"
python: pypy
- env: TOX_SUFFIX="aiohttp"
python: "pypy3.5-5.9.0"
python:
- 2.7
- 3.5

View File

@@ -1,16 +1,21 @@
# flake8: noqa
import asyncio
import aiohttp
async def aiohttp_request(loop, method, url, output='text',
encoding='utf-8', headers=None, **kwargs):
async with aiohttp.ClientSession(loop=loop, headers=headers or {}) as session:
async with session.request(method, url, **kwargs) as response:
if output == 'text':
content = await response.text()
elif output == 'json':
content = await response.json(encoding=encoding)
elif output == 'raw':
content = await response.read()
@asyncio.coroutine
def aiohttp_request(loop, method, url, output='text', encoding='utf-8', **kwargs):
session = aiohttp.ClientSession(loop=loop)
response_ctx = session.request(method, url, **kwargs)
return response, content
response = yield from response_ctx.__aenter__()
if output == 'text':
content = yield from response.text()
elif output == 'json':
content = yield from response.json(encoding=encoding)
elif output == 'raw':
content = yield from response.read()
response_ctx._resp.close()
yield from session.close()