summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMichele Simionato <michele.simionato@gmail.com>2017-06-06 19:29:45 +0200
committerMichele Simionato <michele.simionato@gmail.com>2017-06-06 19:29:45 +0200
commit24bc55b8c3446a417ce80b15b7cbf15b6b120ffc (patch)
tree6eae8c6fd6f3b1b68582565cbe86ea51a4d391e1 /src/tests
parent238bf589eb6100f2da4efba3a9c9297adbd63bef (diff)
downloadpython-decorator-git-24bc55b8c3446a417ce80b15b7cbf15b6b120ffc.tar.gz
Fixed bug in the decoration of coroutines
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/test.py23
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>')
''')