(self)
| 411 | f'<{self.cls.__name__} cancelled>') |
| 412 | |
| 413 | def test_copy_state(self): |
| 414 | from asyncio.futures import _copy_future_state |
| 415 | |
| 416 | f = concurrent.futures.Future() |
| 417 | f.set_result(10) |
| 418 | |
| 419 | newf = self._new_future(loop=self.loop) |
| 420 | _copy_future_state(f, newf) |
| 421 | self.assertTrue(newf.done()) |
| 422 | self.assertEqual(newf.result(), 10) |
| 423 | |
| 424 | f_exception = concurrent.futures.Future() |
| 425 | f_exception.set_exception(RuntimeError()) |
| 426 | |
| 427 | newf_exception = self._new_future(loop=self.loop) |
| 428 | _copy_future_state(f_exception, newf_exception) |
| 429 | self.assertTrue(newf_exception.done()) |
| 430 | self.assertRaises(RuntimeError, newf_exception.result) |
| 431 | |
| 432 | f_cancelled = concurrent.futures.Future() |
| 433 | f_cancelled.cancel() |
| 434 | |
| 435 | newf_cancelled = self._new_future(loop=self.loop) |
| 436 | _copy_future_state(f_cancelled, newf_cancelled) |
| 437 | self.assertTrue(newf_cancelled.cancelled()) |
| 438 | |
| 439 | try: |
| 440 | raise concurrent.futures.InvalidStateError |
| 441 | except BaseException as e: |
| 442 | f_exc = e |
| 443 | |
| 444 | f_conexc = concurrent.futures.Future() |
| 445 | f_conexc.set_exception(f_exc) |
| 446 | |
| 447 | newf_conexc = self._new_future(loop=self.loop) |
| 448 | _copy_future_state(f_conexc, newf_conexc) |
| 449 | self.assertTrue(newf_conexc.done()) |
| 450 | try: |
| 451 | newf_conexc.result() |
| 452 | except BaseException as e: |
| 453 | newf_exc = e # assertRaises context manager drops the traceback |
| 454 | newf_tb = ''.join(traceback.format_tb(newf_exc.__traceback__)) |
| 455 | self.assertEqual(newf_tb.count('raise concurrent.futures.InvalidStateError'), 1) |
| 456 | |
| 457 | def test_copy_state_from_concurrent_futures(self): |
| 458 | """Test _copy_future_state from concurrent.futures.Future. |
nothing calls this directly
no test coverage detected