Skip to content

Commit 451515a

Browse files
committed
Merge branch 'master' into stephenfin/stop-using-argspec
2 parents 5758ba0 + 7f865b0 commit 451515a

12 files changed

+152
-126
lines changed

.travis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ matrix:
77
env: TOXENV=check
88
- python: '3.6'
99
env: TOXENV=docs
10-
- python: '2.6'
11-
env: TOXENV=py26-pytestrelease
1210
- python: '2.7'
1311
env: TOXENV=py27-pytestrelease
14-
- python: '3.3'
15-
env: TOXENV=py33-pytestrelease
1612
- python: '3.4'
1713
env: TOXENV=py34-pytestrelease
1814
- python: '3.5'

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
0.6.0
2+
-----
3+
4+
- Drop support for EOL Python 2.6 and 3.3 in PR `#103`_.
5+
6+
.. _#103: https://github.com/pytest-dev/pluggy/pull/103
7+
18
0.5.2
29
-----
310
- fix bug where ``firstresult`` wrappers were being sent an incorrectly configured

appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ environment:
33
# note: please use "tox --listenvs" to populate the build matrix below
44
- TOXENV: "check"
55
- TOXENV: "docs"
6-
- TOXENV: "py26-pytestrelease"
76
- TOXENV: "py27-pytestrelease"
87
- TOXENV: "py34-pytestrelease"
98
- TOXENV: "py35-pytestrelease"

pluggy/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ def __init__(self, project_name, implprefix=None):
212212
self._implprefix = implprefix
213213
self._inner_hookexec = lambda hook, methods, kwargs: \
214214
hook.multicall(
215-
methods, kwargs, specopts=hook.spec_opts, hook=hook
215+
methods, kwargs,
216+
firstresult=hook.spec_opts.get('firstresult'),
216217
)
217218

218219
def _hookexec(self, hook, methods, kwargs):
@@ -528,20 +529,22 @@ def __init__(self, trace):
528529

529530

530531
class _HookCaller(object):
531-
def __init__(self, name, hook_execute, specmodule_or_class=None, spec_opts=None):
532+
def __init__(self, name, hook_execute, specmodule_or_class=None,
533+
spec_opts=None):
532534
self.name = name
533535
self._wrappers = []
534536
self._nonwrappers = []
535537
self._hookexec = hook_execute
538+
self._specmodule_or_class = None
536539
self.argnames = None
537540
self.kwargnames = None
538541
self.multicall = _multicall
542+
self.spec_opts = spec_opts or {}
539543
if specmodule_or_class is not None:
540-
assert spec_opts is not None
541544
self.set_specification(specmodule_or_class, spec_opts)
542545

543546
def has_spec(self):
544-
return hasattr(self, "_specmodule_or_class")
547+
return self._specmodule_or_class is not None
545548

546549
def set_specification(self, specmodule_or_class, spec_opts):
547550
assert not self.has_spec()
@@ -550,7 +553,7 @@ def set_specification(self, specmodule_or_class, spec_opts):
550553
# get spec arg signature
551554
argnames, self.kwargnames = varnames(specfunc)
552555
self.argnames = ["__multicall__"] + list(argnames)
553-
self.spec_opts = spec_opts
556+
self.spec_opts.update(spec_opts)
554557
if spec_opts.get("historic"):
555558
self._call_history = []
556559

@@ -606,7 +609,7 @@ def __call__(self, *args, **kwargs):
606609
kwargs.keys())
607610
if notincall:
608611
warnings.warn(
609-
"Argument(s) {0} which are declared in the hookspec "
612+
"Argument(s) {} which are declared in the hookspec "
610613
"can not be found in this hook call"
611614
.format(tuple(notincall)),
612615
stacklevel=2,

pluggy/callers.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,16 @@ class _LegacyMultiCall(object):
105105
# so we can remove it soon, allowing to avoid the below recursion
106106
# in execute() and simplify/speed up the execute loop.
107107

108-
def __init__(self, hook_impls, kwargs, specopts={}, hook=None):
109-
self.hook = hook
108+
def __init__(self, hook_impls, kwargs, firstresult=False):
110109
self.hook_impls = hook_impls
111110
self.caller_kwargs = kwargs # come from _HookCaller.__call__()
112111
self.caller_kwargs["__multicall__"] = self
113-
self.specopts = hook.spec_opts if hook else specopts
112+
self.firstresult = firstresult
114113

115114
def execute(self):
116115
caller_kwargs = self.caller_kwargs
117116
self.results = results = []
118-
firstresult = self.specopts.get("firstresult")
117+
firstresult = self.firstresult
119118

120119
while self.hook_impls:
121120
hook_impl = self.hook_impls.pop()
@@ -144,21 +143,19 @@ def __repr__(self):
144143
return "<_MultiCall %s, kwargs=%r>" % (status, self.caller_kwargs)
145144

146145

147-
def _legacymulticall(hook_impls, caller_kwargs, specopts={}, hook=None):
146+
def _legacymulticall(hook_impls, caller_kwargs, firstresult=False):
148147
return _LegacyMultiCall(
149-
hook_impls, caller_kwargs, specopts=specopts, hook=hook).execute()
148+
hook_impls, caller_kwargs, firstresult=firstresult).execute()
150149

151150

152-
def _multicall(hook_impls, caller_kwargs, specopts={}, hook=None):
151+
def _multicall(hook_impls, caller_kwargs, firstresult=False):
153152
"""Execute a call into multiple python functions/methods and return the
154153
result(s).
155154
156155
``caller_kwargs`` comes from _HookCaller.__call__().
157156
"""
158157
__tracebackhide__ = True
159-
specopts = hook.spec_opts if hook else specopts
160158
results = []
161-
firstresult = specopts.get("firstresult")
162159
excinfo = None
163160
try: # run impl and wrapper setup functions in a loop
164161
teardowns = []

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
'Programming Language :: Python :: Implementation :: CPython',
1515
'Programming Language :: Python :: Implementation :: PyPy'] + [
1616
('Programming Language :: Python :: %s' % x) for x in
17-
'2 2.6 2.7 3 3.3 3.4 3.5 3.6'.split()]
17+
'2 2.7 3 3.4 3.5 3.6'.split()]
1818

1919
with open('README.rst') as fd:
2020
long_description = fd.read()

testing/test_hookrelay.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def hello(self, arg):
2424

2525
plugin = Plugin()
2626
pm.register(plugin)
27-
l = hook.hello(arg=3)
28-
assert l == [4]
27+
out = hook.hello(arg=3)
28+
assert out == [4]
2929
assert not hasattr(hook, 'world')
3030
pm.unregister(plugin)
3131
assert hook.hello(arg=3) == []

testing/test_method_ordering.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -215,42 +215,42 @@ def test_load_setuptools_not_installed(monkeypatch, pm):
215215

216216

217217
def test_add_tracefuncs(he_pm):
218-
l = []
218+
out = []
219219

220220
class api1(object):
221221
@hookimpl
222222
def he_method1(self):
223-
l.append("he_method1-api1")
223+
out.append("he_method1-api1")
224224

225225
class api2(object):
226226
@hookimpl
227227
def he_method1(self):
228-
l.append("he_method1-api2")
228+
out.append("he_method1-api2")
229229

230230
he_pm.register(api1())
231231
he_pm.register(api2())
232232

233233
def before(hook_name, hook_impls, kwargs):
234-
l.append((hook_name, list(hook_impls), kwargs))
234+
out.append((hook_name, list(hook_impls), kwargs))
235235

236236
def after(outcome, hook_name, hook_impls, kwargs):
237-
l.append((outcome, hook_name, list(hook_impls), kwargs))
237+
out.append((outcome, hook_name, list(hook_impls), kwargs))
238238

239239
undo = he_pm.add_hookcall_monitoring(before, after)
240240

241241
he_pm.hook.he_method1(arg=1)
242-
assert len(l) == 4
243-
assert l[0][0] == "he_method1"
244-
assert len(l[0][1]) == 2
245-
assert isinstance(l[0][2], dict)
246-
assert l[1] == "he_method1-api2"
247-
assert l[2] == "he_method1-api1"
248-
assert len(l[3]) == 4
249-
assert l[3][1] == l[0][0]
242+
assert len(out) == 4
243+
assert out[0][0] == "he_method1"
244+
assert len(out[0][1]) == 2
245+
assert isinstance(out[0][2], dict)
246+
assert out[1] == "he_method1-api2"
247+
assert out[2] == "he_method1-api1"
248+
assert len(out[3]) == 4
249+
assert out[3][1] == out[0][0]
250250

251251
undo()
252252
he_pm.hook.he_method1(arg=1)
253-
assert len(l) == 4 + 2
253+
assert len(out) == 4 + 2
254254

255255

256256
def test_hook_tracing(he_pm):
@@ -268,18 +268,18 @@ def he_method1(self):
268268
raise ValueError()
269269

270270
he_pm.register(api1())
271-
l = []
272-
he_pm.trace.root.setwriter(l.append)
271+
out = []
272+
he_pm.trace.root.setwriter(out.append)
273273
undo = he_pm.enable_tracing()
274274
try:
275275
indent = he_pm.trace.root.indent
276276
he_pm.hook.he_method1(arg=1)
277277
assert indent == he_pm.trace.root.indent
278-
assert len(l) == 2
279-
assert 'he_method1' in l[0]
280-
assert 'finish' in l[1]
278+
assert len(out) == 2
279+
assert 'he_method1' in out[0]
280+
assert 'finish' in out[1]
281281

282-
l[:] = []
282+
out[:] = []
283283
he_pm.register(api2())
284284

285285
with pytest.raises(ValueError):
@@ -290,15 +290,17 @@ def he_method1(self):
290290
undo()
291291

292292

293-
def test_prefix_hookimpl():
293+
@pytest.mark.parametrize('include_hookspec', [True, False])
294+
def test_prefix_hookimpl(include_hookspec):
294295
pm = PluginManager(hookspec.project_name, "hello_")
295296

296-
class HookSpec(object):
297-
@hookspec
298-
def hello_myhook(self, arg1):
299-
""" add to arg1 """
297+
if include_hookspec:
298+
class HookSpec(object):
299+
@hookspec
300+
def hello_myhook(self, arg1):
301+
""" add to arg1 """
300302

301-
pm.add_hookspecs(HookSpec)
303+
pm.add_hookspecs(HookSpec)
302304

303305
class Plugin(object):
304306
def hello_myhook(self, arg1):

testing/test_multicall.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111

1212
def test_uses_copy_of_methods():
13-
l = [lambda: 42]
14-
mc = _LegacyMultiCall(l, {})
13+
out = [lambda: 42]
14+
mc = _LegacyMultiCall(out, {})
1515
repr(mc)
16-
l[:] = []
16+
out[:] = []
1717
res = mc.execute()
1818
return res == 42
1919

@@ -26,7 +26,7 @@ def MC(methods, kwargs, firstresult=False):
2626
hookfuncs.append(f)
2727
if '__multicall__' in f.argnames:
2828
caller = _legacymulticall
29-
return caller(hookfuncs, kwargs, specopts={"firstresult": firstresult})
29+
return caller(hookfuncs, kwargs, firstresult=firstresult)
3030

3131

3232
def test_call_passing():
@@ -105,53 +105,53 @@ def m1():
105105
def m2():
106106
return None
107107

108-
res = MC([m1, m2], {}, {"firstresult": True})
108+
res = MC([m1, m2], {}, firstresult=True)
109109
assert res == 1
110110
res = MC([m1, m2], {}, {})
111111
assert res == [1]
112112

113113

114114
def test_hookwrapper():
115-
l = []
115+
out = []
116116

117117
@hookimpl(hookwrapper=True)
118118
def m1():
119-
l.append("m1 init")
119+
out.append("m1 init")
120120
yield None
121-
l.append("m1 finish")
121+
out.append("m1 finish")
122122

123123
@hookimpl
124124
def m2():
125-
l.append("m2")
125+
out.append("m2")
126126
return 2
127127

128128
res = MC([m2, m1], {})
129129
assert res == [2]
130-
assert l == ["m1 init", "m2", "m1 finish"]
131-
l[:] = []
132-
res = MC([m2, m1], {}, {"firstresult": True})
130+
assert out == ["m1 init", "m2", "m1 finish"]
131+
out[:] = []
132+
res = MC([m2, m1], {}, firstresult=True)
133133
assert res == 2
134-
assert l == ["m1 init", "m2", "m1 finish"]
134+
assert out == ["m1 init", "m2", "m1 finish"]
135135

136136

137137
def test_hookwrapper_order():
138-
l = []
138+
out = []
139139

140140
@hookimpl(hookwrapper=True)
141141
def m1():
142-
l.append("m1 init")
142+
out.append("m1 init")
143143
yield 1
144-
l.append("m1 finish")
144+
out.append("m1 finish")
145145

146146
@hookimpl(hookwrapper=True)
147147
def m2():
148-
l.append("m2 init")
148+
out.append("m2 init")
149149
yield 2
150-
l.append("m2 finish")
150+
out.append("m2 finish")
151151

152152
res = MC([m2, m1], {})
153153
assert res == []
154-
assert l == ["m1 init", "m2 init", "m2 finish", "m1 finish"]
154+
assert out == ["m1 init", "m2 init", "m2 finish", "m1 finish"]
155155

156156

157157
def test_hookwrapper_not_yield():
@@ -177,18 +177,18 @@ def m1():
177177

178178
@pytest.mark.parametrize("exc", [ValueError, SystemExit])
179179
def test_hookwrapper_exception(exc):
180-
l = []
180+
out = []
181181

182182
@hookimpl(hookwrapper=True)
183183
def m1():
184-
l.append("m1 init")
184+
out.append("m1 init")
185185
yield None
186-
l.append("m1 finish")
186+
out.append("m1 finish")
187187

188188
@hookimpl
189189
def m2():
190190
raise exc
191191

192192
with pytest.raises(exc):
193193
MC([m2, m1], {})
194-
assert l == ["m1 init", "m1 finish"]
194+
assert out == ["m1 init", "m1 finish"]

0 commit comments

Comments
 (0)