Skip to content

Commit

Permalink
Successfully pass run_until_complete (#2161)
Browse files Browse the repository at this point in the history
* Successfully pass run_until_complete

* Add missing test
  • Loading branch information
asvetlov authored Aug 3, 2017
1 parent 2c2172a commit 590143a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
18 changes: 14 additions & 4 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,19 @@

class _BaseCoroMixin(base):

__slots__ = ('_coro', 'send', 'throw', 'close')
__slots__ = ('_coro')

def __init__(self, coro):
self._coro = coro
self.send = coro.send
self.throw = coro.throw
self.close = coro.close

def send(self, arg):
return self._coro.send(arg)

def throw(self, arg):
return self._coro.throw(arg)

def close(self):
return self._coro.close()

@property
def gi_frame(self):
Expand Down Expand Up @@ -113,6 +119,10 @@ def __init__(self, coro, msg):
self._msg = msg
self._awaited = False

def send(self, arg):
self._awaited = True
return self._coro.send(arg)

@asyncio.coroutine
def __iter__(self):
self._awaited = True
Expand Down
6 changes: 6 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def test_no_warn_on_await():
assert not ctx.list


def test_coro_guard_close():
guard = helpers.deprecated_noop('Text')
guard.close()
assert not guard.gi_running


# ------------------- parse_mimetype ----------------------------------

def test_parse_mimetype_1():
Expand Down
24 changes: 22 additions & 2 deletions tests/test_py35/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,32 @@


async def test_async_with_session(loop):
async with aiohttp.ClientSession(loop=loop) as session:
pass
with pytest.warns(None) as cm:
async with aiohttp.ClientSession(loop=loop) as session:
pass
assert len(cm.list) == 0

assert session.closed


async def test_session_close_awaitable(loop):
session = aiohttp.ClientSession(loop=loop)
with pytest.warns(None) as cm:
await session.close()
assert len(cm.list) == 0

assert session.closed


def test_close_run_until_complete_not_deprecated(loop):
session = aiohttp.ClientSession(loop=loop)

with pytest.warns(None) as cm:
loop.run_until_complete(session.close())

assert len(cm.list) == 0


async def test_close_resp_on_error_async_with_session(loop, test_server):
async def handler(request):
resp = web.StreamResponse(headers={'content-length': '100'})
Expand Down

0 comments on commit 590143a

Please sign in to comment.