gradio

Форк
0
/
test_buttons.py 
55 строк · 1.9 Кб
1
from unittest.mock import patch
2

3
import pytest
4

5
import gradio as gr
6

7

8
class TestClearButton:
9
    def test_clear_event_setup_correctly(self):
10
        with gr.Blocks() as demo:
11
            chatbot = gr.Chatbot([["Hello", "How are you?"]])
12
            with gr.Row():
13
                textbox = gr.Textbox(scale=3, interactive=True)
14
                gr.ClearButton([textbox, chatbot], scale=1)
15

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]
20

21
    def test_clear_event_setup_correctly_with_state(self):
22
        with gr.Blocks() as demo:
23
            chatbot = gr.Chatbot([["Hello", "How are you?"]])
24
            state = gr.State("")
25
            gr.ClearButton([state, chatbot], scale=1)
26

27
        clear_event_trigger_state = demo.dependencies.pop()
28
        assert clear_event_trigger_state["backend_fn"]
29

30

31
class TestOAuthButtons:
32
    @pytest.mark.flaky
33
    def test_login_button_warns_when_not_on_spaces(self):
34
        with pytest.warns(UserWarning):
35
            with gr.Blocks():
36
                gr.LoginButton()
37

38
    @pytest.mark.flaky
39
    def test_logout_button_warns_when_not_on_spaces(self):
40
        with pytest.warns(UserWarning):
41
            with gr.Blocks():
42
                gr.LogoutButton()
43

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()
49

50
        login_event = demo.dependencies[0]
51
        assert login_event["targets"][0][1] == "click"
52
        assert not login_event["backend_fn"]  # No Python code
53
        assert login_event["js"]  # But JS code instead
54
        assert login_event["inputs"] == [button._id]
55
        assert login_event["outputs"] == []
56

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.