gradio/test/test_route_utils.py
Abubakar Abid a0d3cc45c6
Fix gr.SelectData so that the target attribute is correctly attached, and the filedata is included in the data attribute with gr.Gallery (#5798)
* fix select

* add changeset

* add changeset

* restore

* refactor

* add pytest

* typo

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
2023-10-05 12:53:52 -07:00

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)