| 841 | coro.close() |
| 842 | |
| 843 | def test_func_18(self): |
| 844 | # See http://bugs.python.org/issue25887 for details |
| 845 | |
| 846 | async def coroutine(): |
| 847 | return 'spam' |
| 848 | |
| 849 | coro = coroutine() |
| 850 | await_iter = coro.__await__() |
| 851 | it = iter(await_iter) |
| 852 | |
| 853 | with self.assertRaisesRegex(StopIteration, 'spam'): |
| 854 | it.send(None) |
| 855 | |
| 856 | with self.assertRaisesRegex(RuntimeError, |
| 857 | 'cannot reuse already awaited coroutine'): |
| 858 | it.send(None) |
| 859 | |
| 860 | with self.assertRaisesRegex(RuntimeError, |
| 861 | 'cannot reuse already awaited coroutine'): |
| 862 | # Although the iterator protocol requires iterators to |
| 863 | # raise another StopIteration here, we don't want to do |
| 864 | # that. In this particular case, the iterator will raise |
| 865 | # a RuntimeError, so that 'yield from' and 'await' |
| 866 | # expressions will trigger the error, instead of silently |
| 867 | # ignoring the call. |
| 868 | next(it) |
| 869 | |
| 870 | with self.assertRaisesRegex(RuntimeError, |
| 871 | 'cannot reuse already awaited coroutine'): |
| 872 | it.throw(Exception('wat')) |
| 873 | |
| 874 | with self.assertRaisesRegex(RuntimeError, |
| 875 | 'cannot reuse already awaited coroutine'): |
| 876 | it.throw(Exception('wat')) |
| 877 | |
| 878 | # Closing a coroutine shouldn't raise any exception even if it's |
| 879 | # already closed/exhausted (similar to generators) |
| 880 | it.close() |
| 881 | it.close() |
| 882 | |
| 883 | def test_func_19(self): |
| 884 | CHK = 0 |