##// END OF EJS Templates
Add extra tests for checking decorator logic with __wrapped__.
Fernando Perez -
Show More
@@ -25,8 +25,10 b' from IPython.core.magic import (Magics, magics_class, line_magic,'
25 cell_magic, line_cell_magic,
25 cell_magic, line_cell_magic,
26 register_line_magic, register_cell_magic,
26 register_line_magic, register_cell_magic,
27 register_line_cell_magic)
27 register_line_cell_magic)
28 from IPython.external.decorator import decorator
28 from IPython.utils import py3compat
29 from IPython.utils import py3compat
29
30
31
30 #-----------------------------------------------------------------------------
32 #-----------------------------------------------------------------------------
31 # Globals and constants
33 # Globals and constants
32 #-----------------------------------------------------------------------------
34 #-----------------------------------------------------------------------------
@@ -42,7 +44,7 b' ip = get_ipython()'
42 # defined, if any code is inserted above, the following line will need to be
44 # defined, if any code is inserted above, the following line will need to be
43 # updated. Do NOT insert any whitespace between the next line and the function
45 # updated. Do NOT insert any whitespace between the next line and the function
44 # definition below.
46 # definition below.
45 THIS_LINE_NUMBER = 45 # Put here the actual number of this line
47 THIS_LINE_NUMBER = 47 # Put here the actual number of this line
46 def test_find_source_lines():
48 def test_find_source_lines():
47 nt.assert_equal(oinspect.find_source_lines(test_find_source_lines),
49 nt.assert_equal(oinspect.find_source_lines(test_find_source_lines),
48 THIS_LINE_NUMBER+1)
50 THIS_LINE_NUMBER+1)
@@ -53,6 +55,38 b' def test_find_file():'
53 os.path.abspath(__file__))
55 os.path.abspath(__file__))
54
56
55
57
58 def test_find_file_decorated1():
59
60 @decorator
61 def noop1(f):
62 def wrapper():
63 return f(*a, **kw)
64 return wrapper
65
66 @noop1
67 def f(x):
68 "My docstring"
69
70 nt.assert_equal(oinspect.find_file(f),
71 os.path.abspath(__file__))
72 nt.assert_equal(f.__doc__, "My docstring")
73
74
75 def test_find_file_decorated2():
76
77 @decorator
78 def noop2(f, *a, **kw):
79 return f(*a, **kw)
80
81 @noop2
82 def f(x):
83 "My docstring 2"
84
85 nt.assert_equal(oinspect.find_file(f),
86 os.path.abspath(__file__))
87 nt.assert_equal(f.__doc__, "My docstring 2")
88
89
56 def test_find_file_magic():
90 def test_find_file_magic():
57 run = ip.find_line_magic('run')
91 run = ip.find_line_magic('run')
58 nt.assert_not_equal(oinspect.find_file(run), None)
92 nt.assert_not_equal(oinspect.find_file(run), None)
General Comments 0
You need to be logged in to leave comments. Login now