(self)
| 2422 | wd['h'] = h # Would fail without __weakref__ slot. |
| 2423 | |
| 2424 | def test_handle_repr(self): |
| 2425 | self.loop.get_debug.return_value = False |
| 2426 | |
| 2427 | # simple function |
| 2428 | h = asyncio.Handle(noop, (1, 2), self.loop) |
| 2429 | filename, lineno = test_utils.get_function_source(noop) |
| 2430 | self.assertEqual(repr(h), |
| 2431 | '<Handle noop() at %s:%s>' |
| 2432 | % (filename, lineno)) |
| 2433 | |
| 2434 | # cancelled handle |
| 2435 | h.cancel() |
| 2436 | self.assertEqual(repr(h), |
| 2437 | '<Handle cancelled>') |
| 2438 | |
| 2439 | # decorated function |
| 2440 | cb = types.coroutine(noop) |
| 2441 | h = asyncio.Handle(cb, (), self.loop) |
| 2442 | self.assertEqual(repr(h), |
| 2443 | '<Handle noop() at %s:%s>' |
| 2444 | % (filename, lineno)) |
| 2445 | |
| 2446 | # partial function |
| 2447 | cb = functools.partial(noop, 1, 2) |
| 2448 | h = asyncio.Handle(cb, (3,), self.loop) |
| 2449 | regex = (r'^<Handle noop\(\)\(\) at %s:%s>$' |
| 2450 | % (re.escape(filename), lineno)) |
| 2451 | self.assertRegex(repr(h), regex) |
| 2452 | |
| 2453 | # partial function with keyword args |
| 2454 | cb = functools.partial(noop, x=1) |
| 2455 | h = asyncio.Handle(cb, (2, 3), self.loop) |
| 2456 | regex = (r'^<Handle noop\(\)\(\) at %s:%s>$' |
| 2457 | % (re.escape(filename), lineno)) |
| 2458 | self.assertRegex(repr(h), regex) |
| 2459 | |
| 2460 | # partial method |
| 2461 | method = HandleTests.test_handle_repr |
| 2462 | cb = functools.partialmethod(method) |
| 2463 | filename, lineno = test_utils.get_function_source(method) |
| 2464 | h = asyncio.Handle(cb, (), self.loop) |
| 2465 | |
| 2466 | cb_regex = r'<function HandleTests.test_handle_repr .*>' |
| 2467 | cb_regex = fr'functools.partialmethod\({cb_regex}\)\(\)' |
| 2468 | regex = fr'^<Handle {cb_regex} at {re.escape(filename)}:{lineno}>$' |
| 2469 | self.assertRegex(repr(h), regex) |
| 2470 | |
| 2471 | def test_handle_repr_debug(self): |
| 2472 | self.loop.get_debug.return_value = True |
nothing calls this directly
no test coverage detected