diff options
author | Johannes Gijsbers <jlg@dds.nl> | 2004-08-18 12:40:31 (GMT) |
---|---|---|
committer | Johannes Gijsbers <jlg@dds.nl> | 2004-08-18 12:40:31 (GMT) |
commit | c473c99d16b43544fffcc8a33fbc61c95061b088 (patch) | |
tree | 9f05451df2a4531c993aca7e793a2ff9f2338a32 /Lib/test/test_inspect.py | |
parent | 318a12eb0129bd75754cb3cc68076cc3b737074f (diff) | |
download | cpython-c473c99d16b43544fffcc8a33fbc61c95061b088.zip cpython-c473c99d16b43544fffcc8a33fbc61c95061b088.tar.gz cpython-c473c99d16b43544fffcc8a33fbc61c95061b088.tar.bz2 |
Patch #1006219: let inspect.getsource show '@' decorators and add tests for
this (which are rather ugly, but it'll have to do until test_inspect gets a
major overhaul and a conversion to unittest). Thanks Simon Percivall!
Diffstat (limited to 'Lib/test/test_inspect.py')
-rw-r--r-- | Lib/test/test_inspect.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 2f79fc3..e3bf73a 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -202,6 +202,47 @@ for fname in files_to_clean_up: except: pass +# Test for decorators as well. + +source = r""" +def wrap(foo=None): + def wrapper(func): + return func + return wrapper + +def replace(func): + def insteadfunc(): + print 'hello' + return insteadfunc + +# two decorators, one with argument +@wrap() +@wrap(wrap) +def wrapped(): + pass + +@replace +def gone(): + pass""" + +file = open(TESTFN + "2", "w") +file.write(source) +file.close() +files_to_clean_up = [TESTFN + "2", TESTFN + '2c', TESTFN + '2o'] + +mod2 = imp.load_source("testmod3", TESTFN + "2") + +test(inspect.getsource(mod2.wrapped) == sourcerange(13, 16), + "inspect.getsource(mod.wrapped)") +test(inspect.getsource(mod2.gone) == sourcerange(8, 9), + "inspect.getsource(mod.gone)") + +for fname in files_to_clean_up: + try: + os.unlink(fname) + except: + pass + # Test classic-class method resolution order. class A: pass class B(A): pass |