diff options
author | Guido van Rossum <guido@python.org> | 2016-09-30 15:17:15 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2016-09-30 15:17:15 (GMT) |
commit | e3c65a7a228a5808a7af48a47fdd77e982f95d00 (patch) | |
tree | 4cc2fd3d36c79999764bb7c9a2de133fb1f5d034 /Lib/test/test_asyncio/test_tasks.py | |
parent | 07cfd504e43c5078b8d106395c45b0a3f6c22fa3 (diff) | |
download | cpython-e3c65a7a228a5808a7af48a47fdd77e982f95d00.zip cpython-e3c65a7a228a5808a7af48a47fdd77e982f95d00.tar.gz cpython-e3c65a7a228a5808a7af48a47fdd77e982f95d00.tar.bz2 |
Misc asyncio improvements from upstream
Diffstat (limited to 'Lib/test/test_asyncio/test_tasks.py')
-rw-r--r-- | Lib/test/test_asyncio/test_tasks.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index e7fb774..2863c42 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -1723,6 +1723,37 @@ class TaskTests(test_utils.TestCase): wd['cw'] = cw # Would fail without __weakref__ slot. cw.gen = None # Suppress warning from __del__. + def test_corowrapper_throw(self): + # Issue 429: CoroWrapper.throw must be compatible with gen.throw + def foo(): + value = None + while True: + try: + value = yield value + except Exception as e: + value = e + + exception = Exception("foo") + cw = asyncio.coroutines.CoroWrapper(foo()) + cw.send(None) + self.assertIs(exception, cw.throw(exception)) + + cw = asyncio.coroutines.CoroWrapper(foo()) + cw.send(None) + self.assertIs(exception, cw.throw(Exception, exception)) + + cw = asyncio.coroutines.CoroWrapper(foo()) + cw.send(None) + exception = cw.throw(Exception, "foo") + self.assertIsInstance(exception, Exception) + self.assertEqual(exception.args, ("foo", )) + + cw = asyncio.coroutines.CoroWrapper(foo()) + cw.send(None) + exception = cw.throw(Exception, "foo", None) + self.assertIsInstance(exception, Exception) + self.assertEqual(exception.args, ("foo", )) + @unittest.skipUnless(PY34, 'need python 3.4 or later') def test_log_destroyed_pending_task(self): |