MCPcopy Index your code
hub / github.com/python/cpython / test_Awaitable

Method test_Awaitable

Lib/test/test_collections.py:790–840  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

788class TestOneTrickPonyABCs(ABCTestCase):
789
790 def test_Awaitable(self):
791 def gen():
792 yield
793
794 @types.coroutine
795 def coro():
796 yield
797
798 async def new_coro():
799 pass
800
801 class Bar:
802 def __await__(self):
803 yield
804
805 class MinimalCoro(Coroutine):
806 def send(self, value):
807 return value
808 def throw(self, typ, val=None, tb=None):
809 super().throw(typ, val, tb)
810 def __await__(self):
811 yield
812
813 self.validate_abstract_methods(Awaitable, '__await__')
814
815 non_samples = [None, int(), gen(), object()]
816 for x in non_samples:
817 self.assertNotIsInstance(x, Awaitable)
818 self.assertNotIsSubclass(type(x), Awaitable)
819
820 samples = [Bar(), MinimalCoro()]
821 for x in samples:
822 self.assertIsInstance(x, Awaitable)
823 self.assertIsSubclass(type(x), Awaitable)
824
825 c = coro()
826 # Iterable coroutines (generators with CO_ITERABLE_COROUTINE
827 # flag don't have '__await__' method, hence can't be instances
828 # of Awaitable. Use inspect.isawaitable to detect them.
829 self.assertNotIsInstance(c, Awaitable)
830
831 c = new_coro()
832 self.assertIsInstance(c, Awaitable)
833 c.close() # avoid RuntimeWarning that coro() was not awaited
834
835 class CoroLike: pass
836 Coroutine.register(CoroLike)
837 self.assertIsInstance(CoroLike(), Awaitable)
838 self.assertIsSubclass(CoroLike, Awaitable)
839 CoroLike = None
840 support.gc_collect() # Kill CoroLike to clean-up ABCMeta cache
841
842 def test_Coroutine(self):
843 def gen():

Callers

nothing calls this directly

Calls 11

MinimalCoroClass · 0.85
assertNotIsInstanceMethod · 0.80
assertNotIsSubclassMethod · 0.80
assertIsInstanceMethod · 0.80
assertIsSubclassMethod · 0.80
genFunction · 0.70
BarClass · 0.70
CoroLikeClass · 0.70
closeMethod · 0.45
registerMethod · 0.45

Tested by

no test coverage detected