streamlit

Форк
0
/
st_metric_test.py 
104 строки · 3.4 Кб
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
from playwright.sync_api import Page, expect
15

16
from e2e_playwright.conftest import ImageCompareFunction
17

18

19
def test_first_metric_in_first_row(app: Page):
20
    expect(app.get_by_test_id("stMetricLabel").nth(0)).to_have_text("User growth")
21
    expect(app.get_by_test_id("stMetricValue").nth(0)).to_have_text(" 123 ")
22
    expect(app.get_by_test_id("stMetricDelta").nth(0)).to_have_text(" 123 ")
23

24

25
def test_second_metric_in_first_row(app: Page):
26
    expect(app.get_by_test_id("stMetricLabel").nth(2)).to_have_text("S&P 500")
27
    expect(app.get_by_test_id("stMetricValue").nth(2)).to_have_text(" -4.56 ")
28
    expect(app.get_by_test_id("stMetricDelta").nth(2)).to_have_text(" -50 ")
29

30

31
def test_third_metric_in_first_row(app: Page):
32
    expect(app.get_by_test_id("stMetricLabel").nth(4)).to_have_text("Apples I've eaten")
33
    expect(app.get_by_test_id("stMetricValue").nth(4)).to_have_text(" 23k ")
34
    expect(app.get_by_test_id("stMetricDelta").nth(4)).to_have_text(" -20 ")
35

36

37
def test_green_up_arrow_render(themed_app: Page, assert_snapshot: ImageCompareFunction):
38
    assert_snapshot(
39
        themed_app.get_by_test_id("stMetric").nth(0),
40
        name="st_metric-green",
41
    )
42

43

44
def test_red_down_arrow_render(themed_app: Page, assert_snapshot: ImageCompareFunction):
45
    assert_snapshot(
46
        themed_app.get_by_test_id("stMetric").nth(2),
47
        name="st_metric-red",
48
    )
49

50

51
def test_gray_down_arrow_render(
52
    themed_app: Page, assert_snapshot: ImageCompareFunction
53
):
54
    assert_snapshot(
55
        themed_app.get_by_test_id("stMetric").nth(4),
56
        name="st_metric-gray",
57
    )
58

59

60
def test_help_shows_up_without_columns(
61
    themed_app: Page, assert_snapshot: ImageCompareFunction
62
):
63
    assert_snapshot(
64
        themed_app.get_by_test_id("stMetric").nth(6),
65
        name="st_metric-with_help",
66
    )
67

68

69
def test_none_results_in_dash_in_value(
70
    themed_app: Page, assert_snapshot: ImageCompareFunction
71
):
72
    assert_snapshot(
73
        themed_app.get_by_test_id("stMetric").nth(7),
74
        name="st_metric-with_none_value",
75
    )
76

77

78
def test_label_visibility_set_to_hidden(
79
    themed_app: Page, assert_snapshot: ImageCompareFunction
80
):
81
    expect(themed_app.get_by_test_id("stMetricLabel").nth(3)).to_have_text("Test 4")
82
    assert_snapshot(
83
        themed_app.get_by_test_id("stMetric").nth(3),
84
        name="st_metric-label_hidden",
85
    )
86

87

88
def test_label_visibility_set_to_collapse(
89
    themed_app: Page, assert_snapshot: ImageCompareFunction
90
):
91
    expect(themed_app.get_by_test_id("stMetricLabel").nth(5)).to_have_text("Test 5")
92
    assert_snapshot(
93
        themed_app.get_by_test_id("stMetric").nth(5),
94
        name="st_metric-label_collapse",
95
    )
96

97

98
def test_ellipses_and_help_shows_up_properly(
99
    themed_app: Page, assert_snapshot: ImageCompareFunction
100
):
101
    assert_snapshot(
102
        themed_app.get_by_test_id("stMetric").nth(8),
103
        name="st_metric-help_and_ellipses",
104
    )
105

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

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

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

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