Skip to content

Commit 32a0287

Browse files
author
Tyler Goodlet
committed
Move hookcaller test to appropriate module
1 parent 4c19d8d commit 32a0287

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

testing/test_hookcaller.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
@pytest.fixture
1313
def hc(pm):
14+
1415
class Hooks(object):
1516
@hookspec
1617
def he_method1(self, arg):
1718
pass
19+
1820
pm.add_hookspecs(Hooks)
1921
return pm.hook.he_method1
2022

@@ -179,6 +181,33 @@ def he_myhook1(arg1):
179181
assert not hasattr(he_myhook1, name)
180182

181183

184+
def test_happypath(pm):
185+
"""Verify hook caller instances are registered by name onto the relay
186+
and can be likewise unregistered."""
187+
class Api(object):
188+
@hookspec
189+
def hello(self, arg):
190+
"api hook 1"
191+
192+
pm.add_hookspecs(Api)
193+
hook = pm.hook
194+
assert hasattr(hook, 'hello')
195+
assert repr(hook.hello).find("hello") != -1
196+
197+
class Plugin(object):
198+
@hookimpl
199+
def hello(self, arg):
200+
return arg + 1
201+
202+
plugin = Plugin()
203+
pm.register(plugin)
204+
out = hook.hello(arg=3)
205+
assert out == [4]
206+
assert not hasattr(hook, 'world')
207+
pm.unregister(plugin)
208+
assert hook.hello(arg=3) == []
209+
210+
182211
def test_load_setuptools_instantiation(monkeypatch, pm):
183212
pkg_resources = pytest.importorskip("pkg_resources")
184213

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)