Properly wrap callbacks in ContextStack.register() and actually assert something in TestContextStack.test_register()

This commit is contained in:
Nick Coghlan 2012-01-03 14:00:18 +10:00
parent 57bc54d8e4
commit 7f99236d3b
3 changed files with 7 additions and 0 deletions

View file

@ -5,6 +5,7 @@ Release History
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)
* Added NEWS.rst (and incorporated into documentation)

View file

@ -170,6 +170,7 @@ class ContextStack(object):
Cannot suppress exceptions.
"""
@wraps(callback)
def _wrapper(exc_type, exc, tb):
callback(*args, **kwds)
return self.register_exit(_wrapper)

View file

@ -317,6 +317,7 @@ class TestContextStack(unittest.TestCase):
]
result = []
def _exit(*args, **kwds):
"""Test metadata propagation"""
result.append((args, kwds))
with ContextStack() as stack:
for args, kwds in reversed(expected):
@ -328,6 +329,10 @@ class TestContextStack(unittest.TestCase):
stack.register(_exit, **kwds)
else:
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):
exc_raised = ZeroDivisionError