Changeset 111
- Timestamp:
- Sun Nov 12 20:36:26 2006
- Files:
-
- trunk/CHANGELOG (modified) (diff)
- trunk/unit_tests/test_tools.py (modified) (diff)
- trunk/unit_tests/test_twisted.py (added)
- trunk/nose/tools.py (modified) (diff)
- trunk/nose/twistedtools.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
trunk/CHANGELOG
r108 r111 1 0.9.2 2 3 - Added make_decorator function to nose.tools. Used to construct decorator 4 functions that are well-behaved and preserve as much of the original 5 function's metadata as possible. Thanks to Antoine Pitrou for the patch. 6 - Added nose.twistedtools, contributed by Antoine Pitrou. This module adds 7 @deferred decorator that makes it simple to write deferred tests, with or 8 without timeouts. 9 1 10 0.9.1 2 11 -
trunk/unit_tests/test_tools.py
r62 r111 77 77 else: 78 78 self.fail("Slow test did not throw TimeExpired") 79 80 def test_make_decorator(self): 81 def func(): 82 pass 83 func.setup = 'setup' 84 func.teardown = 'teardown' 85 86 def f1(): 87 pass 79 88 89 f2 = make_decorator(func)(f1) 90 91 assert f2.setup == 'setup' 92 assert f2.teardown == 'teardown' 93 80 94 if __name__ == '__main__': 81 95 unittest.main() -
trunk/nose/tools.py
r108 r111 22 22 """ 23 23 assert a == b, msg or "%r != %r" % (a, b) 24 24 25 def make_decorator(func): 26 """ 27 Wraps a test decorator so as to properly replicate metadata 28 of the decorated function, including nose's additional stuff 29 (namely, setup and teardown). 30 """ 31 def decorate(newfunc): 32 name = func.__name__ 33 try: 34 newfunc.__doc__ = func.__doc__ 35 newfunc.__module__ = func.__module__ 36 newfunc.__dict__ = func.__dict__ 37 newfunc.__name__ = name 38 except TypeError: 39 # can't set func name in 2.3 40 newfunc.compat_func_name = name 41 return newfunc 42 return decorate 43 25 44 def raises(*exceptions): 26 45 """Test must raise one of expected exceptions to pass. Example use:: … … 32 51 @raises(Exception): 33 52 def test_that_fails_by_passing(): 34 pass 35 """ 53 pass 54 """ 36 55 valid = ' or '.join([e.__name__ for e in exceptions]) 37 56 def decorate(func): … … 47 66 message = "%s() did not raise %s" % (name, valid) 48 67 raise AssertionError(message) 49 try: 50 newfunc.__doc__ = func.__doc__ 51 newfunc.__module__ = func.__module__ 52 newfunc.__name__ = name 53 except TypeError: 54 # can't set func name in 2.3 55 newfunc.compat_func_name = name 68 newfunc = make_decorator(func)(newfunc) 56 69 return newfunc 57 70 return decorate … … 71 84 if end - start > limit: 72 85 raise TimeExpired("Time limit (%s) exceeded" % limit) 73 try: 74 newfunc.__dict__.update(func.__dict__) 75 newfunc.__doc__ = func.__doc__ 76 newfunc.__module__ = func.__module__ 77 newfunc.__name__ = func.__name__ 78 except TypeError: 79 # can't set func name in 2.3 80 newfunc.compat_func_name = func.__name__ 86 newfunc = make_decorator(func)(newfunc) 81 87 return newfunc 82 88 return decorate … … 87 93 @with_setup(setup, teardown) 88 94 def test_something(): 89 # ... 95 # ... 89 95 """ 90 96 def decorate(func, setup=setup, teardown=teardown):
