Skip to content

Commit 68bcd0a

Browse files
committed
Added unit tests
1 parent 49ab56a commit 68bcd0a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/test_cmd2.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,6 +1981,23 @@ def test_get_help_topics(base_app):
19811981
custom_help = base_app.get_help_topics()
19821982
assert len(custom_help) == 0
19831983

1984+
def test_get_help_topics_hidden():
1985+
# Verify get_help_topics() filters out hidden commands
1986+
class TestApp(cmd2.Cmd):
1987+
def __init__(self, *args, **kwargs):
1988+
super().__init__(*args, **kwargs)
1989+
1990+
def do_my_cmd(self, args):
1991+
pass
1992+
1993+
def help_my_cmd(self, args):
1994+
pass
1995+
1996+
app = TestApp()
1997+
assert 'my_cmd' in app.get_help_topics()
1998+
1999+
app.hidden_commands.append('my_cmd')
2000+
assert 'my_cmd' not in app.get_help_topics()
19842001

19852002
class ReplWithExitCode(cmd2.Cmd):
19862003
""" Example cmd2 application where we can specify an exit code when existing."""
@@ -2240,6 +2257,10 @@ def test_disable_and_enable_category(disable_commands_app):
22402257
assert 'has_helper_funcs' not in visible_commands
22412258
assert 'has_no_helper_funcs' not in visible_commands
22422259

2260+
# Make sure get_help_topics() filters out disabled commands
2261+
help_topics = disable_commands_app.get_help_topics()
2262+
assert 'has_helper_funcs' not in help_topics
2263+
22432264
##########################################################################
22442265
# Enable the category
22452266
##########################################################################
@@ -2281,6 +2302,10 @@ def test_disable_and_enable_category(disable_commands_app):
22812302
assert 'has_helper_funcs' in visible_commands
22822303
assert 'has_no_helper_funcs' in visible_commands
22832304

2305+
# Make sure get_help_topics() contains our help function
2306+
help_topics = disable_commands_app.get_help_topics()
2307+
assert 'has_helper_funcs' in help_topics
2308+
22842309
def test_enable_enabled_command(disable_commands_app):
22852310
# Test enabling a command that is not disabled
22862311
saved_len = len(disable_commands_app.disabled_commands)

0 commit comments

Comments
 (0)