Skip to content

Commit 4eb0119

Browse files
add tests
1 parent ffa9ec9 commit 4eb0119

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Lib/test/test_asyncio/test_futures.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,10 @@ def test_future_cancelled_exception_refcycles(self):
750750
self.assertIsNotNone(exc)
751751
self.assertListEqual(gc.get_referrers(exc), [])
752752

753+
def test_future_disallow_multiple_initialization(self):
754+
f = self._new_future(loop=self.loop)
755+
with self.assertRaises(RuntimeError, msg="is already initialized"):
756+
f.__init__(loop=self.loop)
753757

754758
@unittest.skipUnless(hasattr(futures, '_CFuture'),
755759
'requires the C _asyncio module')

Lib/test/test_asyncio/test_tasks.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,6 +2776,18 @@ def test_get_context(self):
27762776
finally:
27772777
loop.close()
27782778

2779+
def test_task_disallow_multiple_initialization(self):
2780+
async def foo():
2781+
pass
2782+
2783+
coro = foo()
2784+
self.addCleanup(coro.close)
2785+
task = self.new_task(self.loop, coro)
2786+
task._log_destroy_pending = False
2787+
2788+
with self.assertRaises(RuntimeError, msg="is already initialized"):
2789+
task.__init__(coro, loop=self.loop)
2790+
27792791
def add_subclass_tests(cls):
27802792
BaseTask = cls.Task
27812793
BaseFuture = cls.Future

0 commit comments

Comments
 (0)