Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e9ad5a5

Browse files
committed
Issue 22906: Add test file.
1 parent 8170e8c commit e9ad5a5

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lib/test/test_pep479.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from __future__ import generator_stop
2+
3+
import unittest
4+
5+
6+
class TestPEP479(unittest.TestCase):
7+
def test_stopiteration_wrapping(self):
8+
def f():
9+
raise StopIteration
10+
def g():
11+
yield f()
12+
with self.assertRaisesRegex(RuntimeError,
13+
"generator raised StopIteration"):
14+
next(g())
15+
16+
def test_stopiteration_wrapping_context(self):
17+
def f():
18+
raise StopIteration
19+
def g():
20+
yield f()
21+
22+
try:
23+
next(g())
24+
except RuntimeError as exc:
25+
self.assertIs(type(exc.__cause__), StopIteration)
26+
self.assertIs(type(exc.__context__), StopIteration)
27+
self.assertTrue(exc.__suppress_context__)
28+
else:
29+
self.fail('__cause__, __context__, or __suppress_context__ '
30+
'were not properly set')
31+
32+
33+
if __name__ == '__main__':
34+
unittest.main()

0 commit comments

Comments
 (0)