Skip to content

Commit 894368a

Browse files
committed
Renamed test_escaping_prompt to test_visible_prompt and fixed it to work with prompt-toolkit
1 parent 92faadc commit 894368a

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

tests/test_cmd2.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,31 +1232,19 @@ def test_default_to_shell(base_app, monkeypatch) -> None:
12321232
assert m.called
12331233

12341234

1235-
@pytest.mark.skip('TODO: Replace escapte prompt stuff with prompt-toolkit equivalents')
1236-
def test_escaping_prompt() -> None:
1237-
# This prompt has nothing which needs to be escaped
1238-
_prompt = '(Cmd) '
1239-
# TODO(T or K): Replace below with prompt-toolkit equivalent # noqa: FIX002, TD003
1240-
# assert rl_escape_prompt(prompt) == prompt # noqa: ERA001
1241-
1242-
# This prompt has color which needs to be escaped
1243-
_prompt = stylize('InColor', style=Color.CYAN)
1244-
1245-
_escape_start = "\x01"
1246-
_escape_end = "\x02"
1247-
1248-
# TODO(T or K): Replace below with prompt-toolkit equivalent # noqa: FIX002, TD003
1249-
# escaped_prompt = rl_escape_prompt(prompt) # noqa: ERA001
1250-
# if sys.platform.startswith('win'):
1251-
# # PyReadline on Windows doesn't need to escape invisible characters
1252-
# assert escaped_prompt == prompt # noqa: ERA001
1253-
# else: # noqa: ERA001
1254-
# cyan = "\x1b[36m" # noqa: ERA001
1255-
# reset_all = "\x1b[0m" # noqa: ERA001
1256-
# assert escaped_prompt.startswith(escape_start + cyan + escape_end) # noqa: ERA001
1257-
# assert escaped_prompt.endswith(escape_start + reset_all + escape_end) # noqa: ERA001
1258-
1259-
# assert rl_unescape_prompt(escaped_prompt) == prompt # noqa: ERA001
1235+
def test_visible_prompt() -> None:
1236+
app = cmd2.Cmd()
1237+
1238+
# This prompt has nothing which needs to be stripped
1239+
app.prompt = '(Cmd) '
1240+
assert app.visible_prompt == app.prompt
1241+
assert su.str_width(app.prompt) == len(app.prompt)
1242+
1243+
# This prompt has color which needs to be stripped
1244+
color_prompt = stylize('InColor', style=Color.CYAN) + '> '
1245+
app.prompt = color_prompt
1246+
assert app.visible_prompt == 'InColor> '
1247+
assert su.str_width(app.prompt) == len('InColor> ')
12601248

12611249

12621250
class HelpApp(cmd2.Cmd):

0 commit comments

Comments
 (0)