summaryrefslogtreecommitdiff
path: root/tests/test_cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-09-10 15:06:50 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-09-10 16:24:16 -0400
commitf98ec0046ca966eef88e24b53caea7c3caee4e61 (patch)
treedb26311d860c681f38cd88c158cca0c6a385a693 /tests/test_cmd2.py
parentdf1fe25cbb8468ca18d5452174ff4a9a7aa33f11 (diff)
downloadcmd2-git-async_prompt.tar.gz
Updated async_alert() to account for self.prompt not matching Readline's current prompt.async_prompt
Diffstat (limited to 'tests/test_cmd2.py')
-rwxr-xr-xtests/test_cmd2.py37
1 files changed, 16 insertions, 21 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index e1a52bce..0f022849 100755
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -1020,37 +1020,32 @@ def test_default_to_shell(base_app, monkeypatch):
assert m.called
-def test_ansi_prompt_not_esacped(base_app):
+def test_escaping_prompt():
from cmd2.rl_utils import (
- rl_make_safe_prompt,
+ rl_escape_prompt,
+ rl_unescape_prompt,
)
+ # This prompt has nothing which needs to be escaped
prompt = '(Cmd) '
- assert rl_make_safe_prompt(prompt) == prompt
+ assert rl_escape_prompt(prompt) == prompt
-
-def test_ansi_prompt_escaped():
- from cmd2.rl_utils import (
- rl_make_safe_prompt,
- )
-
- app = cmd2.Cmd()
+ # This prompt has color which needs to be escaped
color = 'cyan'
- prompt = 'InColor'
- color_prompt = ansi.style(prompt, fg=color)
+ prompt = ansi.style('InColor', fg=color)
- readline_hack_start = "\x01"
- readline_hack_end = "\x02"
+ escape_start = "\x01"
+ escape_end = "\x02"
- readline_safe_prompt = rl_make_safe_prompt(color_prompt)
- assert prompt != color_prompt
+ escaped_prompt = rl_escape_prompt(prompt)
if sys.platform.startswith('win'):
- # PyReadline on Windows doesn't suffer from the GNU readline bug which requires the hack
- assert readline_safe_prompt.startswith(ansi.fg_lookup(color))
- assert readline_safe_prompt.endswith(ansi.FG_RESET)
+ # PyReadline on Windows doesn't need to escape invisible characters
+ assert escaped_prompt == prompt
else:
- assert readline_safe_prompt.startswith(readline_hack_start + ansi.fg_lookup(color) + readline_hack_end)
- assert readline_safe_prompt.endswith(readline_hack_start + ansi.FG_RESET + readline_hack_end)
+ assert escaped_prompt.startswith(escape_start + ansi.fg_lookup(color) + escape_end)
+ assert escaped_prompt.endswith(escape_start + ansi.FG_RESET + escape_end)
+
+ assert rl_unescape_prompt(escaped_prompt) == prompt
class HelpApp(cmd2.Cmd):