mirror of
https://github.com/jazzband/contextlib2.git
synced 2026-03-16 21:50:24 +00:00
Fix test incompatibility with PyPy3
This commit is contained in:
parent
4b39470cbb
commit
032662d6e9
3 changed files with 13 additions and 7 deletions
|
|
@ -1,2 +1,2 @@
|
|||
include *.py *.txt *.rst *.md *.ini MANIFEST.in
|
||||
recursive-include test docs *.rst *.py make.bat Makefile
|
||||
recursive-include dev test docs *.rst *.py make.bat Makefile
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ from contextlib2 import * # Tests __all__
|
|||
from test import support
|
||||
from test.support import os_helper
|
||||
import weakref
|
||||
import gc
|
||||
|
||||
|
||||
class TestAbstractContextManager(unittest.TestCase):
|
||||
|
|
@ -228,6 +229,8 @@ def woohoo():
|
|||
def woohoo(a, b):
|
||||
a = weakref.ref(a)
|
||||
b = weakref.ref(b)
|
||||
# Allow test to work with a non-refcounted GC
|
||||
gc.collect(); gc.collect(); gc.collect()
|
||||
self.assertIsNone(a())
|
||||
self.assertIsNone(b())
|
||||
yield
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import asyncio
|
||||
from contextlib2 import (
|
||||
asynccontextmanager, AbstractAsyncContextManager,
|
||||
AsyncExitStack, nullcontext, aclosing)
|
||||
AsyncExitStack, nullcontext, aclosing, contextmanager)
|
||||
import functools
|
||||
from test import support
|
||||
import unittest
|
||||
|
|
@ -346,14 +346,17 @@ class AclosingTestCase(unittest.TestCase):
|
|||
async def test_aclosing_bpo41229(self):
|
||||
state = []
|
||||
|
||||
class Resource:
|
||||
def __del__(self):
|
||||
@contextmanager
|
||||
def sync_resource():
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
state.append(1)
|
||||
|
||||
async def agenfunc():
|
||||
r = Resource()
|
||||
yield -1
|
||||
yield -2
|
||||
with sync_resource():
|
||||
yield -1
|
||||
yield -2
|
||||
|
||||
x = agenfunc()
|
||||
self.assertEqual(state, [])
|
||||
|
|
|
|||
Loading…
Reference in a new issue