Skip to content

Commit 1ec0408

Browse files
author
Tyler Goodlet
committed
Update unit tests
1 parent fa9c5ae commit 1ec0408

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

testing/test_multicall.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

3-
from pluggy import _MultiCall, HookImpl, HookCallError, _LegacyMultiCall
3+
from pluggy import _multicall, _legacymulticall, HookImpl, HookCallError
4+
from pluggy.callers import _LegacyMultiCall
45
from pluggy import HookspecMarker, HookimplMarker
56

67

@@ -10,22 +11,22 @@
1011

1112
def test_uses_copy_of_methods():
1213
l = [lambda: 42]
13-
mc = _MultiCall(l, {})
14+
mc = _LegacyMultiCall(l, {})
1415
repr(mc)
1516
l[:] = []
1617
res = mc.execute()
1718
return res == 42
1819

1920

2021
def MC(methods, kwargs, firstresult=False):
21-
caller = _MultiCall
22+
caller = _multicall
2223
hookfuncs = []
2324
for method in methods:
2425
f = HookImpl(None, "<temp>", method, method.example_impl)
2526
hookfuncs.append(f)
2627
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})
2930

3031

3132
def test_call_passing():
@@ -45,9 +46,7 @@ def m(self, __multicall__, x):
4546

4647
p1 = P1()
4748
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})
5150
assert len(reslist) == 2
5251
# ensure reversed order
5352
assert reslist == [23, 17]
@@ -63,28 +62,24 @@ class A(object):
6362
def f(self, x, y):
6463
return x + y
6564

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))
7066
assert reslist == [24 + 23, 24]
71-
assert "2 results" in repr(multicall)
7267

7368

7469
def test_keyword_args_with_defaultargs():
7570
@hookimpl
7671
def f(x, z=1):
7772
return x + z
78-
reslist = MC([f], dict(x=23, y=24)).execute()
73+
reslist = MC([f], dict(x=23, y=24))
7974
assert reslist == [24]
8075

8176

8277
def test_tags_call_error():
8378
@hookimpl
8479
def f(x):
8580
return x
86-
multicall = MC([f], {})
87-
pytest.raises(HookCallError, multicall.execute)
81+
with pytest.raises(HookCallError):
82+
MC([f], {})
8883

8984

9085
def test_call_subexecute():
@@ -97,8 +92,7 @@ def m(__multicall__):
9792
def n():
9893
return 1
9994

100-
call = MC([n, m], {}, firstresult=True)
101-
res = call.execute()
95+
res = MC([n, m], {}, firstresult=True)
10296
assert res == 2
10397

10498

@@ -111,9 +105,9 @@ def m1():
111105
def m2():
112106
return None
113107

114-
res = MC([m1, m2], {}, {"firstresult": True}).execute()
108+
res = MC([m1, m2], {}, {"firstresult": True})
115109
assert res == 1
116-
res = MC([m1, m2], {}, {}).execute()
110+
res = MC([m1, m2], {}, {})
117111
assert res == [1]
118112

119113

@@ -131,11 +125,11 @@ def m2():
131125
l.append("m2")
132126
return 2
133127

134-
res = MC([m2, m1], {}).execute()
128+
res = MC([m2, m1], {})
135129
assert res == [2]
136130
assert l == ["m1 init", "m2", "m1 finish"]
137131
l[:] = []
138-
res = MC([m2, m1], {}, {"firstresult": True}).execute()
132+
res = MC([m2, m1], {}, {"firstresult": True})
139133
assert res == 2
140134
assert l == ["m1 init", "m2", "m1 finish"]
141135

@@ -155,7 +149,7 @@ def m2():
155149
yield 2
156150
l.append("m2 finish")
157151

158-
res = MC([m2, m1], {}).execute()
152+
res = MC([m2, m1], {})
159153
assert res == []
160154
assert l == ["m1 init", "m2 init", "m2 finish", "m1 finish"]
161155

@@ -165,9 +159,8 @@ def test_hookwrapper_not_yield():
165159
def m1():
166160
pass
167161

168-
mc = MC([m1], {})
169162
with pytest.raises(TypeError):
170-
mc.execute()
163+
MC([m1], {})
171164

172165

173166
def test_hookwrapper_too_many_yield():
@@ -176,9 +169,8 @@ def m1():
176169
yield 1
177170
yield 2
178171

179-
mc = MC([m1], {})
180172
with pytest.raises(RuntimeError) as ex:
181-
mc.execute()
173+
MC([m1], {})
182174
assert "m1" in str(ex.value)
183175
assert (__file__ + ':') in str(ex.value)
184176

@@ -198,5 +190,5 @@ def m2():
198190
raise exc
199191

200192
with pytest.raises(exc):
201-
MC([m2, m1], {}).execute()
193+
MC([m2, m1], {})
202194
assert l == ["m1 init", "m1 finish"]

0 commit comments

Comments
 (0)