summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-01 13:12:35 -0400
committerGitHub <noreply@github.com>2017-07-01 13:12:35 -0400
commit0b6edb1663ba20ece40f8dbba491f6e28911b183 (patch)
treefc9545ebb5b4f645dcafb0016f957ccc83da98d4
parentb4ce107a16fdf0111a6f024a8d3a99132a858623 (diff)
parent8cf5bdfe32e3d513a80bcc0f1c302e2a21b9ae60 (diff)
downloadcmd2-git-0b6edb1663ba20ece40f8dbba491f6e28911b183.tar.gz
Merge pull request #158 from python-cmd2/help_tests
Added some unit tests related to help and the help menu
-rwxr-xr-xcmd2.py4
-rw-r--r--tests/test_cmd2.py63
2 files changed, 60 insertions, 7 deletions
diff --git a/cmd2.py b/cmd2.py
index dfb81b04..89ed1b7c 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -2294,5 +2294,7 @@ class CmdResult(namedtuple_with_two_defaults('CmdResult', ['out', 'err', 'war'])
if __name__ == '__main__':
# If run as the main application, simply start a bare-bones cmd2 application with only built-in functionality.
- app = Cmd()
+ # But enable the ipy command if IPython is installed, which supports advanced interactive debugging of your app,
+ # via introspection on self.
+ app = Cmd(use_ipython=True)
app.cmdloop()
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 6ea7fa08..f719721a 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -727,12 +727,6 @@ def shell_app():
app.stdout = StdOut()
return app
-@pytest.mark.skipif(sys.platform == 'win32' or sys.platform.startswith('linux'),
- reason="Unit test passes when I run it, but fails on TravisCI and AppVeyor machines")
-def test_default_to_shell_found(shell_app):
- out = run_cmd(shell_app, 'echo Hello')
- assert out == []
-
def test_default_to_shell_unknown(shell_app):
unknown_command = 'zyxcw23'
out = run_cmd(shell_app, unknown_command)
@@ -762,3 +756,60 @@ def test_ansi_prompt_escaped():
assert prompt != color_prompt
assert readline_safe_prompt.startswith(readline_hack_start + app._colorcodes[color][True] + readline_hack_end)
assert readline_safe_prompt.endswith(readline_hack_start + app._colorcodes[color][False] + readline_hack_end)
+
+
+class HelpApp(cmd2.Cmd):
+ """Class for testing custom help_* methods which override docstring help."""
+ def __init__(self, *args, **kwargs):
+ # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x
+ cmd2.Cmd.__init__(self, *args, **kwargs)
+
+ def do_squat(self, arg):
+ """This docstring help will never be shown because the help_squat method overrides it."""
+ pass
+
+ def help_squat(self):
+ self.stdout.write('This command does diddly squat...\n')
+
+ def do_pause(self, arg):
+ """This overrides the pause command and does nothing."""
+ pass
+
+ # This command will be in the "undocumented" section of the help menu
+ def do_undoc(self, arg):
+ pass
+
+@pytest.fixture
+def help_app():
+ app = HelpApp()
+ app.stdout = StdOut()
+ return app
+
+def test_custom_command_help(help_app):
+ out = run_cmd(help_app, 'help squat')
+ expected = normalize('This command does diddly squat...')
+ assert out == expected
+
+def test_custom_help_menu(help_app):
+ out = run_cmd(help_app, 'help')
+ expected = normalize("""
+Documented commands (type help <topic>):
+========================================
+_relative_load edit history pause pyscript run set shortcuts squat
+cmdenvironment help load py quit save shell show
+
+Undocumented commands:
+======================
+undoc
+""")
+ assert out == expected
+
+def test_help_undocumented(help_app):
+ out = run_cmd(help_app, 'help undoc')
+ expected = normalize('*** No help on undoc')
+ assert out == expected
+
+def test_help_overridden_method(help_app):
+ out = run_cmd(help_app, 'help pause')
+ expected = normalize('This overrides the pause command and does nothing.')
+ assert out == expected