mirror of
https://github.com/jazzband/contextlib2.git
synced 2026-05-28 08:18:17 +00:00
Properly wrap callbacks in ContextStack.register() and actually assert something in TestContextStack.test_register()
This commit is contained in:
parent
57bc54d8e4
commit
7f99236d3b
3 changed files with 7 additions and 0 deletions
1
NEWS.rst
1
NEWS.rst
|
|
@ -5,6 +5,7 @@ Release History
|
||||||
0.3 (2012-01-XX)
|
0.3 (2012-01-XX)
|
||||||
~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
* Wrapped callbacks now use functools.wraps to aid in introspection
|
||||||
* Moved version number to a VERSION.txt file (read by both docs and setup.py)
|
* Moved version number to a VERSION.txt file (read by both docs and setup.py)
|
||||||
* Added NEWS.rst (and incorporated into documentation)
|
* Added NEWS.rst (and incorporated into documentation)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,7 @@ class ContextStack(object):
|
||||||
|
|
||||||
Cannot suppress exceptions.
|
Cannot suppress exceptions.
|
||||||
"""
|
"""
|
||||||
|
@wraps(callback)
|
||||||
def _wrapper(exc_type, exc, tb):
|
def _wrapper(exc_type, exc, tb):
|
||||||
callback(*args, **kwds)
|
callback(*args, **kwds)
|
||||||
return self.register_exit(_wrapper)
|
return self.register_exit(_wrapper)
|
||||||
|
|
|
||||||
|
|
@ -317,6 +317,7 @@ class TestContextStack(unittest.TestCase):
|
||||||
]
|
]
|
||||||
result = []
|
result = []
|
||||||
def _exit(*args, **kwds):
|
def _exit(*args, **kwds):
|
||||||
|
"""Test metadata propagation"""
|
||||||
result.append((args, kwds))
|
result.append((args, kwds))
|
||||||
with ContextStack() as stack:
|
with ContextStack() as stack:
|
||||||
for args, kwds in reversed(expected):
|
for args, kwds in reversed(expected):
|
||||||
|
|
@ -328,6 +329,10 @@ class TestContextStack(unittest.TestCase):
|
||||||
stack.register(_exit, **kwds)
|
stack.register(_exit, **kwds)
|
||||||
else:
|
else:
|
||||||
stack.register(_exit)
|
stack.register(_exit)
|
||||||
|
for wrapper in stack._callbacks:
|
||||||
|
self.assertEqual(wrapper.__name__, _exit.__name__)
|
||||||
|
self.assertEqual(wrapper.__doc__, _exit.__doc__)
|
||||||
|
self.assertEqual(result, expected)
|
||||||
|
|
||||||
def test_register_exit(self):
|
def test_register_exit(self):
|
||||||
exc_raised = ZeroDivisionError
|
exc_raised = ZeroDivisionError
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue