1
1
import pytest
2
2
3
- from pluggy import _MultiCall , HookImpl , HookCallError , _LegacyMultiCall
3
+ from pluggy import _multicall , _legacymulticall , HookImpl , HookCallError
4
+ from pluggy .callers import _LegacyMultiCall
4
5
from pluggy import HookspecMarker , HookimplMarker
5
6
6
7
10
11
11
12
def test_uses_copy_of_methods ():
12
13
l = [lambda : 42 ]
13
- mc = _MultiCall (l , {})
14
+ mc = _LegacyMultiCall (l , {})
14
15
repr (mc )
15
16
l [:] = []
16
17
res = mc .execute ()
17
18
return res == 42
18
19
19
20
20
21
def MC (methods , kwargs , firstresult = False ):
21
- caller = _MultiCall
22
+ caller = _multicall
22
23
hookfuncs = []
23
24
for method in methods :
24
25
f = HookImpl (None , "<temp>" , method , method .example_impl )
25
26
hookfuncs .append (f )
26
27
if '__multicall__' in f .argnames :
27
- caller = _LegacyMultiCall
28
- return caller (hookfuncs , kwargs , {"firstresult" : firstresult })
28
+ caller = _legacymulticall
29
+ return caller (hookfuncs , kwargs , specopts = {"firstresult" : firstresult })
29
30
30
31
31
32
def test_call_passing ():
@@ -45,9 +46,7 @@ def m(self, __multicall__, x):
45
46
46
47
p1 = P1 ()
47
48
p2 = P2 ()
48
- multicall = MC ([p1 .m , p2 .m ], {"x" : 23 })
49
- assert "23" in repr (multicall )
50
- reslist = multicall .execute ()
49
+ reslist = MC ([p1 .m , p2 .m ], {"x" : 23 })
51
50
assert len (reslist ) == 2
52
51
# ensure reversed order
53
52
assert reslist == [23 , 17 ]
@@ -63,28 +62,24 @@ class A(object):
63
62
def f (self , x , y ):
64
63
return x + y
65
64
66
- multicall = MC ([f , A ().f ], dict (x = 23 , y = 24 ))
67
- assert "'x': 23" in repr (multicall )
68
- assert "'y': 24" in repr (multicall )
69
- reslist = multicall .execute ()
65
+ reslist = MC ([f , A ().f ], dict (x = 23 , y = 24 ))
70
66
assert reslist == [24 + 23 , 24 ]
71
- assert "2 results" in repr (multicall )
72
67
73
68
74
69
def test_keyword_args_with_defaultargs ():
75
70
@hookimpl
76
71
def f (x , z = 1 ):
77
72
return x + z
78
- reslist = MC ([f ], dict (x = 23 , y = 24 )). execute ()
73
+ reslist = MC ([f ], dict (x = 23 , y = 24 ))
79
74
assert reslist == [24 ]
80
75
81
76
82
77
def test_tags_call_error ():
83
78
@hookimpl
84
79
def f (x ):
85
80
return x
86
- multicall = MC ([ f ], {})
87
- pytest . raises ( HookCallError , multicall . execute )
81
+ with pytest . raises ( HookCallError ):
82
+ MC ([ f ], {} )
88
83
89
84
90
85
def test_call_subexecute ():
@@ -97,8 +92,7 @@ def m(__multicall__):
97
92
def n ():
98
93
return 1
99
94
100
- call = MC ([n , m ], {}, firstresult = True )
101
- res = call .execute ()
95
+ res = MC ([n , m ], {}, firstresult = True )
102
96
assert res == 2
103
97
104
98
@@ -111,9 +105,9 @@ def m1():
111
105
def m2 ():
112
106
return None
113
107
114
- res = MC ([m1 , m2 ], {}, {"firstresult" : True }). execute ()
108
+ res = MC ([m1 , m2 ], {}, {"firstresult" : True })
115
109
assert res == 1
116
- res = MC ([m1 , m2 ], {}, {}). execute ()
110
+ res = MC ([m1 , m2 ], {}, {})
117
111
assert res == [1 ]
118
112
119
113
@@ -131,11 +125,11 @@ def m2():
131
125
l .append ("m2" )
132
126
return 2
133
127
134
- res = MC ([m2 , m1 ], {}). execute ()
128
+ res = MC ([m2 , m1 ], {})
135
129
assert res == [2 ]
136
130
assert l == ["m1 init" , "m2" , "m1 finish" ]
137
131
l [:] = []
138
- res = MC ([m2 , m1 ], {}, {"firstresult" : True }). execute ()
132
+ res = MC ([m2 , m1 ], {}, {"firstresult" : True })
139
133
assert res == 2
140
134
assert l == ["m1 init" , "m2" , "m1 finish" ]
141
135
@@ -155,7 +149,7 @@ def m2():
155
149
yield 2
156
150
l .append ("m2 finish" )
157
151
158
- res = MC ([m2 , m1 ], {}). execute ()
152
+ res = MC ([m2 , m1 ], {})
159
153
assert res == []
160
154
assert l == ["m1 init" , "m2 init" , "m2 finish" , "m1 finish" ]
161
155
@@ -165,9 +159,8 @@ def test_hookwrapper_not_yield():
165
159
def m1 ():
166
160
pass
167
161
168
- mc = MC ([m1 ], {})
169
162
with pytest .raises (TypeError ):
170
- mc . execute ( )
163
+ MC ([ m1 ], {} )
171
164
172
165
173
166
def test_hookwrapper_too_many_yield ():
@@ -176,9 +169,8 @@ def m1():
176
169
yield 1
177
170
yield 2
178
171
179
- mc = MC ([m1 ], {})
180
172
with pytest .raises (RuntimeError ) as ex :
181
- mc . execute ( )
173
+ MC ([ m1 ], {} )
182
174
assert "m1" in str (ex .value )
183
175
assert (__file__ + ':' ) in str (ex .value )
184
176
@@ -198,5 +190,5 @@ def m2():
198
190
raise exc
199
191
200
192
with pytest .raises (exc ):
201
- MC ([m2 , m1 ], {}). execute ()
193
+ MC ([m2 , m1 ], {})
202
194
assert l == ["m1 init" , "m1 finish" ]
0 commit comments