Issue #11647: allow contextmanager objects to be used as decorators as described in the docs. Initial patch by Ysj Ray.

This commit is contained in:
Nick Coghlan 2011-05-05 23:49:25 +10:00
parent f77b74dd1b
commit 0ded3e307b
6 changed files with 50 additions and 10 deletions

View file

@ -14,8 +14,8 @@ from test.support import run_unittest
class MockContextManager(_GeneratorContextManager):
def __init__(self, gen):
_GeneratorContextManager.__init__(self, gen)
def __init__(self, func, *args, **kwds):
super().__init__(func, *args, **kwds)
self.enter_called = False
self.exit_called = False
self.exit_args = None
@ -33,7 +33,7 @@ class MockContextManager(_GeneratorContextManager):
def mock_contextmanager(func):
def helper(*args, **kwds):
return MockContextManager(func(*args, **kwds))
return MockContextManager(func, *args, **kwds)
return helper