Skip to content

Commit 76232fa

Browse files
authored
Merge pull request #153 from tgoodlet/tests_reorg
Tests reorg
2 parents cab120f + dbda5aa commit 76232fa

File tree

5 files changed

+228
-210
lines changed

5 files changed

+228
-210
lines changed

testing/test_deprecations.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
Deprecation warnings testing roundup.
3+
"""
4+
import pytest
5+
from pluggy.callers import _Result
6+
from pluggy import PluginManager, HookimplMarker, HookspecMarker
7+
8+
hookspec = HookspecMarker("example")
9+
hookimpl = HookimplMarker("example")
10+
11+
12+
def test_result_deprecated():
13+
r = _Result(10, None)
14+
with pytest.deprecated_call():
15+
assert r.result == 10
16+
17+
18+
def test_implprefix_deprecated():
19+
with pytest.deprecated_call():
20+
pm = PluginManager('blah', implprefix='blah_')
21+
22+
class Plugin:
23+
def blah_myhook(self, arg1):
24+
return arg1
25+
26+
with pytest.deprecated_call():
27+
pm.register(Plugin())
28+
29+
30+
def test_callhistoric_proc_deprecated(pm):
31+
"""``proc`` kwarg to `PluginMananger.call_historic()` is now officially
32+
deprecated.
33+
"""
34+
class P1(object):
35+
@hookspec(historic=True)
36+
@hookimpl
37+
def m(self, x):
38+
pass
39+
40+
p1 = P1()
41+
pm.add_hookspecs(p1)
42+
pm.register(p1)
43+
with pytest.deprecated_call():
44+
pm.hook.m.call_historic(kwargs=dict(x=10), proc=lambda res: res)
45+
46+
47+
def test_multicall_deprecated(pm):
48+
class P1(object):
49+
@hookimpl
50+
def m(self, __multicall__, x):
51+
pass
52+
53+
pytest.deprecated_call(pm.register, P1())

testing/test_details.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import warnings
22
import pytest
33
from pluggy import PluginManager, HookimplMarker, HookspecMarker
4-
from pluggy.callers import _Result
54

65
hookspec = HookspecMarker("example")
76
hookimpl = HookimplMarker("example")
@@ -118,21 +117,3 @@ def myhook(self, arg1):
118117
warning = warns[-1]
119118
assert issubclass(warning.category, Warning)
120119
assert "Argument(s) ('arg2',)" in str(warning.message)
121-
122-
123-
def test_result_deprecated():
124-
r = _Result(10, None)
125-
with pytest.deprecated_call():
126-
assert r.result == 10
127-
128-
129-
def test_implprefix_deprecated():
130-
with pytest.deprecated_call():
131-
pm = PluginManager('blah', implprefix='blah_')
132-
133-
class Plugin:
134-
def blah_myhook(self, arg1):
135-
return arg1
136-
137-
with pytest.deprecated_call():
138-
pm.register(Plugin())

testing/test_method_ordering.py renamed to testing/test_hookcaller.py

Lines changed: 25 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import pytest
2-
import sys
3-
import types
42

5-
from pluggy import PluginManager, HookimplMarker, HookspecMarker
3+
from pluggy import HookimplMarker, HookspecMarker
64
from pluggy.hooks import HookImpl
75

86
hookspec = HookspecMarker("example")
@@ -11,10 +9,12 @@
119

1210
@pytest.fixture
1311
def hc(pm):
12+
1413
class Hooks(object):
1514
@hookspec
1615
def he_method1(self, arg):
1716
pass
17+
1818
pm.add_hookspecs(Hooks)
1919
return pm.hook.he_method1
2020

@@ -179,146 +179,28 @@ def he_myhook1(arg1):
179179
assert not hasattr(he_myhook1, name)
180180

181181

182-
def test_load_setuptools_instantiation(monkeypatch, pm):
183-
pkg_resources = pytest.importorskip("pkg_resources")
184-
185-
def my_iter(name):
186-
assert name == "hello"
187-
188-
class EntryPoint(object):
189-
name = "myname"
190-
dist = None
191-
192-
def load(self):
193-
class PseudoPlugin(object):
194-
x = 42
195-
return PseudoPlugin()
196-
197-
return iter([EntryPoint()])
198-
199-
monkeypatch.setattr(pkg_resources, 'iter_entry_points', my_iter)
200-
num = pm.load_setuptools_entrypoints("hello")
201-
assert num == 1
202-
plugin = pm.get_plugin("myname")
203-
assert plugin.x == 42
204-
assert pm.list_plugin_distinfo() == [(plugin, None)]
205-
206-
207-
def test_load_setuptools_not_installed(monkeypatch, pm):
208-
monkeypatch.setitem(
209-
sys.modules, 'pkg_resources',
210-
types.ModuleType("pkg_resources"))
211-
212-
with pytest.raises(ImportError):
213-
pm.load_setuptools_entrypoints("qwe")
214-
215-
216-
def test_add_tracefuncs(he_pm):
217-
out = []
218-
219-
class api1(object):
220-
@hookimpl
221-
def he_method1(self):
222-
out.append("he_method1-api1")
223-
224-
class api2(object):
225-
@hookimpl
226-
def he_method1(self):
227-
out.append("he_method1-api2")
228-
229-
he_pm.register(api1())
230-
he_pm.register(api2())
231-
232-
def before(hook_name, hook_impls, kwargs):
233-
out.append((hook_name, list(hook_impls), kwargs))
234-
235-
def after(outcome, hook_name, hook_impls, kwargs):
236-
out.append((outcome, hook_name, list(hook_impls), kwargs))
237-
238-
undo = he_pm.add_hookcall_monitoring(before, after)
239-
240-
he_pm.hook.he_method1(arg=1)
241-
assert len(out) == 4
242-
assert out[0][0] == "he_method1"
243-
assert len(out[0][1]) == 2
244-
assert isinstance(out[0][2], dict)
245-
assert out[1] == "he_method1-api2"
246-
assert out[2] == "he_method1-api1"
247-
assert len(out[3]) == 4
248-
assert out[3][1] == out[0][0]
249-
250-
undo()
251-
he_pm.hook.he_method1(arg=1)
252-
assert len(out) == 4 + 2
253-
254-
255-
def test_hook_tracing(he_pm):
256-
saveindent = []
257-
258-
class api1(object):
259-
@hookimpl
260-
def he_method1(self):
261-
saveindent.append(he_pm.trace.root.indent)
182+
def test_hookrelay_registry(pm):
183+
"""Verify hook caller instances are registered by name onto the relay
184+
and can be likewise unregistered."""
185+
class Api(object):
186+
@hookspec
187+
def hello(self, arg):
188+
"api hook 1"
262189

263-
class api2(object):
264-
@hookimpl
265-
def he_method1(self):
266-
saveindent.append(he_pm.trace.root.indent)
267-
raise ValueError()
268-
269-
he_pm.register(api1())
270-
out = []
271-
he_pm.trace.root.setwriter(out.append)
272-
undo = he_pm.enable_tracing()
273-
try:
274-
indent = he_pm.trace.root.indent
275-
he_pm.hook.he_method1(arg=1)
276-
assert indent == he_pm.trace.root.indent
277-
assert len(out) == 2
278-
assert 'he_method1' in out[0]
279-
assert 'finish' in out[1]
280-
281-
out[:] = []
282-
he_pm.register(api2())
283-
284-
with pytest.raises(ValueError):
285-
he_pm.hook.he_method1(arg=1)
286-
assert he_pm.trace.root.indent == indent
287-
assert saveindent[0] > indent
288-
finally:
289-
undo()
290-
291-
292-
@pytest.mark.parametrize('include_hookspec', [True, False])
293-
def test_prefix_hookimpl(include_hookspec):
294-
with pytest.deprecated_call():
295-
pm = PluginManager(hookspec.project_name, "hello_")
296-
297-
if include_hookspec:
298-
class HookSpec(object):
299-
@hookspec
300-
def hello_myhook(self, arg1):
301-
""" add to arg1 """
302-
303-
pm.add_hookspecs(HookSpec)
190+
pm.add_hookspecs(Api)
191+
hook = pm.hook
192+
assert hasattr(hook, 'hello')
193+
assert repr(hook.hello).find("hello") != -1
304194

305195
class Plugin(object):
306-
def hello_myhook(self, arg1):
307-
return arg1 + 1
308-
309-
with pytest.deprecated_call():
310-
pm.register(Plugin())
311-
pm.register(Plugin())
312-
results = pm.hook.hello_myhook(arg1=17)
313-
assert results == [18, 18]
314-
315-
316-
def test_prefix_hookimpl_dontmatch_module():
317-
with pytest.deprecated_call():
318-
pm = PluginManager(hookspec.project_name, "hello_")
319-
320-
class BadPlugin(object):
321-
hello_module = __import__('email')
322-
323-
pm.register(BadPlugin())
324-
pm.check_pending()
196+
@hookimpl
197+
def hello(self, arg):
198+
return arg + 1
199+
200+
plugin = Plugin()
201+
pm.register(plugin)
202+
out = hook.hello(arg=3)
203+
assert out == [4]
204+
assert not hasattr(hook, 'world')
205+
pm.unregister(plugin)
206+
assert hook.hello(arg=3) == []

testing/test_hookrelay.py renamed to testing/test_invocations.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,6 @@
66
hookimpl = HookimplMarker("example")
77

88

9-
def test_happypath(pm):
10-
class Api(object):
11-
@hookspec
12-
def hello(self, arg):
13-
"api hook 1"
14-
15-
pm.add_hookspecs(Api)
16-
hook = pm.hook
17-
assert hasattr(hook, 'hello')
18-
assert repr(hook.hello).find("hello") != -1
19-
20-
class Plugin(object):
21-
@hookimpl
22-
def hello(self, arg):
23-
return arg + 1
24-
25-
plugin = Plugin()
26-
pm.register(plugin)
27-
out = hook.hello(arg=3)
28-
assert out == [4]
29-
assert not hasattr(hook, 'world')
30-
pm.unregister(plugin)
31-
assert hook.hello(arg=3) == []
32-
33-
349
def test_argmismatch(pm):
3510
class Api(object):
3611
@hookspec

0 commit comments

Comments
 (0)