(self)
| 839 | support.gc_collect() # Kill CoroLike to clean-up ABCMeta cache |
| 840 | |
| 841 | def test_Coroutine(self): |
| 842 | def gen(): |
| 843 | yield |
| 844 | |
| 845 | @types.coroutine |
| 846 | def coro(): |
| 847 | yield |
| 848 | |
| 849 | async def new_coro(): |
| 850 | pass |
| 851 | |
| 852 | class Bar: |
| 853 | def __await__(self): |
| 854 | yield |
| 855 | |
| 856 | class MinimalCoro(Coroutine): |
| 857 | def send(self, value): |
| 858 | return value |
| 859 | def throw(self, typ, val=None, tb=None): |
| 860 | super().throw(typ, val, tb) |
| 861 | def __await__(self): |
| 862 | yield |
| 863 | |
| 864 | self.validate_abstract_methods(Coroutine, '__await__', 'send', 'throw') |
| 865 | |
| 866 | non_samples = [None, int(), gen(), object(), Bar()] |
| 867 | for x in non_samples: |
| 868 | self.assertNotIsInstance(x, Coroutine) |
| 869 | self.assertNotIsSubclass(type(x), Coroutine) |
| 870 | |
| 871 | samples = [MinimalCoro()] |
| 872 | for x in samples: |
| 873 | self.assertIsInstance(x, Awaitable) |
| 874 | self.assertIsSubclass(type(x), Awaitable) |
| 875 | |
| 876 | c = coro() |
| 877 | # Iterable coroutines (generators with CO_ITERABLE_COROUTINE |
| 878 | # flag don't have '__await__' method, hence can't be instances |
| 879 | # of Coroutine. Use inspect.isawaitable to detect them. |
| 880 | self.assertNotIsInstance(c, Coroutine) |
| 881 | |
| 882 | c = new_coro() |
| 883 | self.assertIsInstance(c, Coroutine) |
| 884 | c.close() # avoid RuntimeWarning that coro() was not awaited |
| 885 | |
| 886 | class CoroLike: |
| 887 | def send(self, value): |
| 888 | pass |
| 889 | def throw(self, typ, val=None, tb=None): |
| 890 | pass |
| 891 | def close(self): |
| 892 | pass |
| 893 | def __await__(self): |
| 894 | pass |
| 895 | self.assertIsInstance(CoroLike(), Coroutine) |
| 896 | self.assertIsSubclass(CoroLike, Coroutine) |
| 897 | |
| 898 | class CoroLike: |
nothing calls this directly
no test coverage detected