1
from unittest.mock import patch
9
def test_clear_event_setup_correctly(self):
10
with gr.Blocks() as demo:
11
chatbot = gr.Chatbot([["Hello", "How are you?"]])
13
textbox = gr.Textbox(scale=3, interactive=True)
14
gr.ClearButton([textbox, chatbot], scale=1)
16
clear_event_trigger = demo.dependencies.pop()
17
assert not clear_event_trigger["backend_fn"]
18
assert clear_event_trigger["js"]
19
assert clear_event_trigger["outputs"] == [textbox._id, chatbot._id]
21
def test_clear_event_setup_correctly_with_state(self):
22
with gr.Blocks() as demo:
23
chatbot = gr.Chatbot([["Hello", "How are you?"]])
25
gr.ClearButton([state, chatbot], scale=1)
27
clear_event_trigger_state = demo.dependencies.pop()
28
assert clear_event_trigger_state["backend_fn"]
31
class TestOAuthButtons:
33
def test_login_button_warns_when_not_on_spaces(self):
34
with pytest.warns(UserWarning):
39
def test_logout_button_warns_when_not_on_spaces(self):
40
with pytest.warns(UserWarning):
44
@patch("gradio.oauth.get_space", lambda: "fake_space")
45
@patch("gradio.oauth._add_oauth_routes")
46
def test_login_button_setup_correctly(self, mock_add_oauth_routes):
47
with gr.Blocks() as demo:
48
button = gr.LoginButton()
50
login_event = demo.dependencies[0]
51
assert login_event["targets"][0][1] == "click"
52
assert not login_event["backend_fn"]
53
assert login_event["js"]
54
assert login_event["inputs"] == [button._id]
55
assert login_event["outputs"] == []