diff options
| author | Michele Simionato <michele.simionato@gmail.com> | 2017-06-06 19:29:45 +0200 |
|---|---|---|
| committer | Michele Simionato <michele.simionato@gmail.com> | 2017-06-06 19:29:45 +0200 |
| commit | 24bc55b8c3446a417ce80b15b7cbf15b6b120ffc (patch) | |
| tree | 6eae8c6fd6f3b1b68582565cbe86ea51a4d391e1 /src/tests | |
| parent | 238bf589eb6100f2da4efba3a9c9297adbd63bef (diff) | |
| download | python-decorator-git-24bc55b8c3446a417ce80b15b7cbf15b6b120ffc.tar.gz | |
Fixed bug in the decoration of coroutines
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/test.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/tests/test.py b/src/tests/test.py index 0e31053..d882418 100644 --- a/src/tests/test.py +++ b/src/tests/test.py @@ -24,18 +24,21 @@ def assertRaises(etype): raise Exception('Expected %s' % etype.__name__) if sys.version >= '3.5': - exec('''\ -class CoroutineTestCase(unittest.TestCase): - def test(self): - async def cor(): - pass - self.assertTrue(inspect.iscoroutinefunction(cor)) + exec('''from asyncio import get_event_loop + +@decorator +async def before_after(coro, *args, **kwargs): + return "<before>" + (await coro(*args, **kwargs)) + "<after>" - @decorator - def identity(f, *args, **kwargs): - return f(*args, **kwargs) - self.assertTrue(inspect.iscoroutinefunction(identity(cor))) +class CoroutineTestCase(unittest.TestCase): + def test(self): + @before_after + async def coro(x): + return x + self.assertTrue(inspect.iscoroutinefunction(coro)) + out = get_event_loop().run_until_complete(coro('x')) + self.assertEqual(out, '<before>x<after>') ''') |
