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

Method test_future_repr

Lib/test/test_asyncio/test_futures.py:344–411  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

342 self.assertEqual(next(g), ('C', 42)) # yield 'C', y.
343
344 def test_future_repr(self):
345 self.loop.set_debug(True)
346 f_pending_debug = self._new_future(loop=self.loop)
347 frame = f_pending_debug._source_traceback[-1]
348 self.assertEqual(
349 repr(f_pending_debug),
350 f'<{self.cls.__name__} pending created at {frame[0]}:{frame[1]}>')
351 f_pending_debug.cancel()
352
353 self.loop.set_debug(False)
354 f_pending = self._new_future(loop=self.loop)
355 self.assertEqual(repr(f_pending), f'<{self.cls.__name__} pending>')
356 f_pending.cancel()
357
358 f_cancelled = self._new_future(loop=self.loop)
359 f_cancelled.cancel()
360 self.assertEqual(repr(f_cancelled), f'<{self.cls.__name__} cancelled>')
361
362 f_result = self._new_future(loop=self.loop)
363 f_result.set_result(4)
364 self.assertEqual(
365 repr(f_result), f'<{self.cls.__name__} finished result=4>')
366 self.assertEqual(f_result.result(), 4)
367
368 exc = RuntimeError()
369 f_exception = self._new_future(loop=self.loop)
370 f_exception.set_exception(exc)
371 self.assertEqual(
372 repr(f_exception),
373 f'<{self.cls.__name__} finished exception=RuntimeError()>')
374 self.assertIs(f_exception.exception(), exc)
375
376 def func_repr(func):
377 filename, lineno = test_utils.get_function_source(func)
378 text = '%s() at %s:%s' % (func.__qualname__, filename, lineno)
379 return re.escape(text)
380
381 f_one_callbacks = self._new_future(loop=self.loop)
382 f_one_callbacks.add_done_callback(_fakefunc)
383 fake_repr = func_repr(_fakefunc)
384 self.assertRegex(
385 repr(f_one_callbacks),
386 r'<' + self.cls.__name__ + r' pending cb=\[%s\]>' % fake_repr)
387 f_one_callbacks.cancel()
388 self.assertEqual(repr(f_one_callbacks),
389 f'<{self.cls.__name__} cancelled>')
390
391 f_two_callbacks = self._new_future(loop=self.loop)
392 f_two_callbacks.add_done_callback(first_cb)
393 f_two_callbacks.add_done_callback(last_cb)
394 first_repr = func_repr(first_cb)
395 last_repr = func_repr(last_cb)
396 self.assertRegex(repr(f_two_callbacks),
397 r'<' + self.cls.__name__ + r' pending cb=\[%s, %s\]>'
398 % (first_repr, last_repr))
399
400 f_many_callbacks = self._new_future(loop=self.loop)
401 f_many_callbacks.add_done_callback(first_cb)

Callers

nothing calls this directly

Calls 11

_new_futureMethod · 0.95
assertRegexMethod · 0.80
set_debugMethod · 0.45
assertEqualMethod · 0.45
cancelMethod · 0.45
set_resultMethod · 0.45
resultMethod · 0.45
set_exceptionMethod · 0.45
assertIsMethod · 0.45
exceptionMethod · 0.45
add_done_callbackMethod · 0.45

Tested by

no test coverage detected