This repository has been archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accept capitals in ask_yes_no (#443)
Co-authored-by: PCSwingle <[email protected]>
- Loading branch information
1 parent
69410b9
commit a955b58
Showing
3 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import asyncio | ||
|
||
import pytest | ||
|
||
from mentat.session_context import SESSION_CONTEXT | ||
from mentat.session_input import ask_yes_no | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_ask_yes_no(): | ||
stream = SESSION_CONTEXT.get().stream | ||
stream.start() | ||
|
||
# Test when user inputs invalid confirmation | ||
ask_yes_no_task = asyncio.create_task(ask_yes_no(default_yes=False)) | ||
input_request_message = await stream.recv("input_request") | ||
stream.send("yes", channel=f"input_request:{input_request_message.id}") | ||
input_request_message = await stream.recv("input_request") | ||
stream.send("y", channel=f"input_request:{input_request_message.id}") | ||
assert await ask_yes_no_task is True | ||
|
||
# Test when user inputs 'Y' | ||
ask_yes_no_task = asyncio.create_task(ask_yes_no(default_yes=False)) | ||
input_request_message = await stream.recv("input_request") | ||
stream.send("Y", channel=f"input_request:{input_request_message.id}") | ||
assert await ask_yes_no_task is True | ||
|
||
# Test when user inputs nothing | ||
ask_yes_no_task = asyncio.create_task(ask_yes_no(default_yes=False)) | ||
input_request_message = await stream.recv("input_request") | ||
stream.send("", channel=f"input_request:{input_request_message.id}") | ||
assert await ask_yes_no_task is False | ||
|
||
# Test when user inputs 'n' | ||
ask_yes_no_task = asyncio.create_task(ask_yes_no(default_yes=False)) | ||
input_request_message = await stream.recv("input_request") | ||
stream.send("n", channel=f"input_request:{input_request_message.id}") | ||
assert await ask_yes_no_task is False | ||
|
||
# Test default true | ||
ask_yes_no_task = asyncio.create_task(ask_yes_no(default_yes=True)) | ||
input_request_message = await stream.recv("input_request") | ||
stream.send("", channel=f"input_request:{input_request_message.id}") | ||
assert await ask_yes_no_task is True | ||
|
||
stream.stop() |