@@ -1723,6 +1723,37 @@ def foo(): yield from []
1723
1723
wd ['cw' ] = cw # Would fail without __weakref__ slot.
1724
1724
cw .gen = None # Suppress warning from __del__.
1725
1725
1726
+ def test_corowrapper_throw (self ):
1727
+ # Issue 429: CoroWrapper.throw must be compatible with gen.throw
1728
+ def foo ():
1729
+ value = None
1730
+ while True :
1731
+ try :
1732
+ value = yield value
1733
+ except Exception as e :
1734
+ value = e
1735
+
1736
+ exception = Exception ("foo" )
1737
+ cw = asyncio .coroutines .CoroWrapper (foo ())
1738
+ cw .send (None )
1739
+ self .assertIs (exception , cw .throw (exception ))
1740
+
1741
+ cw = asyncio .coroutines .CoroWrapper (foo ())
1742
+ cw .send (None )
1743
+ self .assertIs (exception , cw .throw (Exception , exception ))
1744
+
1745
+ cw = asyncio .coroutines .CoroWrapper (foo ())
1746
+ cw .send (None )
1747
+ exception = cw .throw (Exception , "foo" )
1748
+ self .assertIsInstance (exception , Exception )
1749
+ self .assertEqual (exception .args , ("foo" , ))
1750
+
1751
+ cw = asyncio .coroutines .CoroWrapper (foo ())
1752
+ cw .send (None )
1753
+ exception = cw .throw (Exception , "foo" , None )
1754
+ self .assertIsInstance (exception , Exception )
1755
+ self .assertEqual (exception .args , ("foo" , ))
1756
+
1726
1757
@unittest .skipUnless (PY34 ,
1727
1758
'need python 3.4 or later' )
1728
1759
def test_log_destroyed_pending_task (self ):
0 commit comments