streamlit
51 строка · 1.9 Кб
1# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from playwright.sync_api import Page, expect
16
17
18def test_shows_clear_cache_dialog_when_c_is_pressed(app: Page):
19app.keyboard.type("c")
20expect(app.get_by_role("dialog")).to_be_visible()
21expect(app.get_by_role("dialog")).to_have_text(
22"""
23Clear cachesAre you sure you want to clear the app's function caches?This will remove all cached entries from functions using @st.cache, @st.cache_data, and @st.cache_resource.CancelClear caches
24"""
25)
26
27
28modifier_keys = ["Control", "Meta"]
29
30
31def test_does_not_show_clear_cache_when_modifier_c_is_pressed(app: Page):
32for key in modifier_keys:
33app.keyboard.press(f"{key}+c")
34expect(app.get_by_test_id("stClearCacheDialog")).not_to_be_visible()
35
36
37def test_does_not_clear_cache_dialog_when_c_is_pressed_inside_text_input(app: Page):
38app.get_by_test_id("stTextInput").type("c")
39expect(app.get_by_test_id("stClearCacheDialog")).not_to_be_visible()
40
41
42def test_reruns_when_r_is_pressed(app: Page):
43app.keyboard.type("r")
44expect(app.get_by_test_id("stStatusWidget")).to_be_visible()
45
46
47def test_does_not_clear_cache_dialog_when_r_is_pressed_inside_text_input(
48app: Page,
49):
50app.get_by_test_id("stTextInput").press("r")
51expect(app.get_by_test_id("stStatusWidget")).not_to_be_visible()
52