MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_Awaitable

Method test_Awaitable

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected