File tree Expand file tree Collapse file tree 2 files changed +29
-25
lines changed Expand file tree Collapse file tree 2 files changed +29
-25
lines changed Original file line number Diff line number Diff line change 11
11
12
12
@pytest .fixture
13
13
def hc (pm ):
14
+
14
15
class Hooks (object ):
15
16
@hookspec
16
17
def he_method1 (self , arg ):
17
18
pass
19
+
18
20
pm .add_hookspecs (Hooks )
19
21
return pm .hook .he_method1
20
22
@@ -179,6 +181,33 @@ def he_myhook1(arg1):
179
181
assert not hasattr (he_myhook1 , name )
180
182
181
183
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
+
182
211
def test_load_setuptools_instantiation (monkeypatch , pm ):
183
212
pkg_resources = pytest .importorskip ("pkg_resources" )
184
213
Original file line number Diff line number Diff line change 6
6
hookimpl = HookimplMarker ("example" )
7
7
8
8
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
-
34
9
def test_argmismatch (pm ):
35
10
class Api (object ):
36
11
@hookspec
You can’t perform that action at this time.
0 commit comments