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