ยปCore Development>Code coverage>Lib/test/test_generator_stop.py

Python code coverage for Lib/test/test_generator_stop.py

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