summaryrefslogtreecommitdiff
path: root/tests/test_cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-01 12:44:48 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-01 12:44:48 -0400
commit8cf5bdfe32e3d513a80bcc0f1c302e2a21b9ae60 (patch)
treefc9545ebb5b4f645dcafb0016f957ccc83da98d4 /tests/test_cmd2.py
parentb4ce107a16fdf0111a6f024a8d3a99132a858623 (diff)
downloadcmd2-git-8cf5bdfe32e3d513a80bcc0f1c302e2a21b9ae60.tar.gz
Added some unit tests related to help and the help menu
Also: - When running cmd2.py as main, enable use of IPython if present to aid with debugging and troubleshooting - Deleted a unit test which wasn't reliable
Diffstat (limited to 'tests/test_cmd2.py')
-rw-r--r--tests/test_cmd2.py63
1 files changed, 57 insertions, 6 deletions
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