@@ -1,5 +1,5 @@
11importasyncio
2-fromcontextlibimportasynccontextmanager, AbstractAsyncContextManager, AsyncExitStack
2+fromcontextlibimportaclosing, asynccontextmanager, AbstractAsyncContextManager, AsyncExitStack
33importfunctools
44fromtestimportsupport
55importunittest
@@ -279,6 +279,63 @@ async def woohoo(self, func, args, kwds):
279279self.assertEqual(target, (11, 22, 33, 44))
280280281281282+classAclosingTestCase(unittest.TestCase):
[email protected]_docstrings
285+deftest_instance_docs(self):
286+cm_docstring=aclosing.__doc__
287+obj=aclosing(None)
288+self.assertEqual(obj.__doc__, cm_docstring)
289+290+@_async_test
291+asyncdeftest_aclosing(self):
292+state= []
293+classC:
294+asyncdefaclose(self):
295+state.append(1)
296+x=C()
297+self.assertEqual(state, [])
298+asyncwithaclosing(x) asy:
299+self.assertEqual(x, y)
300+self.assertEqual(state, [1])
301+302+@_async_test
303+asyncdeftest_aclosing_error(self):
304+state= []
305+classC:
306+asyncdefaclose(self):
307+state.append(1)
308+x=C()
309+self.assertEqual(state, [])
310+withself.assertRaises(ZeroDivisionError):
311+asyncwithaclosing(x) asy:
312+self.assertEqual(x, y)
313+1/0
314+self.assertEqual(state, [1])
315+316+@_async_test
317+asyncdeftest_aclosing_bpo41229(self):
318+state= []
319+320+classResource:
321+def__del__(self):
322+state.append(1)
323+324+asyncdefagenfunc():
325+r=Resource()
326+yield-1
327+yield-2
328+329+x=agenfunc()
330+self.assertEqual(state, [])
331+withself.assertRaises(ZeroDivisionError):
332+asyncwithaclosing(x) asy:
333+self.assertEqual(x, y)
334+self.assertEqual(-1, awaitx.__anext__())
335+1/0
336+self.assertEqual(state, [1])
337+338+282339classTestAsyncExitStack(TestBaseExitStack, unittest.TestCase):
283340classSyncAsyncExitStack(AsyncExitStack):
284341@staticmethod