(self)
| 246 | self.assertFalse(inspect.ispackage(FakePackage())) |
| 247 | |
| 248 | def test_iscoroutine(self): |
| 249 | async_gen_coro = async_generator_function_example(1) |
| 250 | gen_coro = gen_coroutine_function_example(1) |
| 251 | coro = coroutine_function_example(1) |
| 252 | |
| 253 | class PMClass: |
| 254 | async_generator_partialmethod_example = functools.partialmethod( |
| 255 | async_generator_function_example) |
| 256 | coroutine_partialmethod_example = functools.partialmethod( |
| 257 | coroutine_function_example) |
| 258 | gen_coroutine_partialmethod_example = functools.partialmethod( |
| 259 | gen_coroutine_function_example) |
| 260 | |
| 261 | # partialmethods on the class, bound to an instance |
| 262 | pm_instance = PMClass() |
| 263 | async_gen_coro_pmi = pm_instance.async_generator_partialmethod_example |
| 264 | gen_coro_pmi = pm_instance.gen_coroutine_partialmethod_example |
| 265 | coro_pmi = pm_instance.coroutine_partialmethod_example |
| 266 | |
| 267 | # partialmethods on the class, unbound but accessed via the class |
| 268 | async_gen_coro_pmc = PMClass.async_generator_partialmethod_example |
| 269 | gen_coro_pmc = PMClass.gen_coroutine_partialmethod_example |
| 270 | coro_pmc = PMClass.coroutine_partialmethod_example |
| 271 | |
| 272 | self.assertFalse( |
| 273 | inspect.iscoroutinefunction(gen_coroutine_function_example)) |
| 274 | self.assertFalse( |
| 275 | inspect.iscoroutinefunction( |
| 276 | functools.partial(functools.partial( |
| 277 | gen_coroutine_function_example)))) |
| 278 | self.assertFalse(inspect.iscoroutinefunction(gen_coro_pmi)) |
| 279 | self.assertFalse(inspect.iscoroutinefunction(gen_coro_pmc)) |
| 280 | self.assertFalse(inspect.iscoroutinefunction(inspect)) |
| 281 | self.assertFalse(inspect.iscoroutine(gen_coro)) |
| 282 | |
| 283 | self.assertTrue( |
| 284 | inspect.isgeneratorfunction(gen_coroutine_function_example)) |
| 285 | self.assertTrue( |
| 286 | inspect.isgeneratorfunction( |
| 287 | functools.partial(functools.partial( |
| 288 | gen_coroutine_function_example)))) |
| 289 | self.assertTrue(inspect.isgeneratorfunction(gen_coro_pmi)) |
| 290 | self.assertTrue(inspect.isgeneratorfunction(gen_coro_pmc)) |
| 291 | self.assertTrue(inspect.isgenerator(gen_coro)) |
| 292 | |
| 293 | async def _fn3(): |
| 294 | pass |
| 295 | |
| 296 | @inspect.markcoroutinefunction |
| 297 | def fn3(): |
| 298 | return _fn3() |
| 299 | |
| 300 | self.assertTrue(inspect.iscoroutinefunction(fn3)) |
| 301 | self.assertTrue( |
| 302 | inspect.iscoroutinefunction( |
| 303 | inspect.markcoroutinefunction(lambda: _fn3()) |
| 304 | ) |
| 305 | ) |
nothing calls this directly
no test coverage detected