Skip to content

Commit 27acf59

Browse files
committed
Handling case when completekey is empty string.
1 parent 0a26a51 commit 27acf59

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

cmd2/cmd2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def __init__(
370370
) -> None:
371371
"""Easy but powerful framework for writing line-oriented command interpreters, extends Python's cmd package.
372372
373-
:param completekey: name of a completion key, default to Tab
373+
:param completekey: name of a completion key, default to 'tab'. (If None or an empty string, 'tab' is used)
374374
:param stdin: alternate input file object, if not specified, sys.stdin is used
375375
:param stdout: alternate output file object, if not specified, sys.stdout is used
376376
:param allow_cli_args: if ``True``, then [cmd2.Cmd.__init__][] will process command
@@ -430,7 +430,7 @@ def __init__(
430430
self.prompt: str = self.DEFAULT_PROMPT
431431
self.intro = intro
432432

433-
if completekey is None:
433+
if not completekey:
434434
completekey = self.DEFAULT_COMPLETEKEY
435435

436436
# What to use for standard input

tests/test_cmd2.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4164,6 +4164,17 @@ def test_custom_completekey_ctrl_k():
41644164
assert found, "Could not find binding for 'c-k' (Keys.ControlK) in session key bindings"
41654165

41664166

4167+
def test_completekey_empty_string() -> None:
4168+
# Test that an empty string for completekey defaults to DEFAULT_COMPLETEKEY
4169+
with mock.patch('cmd2.Cmd._create_main_session', autospec=True) as create_session_mock:
4170+
create_session_mock.return_value = mock.MagicMock(spec=PromptSession)
4171+
app = cmd2.Cmd(completekey='')
4172+
4173+
# Verify it was called with DEFAULT_COMPLETEKEY
4174+
# auto_suggest is the second arg and it defaults to True
4175+
create_session_mock.assert_called_once_with(app, True, app.DEFAULT_COMPLETEKEY)
4176+
4177+
41674178
def test_create_main_session_exception(monkeypatch):
41684179

41694180
# Mock PromptSession to raise ValueError on first call, then succeed

0 commit comments

Comments
 (0)