-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
149 additions
and
3 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
24 changes: 24 additions & 0 deletions
24
tests/playwright/shiny/components/chat/stream-result/app.py
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,24 @@ | ||
import asyncio | ||
|
||
from shiny.express import render, ui | ||
|
||
chat = ui.Chat("chat") | ||
|
||
chat.ui() | ||
chat.update_user_input(value="Press Enter to start the stream") | ||
|
||
|
||
async def stream_generator(): | ||
for i in range(10): | ||
await asyncio.sleep(0.25) | ||
yield f"Message {i} \n\n" | ||
|
||
|
||
@chat.on_user_submit | ||
async def _(message: str): | ||
await chat.append_message_stream(stream_generator()) | ||
|
||
|
||
@render.code | ||
async def stream_result_ui(): | ||
return chat.get_latest_stream_result() |
37 changes: 37 additions & 0 deletions
37
tests/playwright/shiny/components/chat/stream-result/test_chat_stream_result.py
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,37 @@ | ||
import re | ||
|
||
from playwright.sync_api import Page, expect | ||
from utils.deploy_utils import skip_on_webkit | ||
|
||
from shiny.playwright import controller | ||
from shiny.run import ShinyAppProc | ||
|
||
|
||
@skip_on_webkit | ||
def test_validate_chat_stream_result(page: Page, local_app: ShinyAppProc) -> None: | ||
page.goto(local_app.url) | ||
|
||
chat = controller.Chat(page, "chat") | ||
stream_result_ui = controller.OutputCode(page, "stream_result_ui") | ||
|
||
expect(chat.loc).to_be_visible(timeout=10 * 1000) | ||
|
||
chat.send_user_input() | ||
|
||
messages = [ | ||
"Message 0", | ||
"Message 1", | ||
"Message 2", | ||
"Message 3", | ||
"Message 4", | ||
"Message 5", | ||
"Message 6", | ||
"Message 7", | ||
"Message 8", | ||
"Message 9", | ||
] | ||
# Allow for any whitespace between messages | ||
chat.expect_messages(re.compile(r"\s*".join(messages)), timeout=30 * 1000) | ||
|
||
# Verify that the stream result is as expected | ||
stream_result_ui.expect.to_contain_text("Message 9") |