mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-09 02:00:44 +08:00
a0d3cc45c6
* fix select * add changeset * add changeset * restore * refactor * add pytest * typo --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
20 lines
730 B
Python
20 lines
730 B
Python
import gradio as gr
|
|
from gradio.data_classes import PredictBody
|
|
from gradio.helpers import EventData
|
|
from gradio.route_utils import prepare_event_data
|
|
|
|
|
|
def test_prepare_event_data():
|
|
def on_select(evt: gr.SelectData):
|
|
return f"You selected {evt.value} at {evt.index} from {evt.target}"
|
|
|
|
with gr.Blocks() as demo:
|
|
textbox = gr.Textbox("Hello World!")
|
|
statement = gr.Textbox()
|
|
textbox.select(on_select, None, statement)
|
|
|
|
body = PredictBody(data=[], event_data={"value": "World", "index": [6, 11]})
|
|
event_data = prepare_event_data(demo, body, 0)
|
|
correct_event_data = EventData(textbox, {"value": "World", "index": [6, 11]})
|
|
assert vars(event_data) == vars(correct_event_data)
|