summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_coroutines.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@gmail.com>2017-03-03 03:20:00 (GMT)
committerGitHub <noreply@github.com>2017-03-03 03:20:00 (GMT)
commit398ff91ac0b8f4d930cd5d9e3e6a4bf247f810ef (patch)
tree574e40060c9c962fa87627af595ee540dbe33ab1 /Lib/test/test_coroutines.py
parent8d26aa930c0123933a1ceb12fceba4f5aef4e95e (diff)
downloadcpython-398ff91ac0b8f4d930cd5d9e3e6a4bf247f810ef.zip
cpython-398ff91ac0b8f4d930cd5d9e3e6a4bf247f810ef.tar.gz
cpython-398ff91ac0b8f4d930cd5d9e3e6a4bf247f810ef.tar.bz2
bpo-28893: Set __cause__ for errors in async iteration protocol (#407)
Diffstat (limited to 'Lib/test/test_coroutines.py')
-rw-r--r--Lib/test/test_coroutines.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py
index 78439a2..b4c7b5b 100644
--- a/Lib/test/test_coroutines.py
+++ b/Lib/test/test_coroutines.py
@@ -1680,6 +1680,44 @@ class CoroutineTest(unittest.TestCase):
warnings.simplefilter("error")
run_async(foo())
+ def test_for_11(self):
+ class F:
+ def __aiter__(self):
+ return self
+ def __anext__(self):
+ return self
+ def __await__(self):
+ 1 / 0
+
+ async def main():
+ async for _ in F():
+ pass
+
+ with self.assertRaisesRegex(TypeError,
+ 'an invalid object from __anext__') as c:
+ main().send(None)
+
+ err = c.exception
+ self.assertIsInstance(err.__cause__, ZeroDivisionError)
+
+ def test_for_12(self):
+ class F:
+ def __aiter__(self):
+ return self
+ def __await__(self):
+ 1 / 0
+
+ async def main():
+ async for _ in F():
+ pass
+
+ with self.assertRaisesRegex(TypeError,
+ 'an invalid object from __aiter__') as c:
+ main().send(None)
+
+ err = c.exception
+ self.assertIsInstance(err.__cause__, ZeroDivisionError)
+
def test_for_tuple(self):
class Done(Exception): pass