Skip to content

Commit 240f6f9

Browse files
committed
装饰器测试
1 parent 30fb2cb commit 240f6f9

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

test/test_wrapper.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python
2+
# encoding: utf-8
3+
4+
"""
5+
@author: zhanghe
6+
@software: PyCharm
7+
@file: test_wrapper.py
8+
@time: 2017/8/5 下午7:57
9+
"""
10+
11+
12+
def w1(func):
13+
def wrapper(*args, **kw):
14+
back_func = func(*args, **kw)
15+
print func.__name__, 'w1'
16+
return back_func
17+
return wrapper
18+
19+
20+
def w2(func):
21+
def wrapper(*args, **kw):
22+
back_func = func(*args, **kw)
23+
print func.__name__, 'w2'
24+
return back_func
25+
return wrapper
26+
27+
28+
def w3(func):
29+
def wrapper(*args, **kw):
30+
back_func = func(*args, **kw)
31+
print func.__name__, 'w3'
32+
return back_func
33+
return wrapper
34+
35+
36+
@w1
37+
@w2
38+
@w3
39+
def func1():
40+
return 1
41+
42+
43+
@w1
44+
@w2
45+
@w3
46+
def func2():
47+
return 2
48+
49+
50+
@w1
51+
@w2
52+
@w3
53+
def func3():
54+
return 3
55+
56+
57+
@w1
58+
@w2
59+
@w3
60+
def fuck(func):
61+
def wrapper(*args, **kw):
62+
back_func = func(*args, **kw)
63+
print func.__name__, 'fuck'
64+
return back_func
65+
return wrapper
66+
67+
68+
@fuck
69+
def test():
70+
return 'test'
71+
72+
73+
if __name__ == '__main__':
74+
# print func1()
75+
# print func2()
76+
# print func3()
77+
# print test()
78+
pass

0 commit comments

Comments
 (0)