1from __future__ import generator_stop
2
3import unittest
4
5
6class 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
33if __name__ == '__main__':
34    unittest.main()
35