(self)
| 852 | self.assertEqual(result, "completed") |
| 853 | |
| 854 | def test_anext_iter(self): |
| 855 | @types.coroutine |
| 856 | def _async_yield(v): |
| 857 | return (yield v) |
| 858 | |
| 859 | class MyError(Exception): |
| 860 | pass |
| 861 | |
| 862 | async def agenfn(): |
| 863 | try: |
| 864 | await _async_yield(1) |
| 865 | except MyError: |
| 866 | await _async_yield(2) |
| 867 | return |
| 868 | yield |
| 869 | |
| 870 | def test1(anext): |
| 871 | agen = agenfn() |
| 872 | with contextlib.closing(anext(agen, "default").__await__()) as g: |
| 873 | self.assertEqual(g.send(None), 1) |
| 874 | self.assertEqual(g.throw(MyError()), 2) |
| 875 | try: |
| 876 | g.send(None) |
| 877 | except StopIteration as e: |
| 878 | err = e |
| 879 | else: |
| 880 | self.fail('StopIteration was not raised') |
| 881 | self.assertEqual(err.value, "default") |
| 882 | |
| 883 | def test2(anext): |
| 884 | agen = agenfn() |
| 885 | with contextlib.closing(anext(agen, "default").__await__()) as g: |
| 886 | self.assertEqual(g.send(None), 1) |
| 887 | self.assertEqual(g.throw(MyError()), 2) |
| 888 | with self.assertRaises(MyError): |
| 889 | g.throw(MyError()) |
| 890 | |
| 891 | def test3(anext): |
| 892 | agen = agenfn() |
| 893 | with contextlib.closing(anext(agen, "default").__await__()) as g: |
| 894 | self.assertEqual(g.send(None), 1) |
| 895 | g.close() |
| 896 | with self.assertRaisesRegex(RuntimeError, 'cannot reuse'): |
| 897 | self.assertEqual(g.send(None), 1) |
| 898 | |
| 899 | def test4(anext): |
| 900 | @types.coroutine |
| 901 | def _async_yield(v): |
| 902 | yield v * 10 |
| 903 | return (yield (v * 10 + 1)) |
| 904 | |
| 905 | async def agenfn(): |
| 906 | try: |
| 907 | await _async_yield(1) |
| 908 | except MyError: |
| 909 | await _async_yield(2) |
| 910 | return |
| 911 | yield |
nothing calls this directly
no test coverage detected