summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-06-30 23:16:49 -0400
committerGitHub <noreply@github.com>2017-06-30 23:16:49 -0400
commitb4ce107a16fdf0111a6f024a8d3a99132a858623 (patch)
tree5582c91c88f99135eb1d282c99a0c2851cf78d57
parent081dc2585faef4303974f4dd6d1707b191e7b56b (diff)
parentdbc1640af4b38f56a23b8c39af3e159ef5a349e2 (diff)
downloadcmd2-git-b4ce107a16fdf0111a6f024a8d3a99132a858623.tar.gz
Merge pull request #157 from python-cmd2/default_to_shell
Fixed a bug where an extraneous line was printed at start sometimes
-rwxr-xr-xcmd2.py2
-rw-r--r--tests/test_cmd2.py50
2 files changed, 50 insertions, 2 deletions
diff --git a/cmd2.py b/cmd2.py
index e45970ce..dfb81b04 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -305,7 +305,7 @@ def options(option_list, arg_desc="arg"):
# Can we access the clipboard? Should always be true on Windows and Mac, but only sometimes on Linux
try:
- pyperclip.paste()
+ _ = pyperclip.paste()
except pyperclip.exceptions.PyperclipException:
can_clip = False
else:
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 791d6b59..6ea7fa08 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -699,7 +699,6 @@ class HookFailureApp(cmd2.Cmd):
"""Simulate precmd hook failure."""
return True, statement
-
@pytest.fixture
def hook_failure():
app = HookFailureApp()
@@ -714,3 +713,52 @@ def test_precmd_hook_success(base_app):
def test_precmd_hook_failure(hook_failure):
out = hook_failure.onecmd_plus_hooks('help')
assert out == True
+
+
+class ShellApp(cmd2.Cmd):
+ 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)
+ self.default_to_shell = True
+
+@pytest.fixture
+def shell_app():
+ app = ShellApp()
+ 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)
+ assert out == ["*** Unknown syntax: {}".format(unknown_command)]
+
+
+def test_ansi_prompt_not_esacped(base_app):
+ prompt = '(Cmd) '
+ assert base_app._surround_ansi_escapes(prompt) == prompt
+
+
+def test_ansi_prompt_escaped():
+ app = cmd2.Cmd()
+ color = 'cyan'
+ prompt = 'InColor'
+ color_prompt = app.colorize(prompt, color)
+
+ readline_hack_start = "\x01"
+ readline_hack_end = "\x02"
+
+ readline_safe_prompt = app._surround_ansi_escapes(color_prompt)
+ if sys.platform.startswith('win'):
+ # colorize() does nothing on Windows due to lack of ANSI color support
+ assert prompt == color_prompt
+ assert readline_safe_prompt == prompt
+ else:
+ 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)