Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions paths_cli/tests/wizard/test_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ def helper(result):
assert result == 'foo'
assert 'You said: helpme' in console.log_text

@pytest.mark.parametrize('autohelp', [True, False])
def test_ask_empty(self, autohelp):
# if the use response in an empty string, we should repeat the
# question (possible giving autohelp). This fixes a regression where
# an empty string would cause an uncaught exception.
console = MockConsole(['', 'foo'])
self.wizard.console = console
result = self.wizard.ask("question",
helper=lambda x: "say_help",
autohelp=autohelp)
assert result == "foo"
if autohelp:
assert "say_help" in self.wizard.console.log_text

def _generic_speak_test(self, func_name):
console = MockConsole()
self.wizard.console = console
Expand Down
5 changes: 5 additions & 0 deletions paths_cli/wizard/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ def ask(self, question, options=None, default=None, helper=None,
helper = Helper(helper)
result = self.console.input("🧙 " + question + " ")
self.console.print()
if result == "":
if not autohelp:
return
result = "?" # autohelp in this case

if helper and result[0] in ["?", "!"]:
self.say(helper(result))
return
Expand Down