@@ -21,6 +21,18 @@ class CommandSetBase(cmd2.CommandSet):
21
21
22
22
@cmd2 .with_default_category ('Fruits' )
23
23
class CommandSetA (CommandSetBase ):
24
+ def on_register (self , cmd ) -> None :
25
+ super ().on_register (cmd )
26
+ print ("in on_register now" )
27
+
28
+ def on_registered (self ) -> None :
29
+ super ().on_registered ()
30
+ print ("in on_registered now" )
31
+
32
+ def on_unregister (self ) -> None :
33
+ print ("in on_unregister now" )
34
+ super ().on_unregister ()
35
+
24
36
def do_apple (self , statement : cmd2 .Statement ):
25
37
self ._cmd .poutput ('Apple!' )
26
38
@@ -158,7 +170,7 @@ def test_custom_construct_commandsets():
158
170
assert command_set_2 not in matches
159
171
160
172
161
- def test_load_commands (command_sets_manual ):
173
+ def test_load_commands (command_sets_manual , capsys ):
162
174
163
175
# now install a command set and verify the commands are now present
164
176
cmd_set = CommandSetA ()
@@ -171,6 +183,11 @@ def test_load_commands(command_sets_manual):
171
183
assert command_sets_manual .find_commandsets (CommandSetA )[0 ] is cmd_set
172
184
assert command_sets_manual .find_commandset_for_command ('elderberry' ) is cmd_set
173
185
186
+ # Make sure registration callbacks ran
187
+ out , err = capsys .readouterr ()
188
+ assert "in on_register now" in out
189
+ assert "in on_registered now" in out
190
+
174
191
cmds_cats , cmds_doc , cmds_undoc , help_topics = command_sets_manual ._build_command_info ()
175
192
176
193
assert 'Alone' in cmds_cats
@@ -192,6 +209,10 @@ def test_load_commands(command_sets_manual):
192
209
assert 'Alone' not in cmds_cats
193
210
assert 'Fruits' not in cmds_cats
194
211
212
+ # Make sure unregistration callback ran
213
+ out , err = capsys .readouterr ()
214
+ assert "in on_unregister now" in out
215
+
195
216
# uninstall a second time and verify no errors happen
196
217
command_sets_manual .unregister_command_set (cmd_set )
197
218
0 commit comments