Skip to content

Commit

Permalink
Merge pull request #36 from dirn/async-await
Browse files Browse the repository at this point in the history
Always use async def
  • Loading branch information
dirn committed Dec 29, 2020
2 parents 41eb412 + ebd86d9 commit af1810f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 35 deletions.
4 changes: 1 addition & 3 deletions doozer/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Custom types for static type analysis."""

import asyncio
from typing import Any, Awaitable, Callable

from typing_extensions import Protocol
Expand All @@ -16,6 +15,5 @@
class Consumer(Protocol):
"""An implementation of the Consumer Interface."""

@asyncio.coroutine
def read(self) -> Any:
async def read(self) -> Any:
"""The read method of the Consumer Interface.""" # NOQA: D401
9 changes: 3 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def run_forever(self, num_workers=1, loop=None, debug=False):
class MockConsumer:
"""A stub consumer that can be used for testing."""

@asyncio.coroutine
def read(self):
async def read(self):
"""Return an item."""
return 1

Expand All @@ -40,8 +39,7 @@ class MockAbortingConsumer:

_run = False

@asyncio.coroutine
def read(self):
async def read(self):
"""Return an item."""
if self._run:
raise Abort("testing", {})
Expand All @@ -62,8 +60,7 @@ def cancelled_future(event_loop):
def coroutine():
"""Return a coroutine function."""

@asyncio.coroutine
def _inner(*args, **kwargs):
async def _inner(*args, **kwargs):
pass

return _inner
Expand Down
38 changes: 12 additions & 26 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Test Doozer's exceptions."""

import asyncio

from doozer import exceptions
from doozer.base import Application

Expand All @@ -18,31 +16,27 @@ def test_abort_preprocessor(event_loop, cancelled_future, queue):

queue.put_nowait({"a": 1})

@asyncio.coroutine
def callback(app, message):
async def callback(app, message):
nonlocal callback_called
callback_called = True
return message

app = Application("testing", callback=callback)

@app.message_preprocessor
@asyncio.coroutine
def preprocess1(app, message):
async def preprocess1(app, message):
nonlocal preprocess1_called
preprocess1_called = True
raise exceptions.Abort("testing", message)

@app.message_preprocessor
@asyncio.coroutine
def preprocess2(app, message):
async def preprocess2(app, message):
nonlocal preprocess2_called
preprocess2_called = True
return message

@app.result_postprocessor
@asyncio.coroutine
def postprocess(app, result):
async def postprocess(app, result):
nonlocal postprocess_called
postprocess_called = True
return result
Expand All @@ -65,17 +59,15 @@ def test_abort_callback(event_loop, cancelled_future, queue):

queue.put_nowait({"a": 1})

@asyncio.coroutine
def callback(app, message):
async def callback(app, message):
nonlocal callback_called
callback_called = True
raise exceptions.Abort("testing", message)

app = Application("testing", callback=callback)

@app.result_postprocessor
@asyncio.coroutine
def postprocess(app, result):
async def postprocess(app, result):
nonlocal postprocess_called
postprocess_called = True
return result
Expand All @@ -97,24 +89,21 @@ def test_abort_error(event_loop, cancelled_future, queue):

queue.put_nowait({"a": 1})

@asyncio.coroutine
def callback(app, message):
async def callback(app, message):
nonlocal callback_called
callback_called = True
raise TypeError("testing")

app = Application("testing", callback=callback)

@app.error
@asyncio.coroutine
def error1(app, message, exc):
async def error1(app, message, exc):
nonlocal error1_called
error1_called = True
raise exceptions.Abort("testing", message)

@app.error
@asyncio.coroutine
def error2(app, message, exc):
async def error2(app, message, exc):
nonlocal error2_called
error2_called = True

Expand All @@ -135,15 +124,13 @@ def test_abort_postprocess(event_loop, cancelled_future, queue):

queue.put_nowait({"a": 1})

@asyncio.coroutine
def callback(app, message):
async def callback(app, message):
return [True, False]

app = Application("testing", callback=callback)

@app.result_postprocessor
@asyncio.coroutine
def postprocess1(app, result):
async def postprocess1(app, result):
nonlocal postprocess1_called_count
postprocess1_called_count += 1
if result:
Expand All @@ -152,8 +139,7 @@ def postprocess1(app, result):
return result

@app.result_postprocessor
@asyncio.coroutine
def postprocess2(app, result):
async def postprocess2(app, result):
nonlocal postprocess2_called_count
postprocess2_called_count += 1
return result
Expand Down

0 comments on commit af1810f

Please sign in to comment.