-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
93 lines (77 loc) · 1.62 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import aspects
def t():
return 1
def test_global():
def inc(func):
def inner():
return func() + 1
return inner
if t() != 1:
return False
aspects.wrap_function(t, inc)
if t() != 2:
return False
return True
def test_class():
class C:
def t(self):
return 1
def inc(func):
def inner(self):
return func(self) + 1
return inner
c = C()
if c.t() != 1:
return False
aspects.wrap_function(C.t, inc)
c = C()
if c.t() != 2:
return False
return True
def test_instance():
class C:
def t(self):
return 1
def inc(func):
def inner(self):
return func(self) + 1
return inner
c = C()
if c.t() != 1:
return False
aspects.wrap_function(c.t, inc)
if c.t() != 2:
return False
c = C()
if c.t() != 1:
return False
return True
def test_nested():
@aspects.wrapper
def t():
return 1
def inc(func):
def inner():
return func() + 1
return inner
for i in range(1, 10):
if t() != i:
return False
aspects.wrap_function(t, inc)
return True
def test():
tests = [
test_global,
test_class,
test_instance,
test_nested,
]
successes = 0
for test in tests:
if test():
successes += 1
else:
print 'Failed ', test.__name__
print('%s succeeded out of %s' % (successes, len(tests)))
if __name__ == '__main__':
test()