Skip to content

Commit 0226749

Browse files
authored
Merge pull request #65 from dwhswenson/wizard-empty-input
Wizard: Fix uncaught exception if user input is empty
2 parents 34cf3a0 + d11d7bc commit 0226749

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

paths_cli/tests/wizard/test_wizard.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ def helper(result):
8181
assert result == 'foo'
8282
assert 'You said: helpme' in console.log_text
8383

84+
@pytest.mark.parametrize('autohelp', [True, False])
85+
def test_ask_empty(self, autohelp):
86+
# if the use response in an empty string, we should repeat the
87+
# question (possible giving autohelp). This fixes a regression where
88+
# an empty string would cause an uncaught exception.
89+
console = MockConsole(['', 'foo'])
90+
self.wizard.console = console
91+
result = self.wizard.ask("question",
92+
helper=lambda x: "say_help",
93+
autohelp=autohelp)
94+
assert result == "foo"
95+
if autohelp:
96+
assert "say_help" in self.wizard.console.log_text
97+
8498
def _generic_speak_test(self, func_name):
8599
console = MockConsole()
86100
self.wizard.console = console

paths_cli/wizard/wizard.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ def ask(self, question, options=None, default=None, helper=None,
8585
helper = Helper(helper)
8686
result = self.console.input("🧙 " + question + " ")
8787
self.console.print()
88+
if result == "":
89+
if not autohelp:
90+
return
91+
result = "?" # autohelp in this case
92+
8893
if helper and result[0] in ["?", "!"]:
8994
self.say(helper(result))
9095
return

0 commit comments

Comments
 (0)