forked from streamlit/streamlit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor streamlit chart e2e tests (streamlit#8946)
This PR refactors our e2e `st_builtin_chart.py` & `st_builtin_chart_test.py` files for the benefit of future e2e test changes for charts. These files have been broken up into separate test files for each type of built-in chart.
- Loading branch information
1 parent
af207c8
commit 0dfe07d
Showing
219 changed files
with
395 additions
and
94 deletions.
There are no files selected for viewing
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added
BIN
+1.76 KB
e2e_playwright/__snapshots__/linux/st_bar_chart_test/st_bar_chart-0[chromium].png
Oops, something went wrong.
Binary file added
BIN
+5.74 KB
e2e_playwright/__snapshots__/linux/st_bar_chart_test/st_bar_chart-0[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file added
BIN
+9.45 KB
e2e_playwright/__snapshots__/linux/st_bar_chart_test/st_bar_chart-10[chromium].png
Oops, something went wrong.
Binary file added
BIN
+16.3 KB
e2e_playwright/__snapshots__/linux/st_bar_chart_test/st_bar_chart-10[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file added
BIN
+11.2 KB
e2e_playwright/__snapshots__/linux/st_bar_chart_test/st_bar_chart-11[chromium].png
Oops, something went wrong.
Binary file added
BIN
+26.6 KB
e2e_playwright/__snapshots__/linux/st_bar_chart_test/st_bar_chart-11[firefox].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file added
BIN
+29.8 KB
e2e_playwright/__snapshots__/linux/st_bar_chart_test/st_bar_chart-12[firefox].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file added
BIN
+15.3 KB
e2e_playwright/__snapshots__/linux/st_bar_chart_test/st_bar_chart-1[firefox].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file renamed
BIN
+15.7 KB
...art_test/st_builtin_chart-14[firefox].png → ...ar_chart_test/st_bar_chart-3[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file added
BIN
+6.84 KB
e2e_playwright/__snapshots__/linux/st_bar_chart_test/st_bar_chart-4[chromium].png
Oops, something went wrong.
Binary file renamed
BIN
+13.5 KB
...art_test/st_builtin_chart-15[firefox].png → ...ar_chart_test/st_bar_chart-4[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file renamed
BIN
+10.8 KB
...rt_test/st_builtin_chart-16[chromium].png → ...r_chart_test/st_bar_chart-5[chromium].png
Oops, something went wrong.
Binary file added
BIN
+16.9 KB
e2e_playwright/__snapshots__/linux/st_bar_chart_test/st_bar_chart-5[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file added
BIN
+12.2 KB
e2e_playwright/__snapshots__/linux/st_bar_chart_test/st_bar_chart-6[chromium].png
Oops, something went wrong.
Binary file added
BIN
+20 KB
e2e_playwright/__snapshots__/linux/st_bar_chart_test/st_bar_chart-6[firefox].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added
BIN
+16.8 KB
e2e_playwright/__snapshots__/linux/st_bar_chart_test/st_bar_chart-8[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file renamed
BIN
+12.3 KB
...rt_test/st_builtin_chart-20[chromium].png → ...r_chart_test/st_bar_chart-9[chromium].png
Oops, something went wrong.
Binary file added
BIN
+23.4 KB
e2e_playwright/__snapshots__/linux/st_bar_chart_test/st_bar_chart-9[firefox].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file added
BIN
+15.6 KB
...snapshots__/linux/st_bar_chart_test/st_bar_chart_themed[dark_theme-firefox].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file added
BIN
+15.3 KB
...napshots__/linux/st_bar_chart_test/st_bar_chart_themed[light_theme-firefox].png
Oops, something went wrong.
File renamed without changes
Binary file removed
BIN
-1.76 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-11[chromium].png
Diff not rendered.
Binary file removed
BIN
-5.73 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-11[firefox].png
Diff not rendered.
Binary file removed
BIN
-15.3 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-12[firefox].png
Diff not rendered.
Binary file removed
BIN
-6.84 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-15[chromium].png
Diff not rendered.
Binary file removed
BIN
-16.9 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-16[firefox].png
Diff not rendered.
Binary file removed
BIN
-12.2 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-17[chromium].png
Diff not rendered.
Binary file removed
BIN
-20 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-17[firefox].png
Diff not rendered.
Binary file removed
BIN
-16.8 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-19[firefox].png
Diff not rendered.
Binary file removed
BIN
-23.4 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-20[firefox].png
Diff not rendered.
Binary file removed
BIN
-9.45 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-21[chromium].png
Diff not rendered.
Binary file removed
BIN
-16.3 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-21[firefox].png
Diff not rendered.
Binary file removed
BIN
-11.2 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-22[chromium].png
Diff not rendered.
Binary file removed
BIN
-26.6 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-22[firefox].png
Diff not rendered.
Binary file removed
BIN
-29.8 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-23[firefox].png
Diff not rendered.
Binary file removed
BIN
-5.06 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-24[firefox].png
Diff not rendered.
Binary file removed
BIN
-41.4 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-25[chromium].png
Diff not rendered.
Binary file removed
BIN
-53.9 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-25[firefox].png
Diff not rendered.
Binary file removed
BIN
-34.7 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-27[firefox].png
Diff not rendered.
Binary file removed
BIN
-17.2 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-29[chromium].png
Diff not rendered.
Binary file removed
BIN
-36.8 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-29[firefox].png
Diff not rendered.
Binary file removed
BIN
-35.3 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-30[firefox].png
Diff not rendered.
Binary file removed
BIN
-28.4 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-31[chromium].png
Diff not rendered.
Binary file removed
BIN
-23.5 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-32[firefox].png
Diff not rendered.
Binary file removed
BIN
-46.3 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-33[chromium].png
Diff not rendered.
Binary file removed
BIN
-52.2 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-34[firefox].png
Diff not rendered.
Binary file removed
BIN
-15.6 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-36[chromium].png
Diff not rendered.
Binary file removed
BIN
-11.7 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-37[chromium].png
Diff not rendered.
Binary file removed
BIN
-10.5 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-38[chromium].png
Diff not rendered.
Binary file removed
BIN
-10.5 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-41[chromium].png
Diff not rendered.
Binary file removed
BIN
-11.7 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-42[chromium].png
Diff not rendered.
Binary file removed
BIN
-7.4 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-43[chromium].png
Diff not rendered.
Binary file removed
BIN
-25.7 KB
...ight/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-44[firefox].png
Diff not rendered.
Binary file removed
BIN
-33 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-46[chromium].png
Diff not rendered.
Binary file removed
BIN
-17.6 KB
...ght/__snapshots__/linux/st_builtin_chart_test/st_builtin_chart-47[chromium].png
Diff not rendered.
Binary file removed
BIN
-15.6 KB
...st_builtin_chart_test/st_builtin_chart-bar_chart_themed[dark_theme-firefox].png
Diff not rendered.
Binary file removed
BIN
-15.3 KB
...t_builtin_chart_test/st_builtin_chart-bar_chart_themed[light_theme-firefox].png
Diff not rendered.
Binary file removed
BIN
-48.2 KB
..._builtin_chart_test/st_builtin_chart-line_chart_themed[dark_theme-chromium].png
Diff not rendered.
Binary file removed
BIN
-61.3 KB
...t_builtin_chart_test/st_builtin_chart-line_chart_themed[dark_theme-firefox].png
Diff not rendered.
Binary file removed
BIN
-41.4 KB
...builtin_chart_test/st_builtin_chart-line_chart_themed[light_theme-chromium].png
Diff not rendered.
Binary file removed
BIN
-53.9 KB
..._builtin_chart_test/st_builtin_chart-line_chart_themed[light_theme-firefox].png
Diff not rendered.
Binary file removed
BIN
-17.1 KB
...iltin_chart_test/st_builtin_chart-scatter_chart_themed[dark_theme-chromium].png
Diff not rendered.
Binary file removed
BIN
-15.6 KB
...ltin_chart_test/st_builtin_chart-scatter_chart_themed[light_theme-chromium].png
Diff not rendered.
Binary file renamed
BIN
+1.54 KB
...rt_test/st_builtin_chart-24[chromium].png → ..._chart_test/st_line_chart-0[chromium].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file renamed
BIN
+41.2 KB
...rt_test/st_builtin_chart-34[chromium].png → ...chart_test/st_line_chart-10[chromium].png
Oops, something went wrong.
Binary file added
BIN
+52.2 KB
...playwright/__snapshots__/linux/st_line_chart_test/st_line_chart-10[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file added
BIN
+41.4 KB
...playwright/__snapshots__/linux/st_line_chart_test/st_line_chart-1[chromium].png
Oops, something went wrong.
Binary file added
BIN
+53.9 KB
e2e_playwright/__snapshots__/linux/st_line_chart_test/st_line_chart-1[firefox].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added
BIN
+34.6 KB
e2e_playwright/__snapshots__/linux/st_line_chart_test/st_line_chart-3[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file renamed
BIN
+35.5 KB
...rt_test/st_builtin_chart-28[chromium].png → ..._chart_test/st_line_chart-4[chromium].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file added
BIN
+17.2 KB
...playwright/__snapshots__/linux/st_line_chart_test/st_line_chart-5[chromium].png
Oops, something went wrong.
Binary file added
BIN
+36.8 KB
e2e_playwright/__snapshots__/linux/st_line_chart_test/st_line_chart-5[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file renamed
BIN
+21.4 KB
...rt_test/st_builtin_chart-30[chromium].png → ..._chart_test/st_line_chart-6[chromium].png
Oops, something went wrong.
Binary file added
BIN
+35.2 KB
e2e_playwright/__snapshots__/linux/st_line_chart_test/st_line_chart-6[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file added
BIN
+28.4 KB
...playwright/__snapshots__/linux/st_line_chart_test/st_line_chart-7[chromium].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added
BIN
+23.5 KB
e2e_playwright/__snapshots__/linux/st_line_chart_test/st_line_chart-8[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file added
BIN
+46.3 KB
...playwright/__snapshots__/linux/st_line_chart_test/st_line_chart-9[chromium].png
Oops, something went wrong.
Binary file renamed
BIN
+72.2 KB
...art_test/st_builtin_chart-33[firefox].png → ...e_chart_test/st_line_chart-9[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file added
BIN
+48.2 KB
...pshots__/linux/st_line_chart_test/st_line_chart_themed[dark_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+61.3 KB
...apshots__/linux/st_line_chart_test/st_line_chart_themed[dark_theme-firefox].png
Oops, something went wrong.
File renamed without changes
Binary file added
BIN
+41.4 KB
...shots__/linux/st_line_chart_test/st_line_chart_themed[light_theme-chromium].png
Oops, something went wrong.
Binary file added
BIN
+53.9 KB
...pshots__/linux/st_line_chart_test/st_line_chart_themed[light_theme-firefox].png
Oops, something went wrong.
File renamed without changes
Binary file renamed
BIN
+1.54 KB
...rt_test/st_builtin_chart-35[chromium].png → ...art_test/st_scatter_chart-0[chromium].png
Oops, something went wrong.
Binary file added
BIN
+5.04 KB
...right/__snapshots__/linux/st_scatter_chart_test/st_scatter_chart-0[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file renamed
BIN
+31.9 KB
...rt_test/st_builtin_chart-45[chromium].png → ...rt_test/st_scatter_chart-10[chromium].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file added
BIN
+33 KB
...ght/__snapshots__/linux/st_scatter_chart_test/st_scatter_chart-11[chromium].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file added
BIN
+17.6 KB
...ght/__snapshots__/linux/st_scatter_chart_test/st_scatter_chart-12[chromium].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file added
BIN
+15.6 KB
...ight/__snapshots__/linux/st_scatter_chart_test/st_scatter_chart-1[chromium].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file added
BIN
+11.7 KB
...ight/__snapshots__/linux/st_scatter_chart_test/st_scatter_chart-2[chromium].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file added
BIN
+10.5 KB
...ight/__snapshots__/linux/st_scatter_chart_test/st_scatter_chart-3[chromium].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file renamed
BIN
+19.1 KB
...art_test/st_builtin_chart-39[firefox].png → ...hart_test/st_scatter_chart-4[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file renamed
BIN
+8.43 KB
...rt_test/st_builtin_chart-40[chromium].png → ...art_test/st_scatter_chart-5[chromium].png
Oops, something went wrong.
Binary file renamed
BIN
+12.2 KB
...art_test/st_builtin_chart-40[firefox].png → ...hart_test/st_scatter_chart-5[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file added
BIN
+10.5 KB
...ight/__snapshots__/linux/st_scatter_chart_test/st_scatter_chart-6[chromium].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file added
BIN
+11.7 KB
...ight/__snapshots__/linux/st_scatter_chart_test/st_scatter_chart-7[chromium].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file added
BIN
+7.41 KB
...ight/__snapshots__/linux/st_scatter_chart_test/st_scatter_chart-8[chromium].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added
BIN
+25.7 KB
...right/__snapshots__/linux/st_scatter_chart_test/st_scatter_chart-9[firefox].png
Oops, something went wrong.
File renamed without changes
Binary file added
BIN
+17.1 KB
...__/linux/st_scatter_chart_test/st_scatter_chart_themed[dark_theme-chromium].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file added
BIN
+15.6 KB
..._/linux/st_scatter_chart_test/st_scatter_chart_themed[light_theme-chromium].png
Oops, something went wrong.
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from datetime import date | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
import streamlit as st | ||
|
||
np.random.seed(0) | ||
|
||
|
||
data = np.random.randn(20, 3) | ||
df = pd.DataFrame(data, columns=["a", "b", "c"]) | ||
|
||
# st.area/bar/line_chart all use Altair/Vega-Lite under the hood. | ||
# By default, Vega-Lite displays time values in the browser's local | ||
# time zone, but data is sent down to the browser as UTC. This means | ||
# Times need to be set correctly to the users timezone. | ||
utc_df = pd.DataFrame( | ||
{ | ||
"index": [ | ||
date(2019, 8, 9), | ||
date(2019, 8, 10), | ||
date(2019, 8, 11), | ||
date(2019, 8, 12), | ||
], | ||
"numbers": [10, 50, 30, 40], | ||
} | ||
) | ||
|
||
utc_df.set_index("index", inplace=True) | ||
|
||
# Dataframe to test the color parameter support: | ||
N = 100 | ||
|
||
color_df = pd.DataFrame( | ||
{ | ||
# Using a negative range so certain kinds of bugs are more visible. | ||
"a": -np.arange(N), | ||
"b": np.random.rand(N) * 10, | ||
"c": np.random.rand(N) * 10, | ||
"d": np.random.randn(N) * 30, | ||
"e": ["bird" if x % 2 else "airplane" for x in range(N)], | ||
} | ||
) | ||
|
||
st.header("Area Chart") | ||
|
||
st.area_chart() | ||
st.area_chart(df) | ||
st.area_chart(df, x="a") | ||
st.area_chart(df, y="a") | ||
st.area_chart(df, y=["a", "b"]) | ||
st.area_chart(df, x="a", y="b", height=500, width=300, use_container_width=False) | ||
st.area_chart(df, x="b", y="a") | ||
st.area_chart(df, x="a", y=["b", "c"]) | ||
st.area_chart(utc_df) | ||
st.area_chart(color_df, x="a", y="b", color="e") | ||
st.area_chart(df, x_label="X Axis Label", y_label="Y Axis Label") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from playwright.sync_api import Page, expect | ||
|
||
from e2e_playwright.conftest import ImageCompareFunction | ||
|
||
TOTAL_AREA_CHARTS = 11 | ||
|
||
|
||
def test_area_chart_rendering(app: Page, assert_snapshot: ImageCompareFunction): | ||
"""Test that st.area_chart renders correctly via snapshot testing.""" | ||
area_chart_elements = app.get_by_test_id("stArrowVegaLiteChart") | ||
expect(area_chart_elements).to_have_count(TOTAL_AREA_CHARTS) | ||
|
||
# Also make sure that all canvas objects are rendered: | ||
expect(area_chart_elements.locator("canvas")).to_have_count(TOTAL_AREA_CHARTS) | ||
|
||
for i, element in enumerate(area_chart_elements.all()): | ||
assert_snapshot(element, name=f"st_area_chart-{i}") | ||
|
||
|
||
def test_themed_area_chart_rendering( | ||
themed_app: Page, assert_snapshot: ImageCompareFunction | ||
): | ||
"""Test that st.area_chart renders with different theming.""" | ||
area_chart_elements = themed_app.get_by_test_id("stArrowVegaLiteChart") | ||
expect(area_chart_elements).to_have_count(TOTAL_AREA_CHARTS) | ||
|
||
# Also make sure that all canvas objects are rendered: | ||
expect(area_chart_elements.locator("canvas")).to_have_count(TOTAL_AREA_CHARTS) | ||
|
||
# Only test a single chart per built-in chart type: | ||
assert_snapshot(area_chart_elements.nth(1), name="st_area_chart_themed") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from datetime import date | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
import streamlit as st | ||
|
||
np.random.seed(0) | ||
|
||
|
||
data = np.random.randn(20, 3) | ||
df = pd.DataFrame(data, columns=["a", "b", "c"]) | ||
|
||
# st.area/bar/line_chart all use Altair/Vega-Lite under the hood. | ||
# By default, Vega-Lite displays time values in the browser's local | ||
# time zone, but data is sent down to the browser as UTC. This means | ||
# Times need to be set correctly to the users timezone. | ||
utc_df = pd.DataFrame( | ||
{ | ||
"index": [ | ||
date(2019, 8, 9), | ||
date(2019, 8, 10), | ||
date(2019, 8, 11), | ||
date(2019, 8, 12), | ||
], | ||
"numbers": [10, 50, 30, 40], | ||
} | ||
) | ||
|
||
utc_df.set_index("index", inplace=True) | ||
|
||
# Dataframe to test the color parameter support: | ||
N = 100 | ||
|
||
color_df = pd.DataFrame( | ||
{ | ||
# Using a negative range so certain kinds of bugs are more visible. | ||
"a": -np.arange(N), | ||
"b": np.random.rand(N) * 10, | ||
"c": np.random.rand(N) * 10, | ||
"d": np.random.randn(N) * 30, | ||
"e": ["bird" if x % 2 else "airplane" for x in range(N)], | ||
} | ||
) | ||
|
||
st.header("Bar Chart") | ||
|
||
st.bar_chart() | ||
st.bar_chart(df) | ||
st.bar_chart(df, x="a") | ||
st.bar_chart(df, y="a") | ||
st.bar_chart(df, y=["a", "b"]) | ||
st.bar_chart(df, x="a", y="b", height=500, width=300, use_container_width=False) | ||
st.bar_chart(df, x="b", y="a") | ||
st.bar_chart(df, x="a", y=["b", "c"]) | ||
st.bar_chart(utc_df) | ||
st.bar_chart(color_df, x="a", y="b", color="e") | ||
st.bar_chart(df, x_label="X Axis Label", y_label="Y Axis Label") | ||
st.bar_chart(df, horizontal=True) | ||
st.bar_chart(df, horizontal=True, x_label="X Label", y_label="Y Label") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from playwright.sync_api import Page, expect | ||
|
||
from e2e_playwright.conftest import ImageCompareFunction | ||
|
||
TOTAL_BAR_CHARTS = 13 | ||
|
||
|
||
def test_bar_chart_rendering(app: Page, assert_snapshot: ImageCompareFunction): | ||
"""Test that st.bar_chart renders correctly via snapshot testing.""" | ||
bar_chart_elements = app.get_by_test_id("stArrowVegaLiteChart") | ||
expect(bar_chart_elements).to_have_count(TOTAL_BAR_CHARTS) | ||
|
||
# Also make sure that all canvas objects are rendered: | ||
expect(bar_chart_elements.locator("canvas")).to_have_count(TOTAL_BAR_CHARTS) | ||
|
||
for i, element in enumerate(bar_chart_elements.all()): | ||
assert_snapshot(element, name=f"st_bar_chart-{i}") | ||
|
||
|
||
def test_themed_bar_chart_rendering( | ||
themed_app: Page, assert_snapshot: ImageCompareFunction | ||
): | ||
"""Test that st.bar_chart renders with different theming.""" | ||
bar_chart_elements = themed_app.get_by_test_id("stArrowVegaLiteChart") | ||
expect(bar_chart_elements).to_have_count(TOTAL_BAR_CHARTS) | ||
|
||
# Also make sure that all canvas objects are rendered: | ||
expect(bar_chart_elements.locator("canvas")).to_have_count(TOTAL_BAR_CHARTS) | ||
|
||
# Only test a single chart per built-in chart type: | ||
assert_snapshot(bar_chart_elements.nth(1), name="st_bar_chart_themed") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from datetime import date | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
import streamlit as st | ||
|
||
np.random.seed(0) | ||
|
||
|
||
data = np.random.randn(20, 3) | ||
df = pd.DataFrame(data, columns=["a", "b", "c"]) | ||
|
||
# st.area/bar/line_chart all use Altair/Vega-Lite under the hood. | ||
# By default, Vega-Lite displays time values in the browser's local | ||
# time zone, but data is sent down to the browser as UTC. This means | ||
# Times need to be set correctly to the users timezone. | ||
utc_df = pd.DataFrame( | ||
{ | ||
"index": [ | ||
date(2019, 8, 9), | ||
date(2019, 8, 10), | ||
date(2019, 8, 11), | ||
date(2019, 8, 12), | ||
], | ||
"numbers": [10, 50, 30, 40], | ||
} | ||
) | ||
|
||
utc_df.set_index("index", inplace=True) | ||
|
||
# Dataframe to test the color parameter support: | ||
N = 100 | ||
|
||
color_df = pd.DataFrame( | ||
{ | ||
# Using a negative range so certain kinds of bugs are more visible. | ||
"a": -np.arange(N), | ||
"b": np.random.rand(N) * 10, | ||
"c": np.random.rand(N) * 10, | ||
"d": np.random.randn(N) * 30, | ||
"e": ["bird" if x % 2 else "airplane" for x in range(N)], | ||
} | ||
) | ||
|
||
st.header("Line Chart") | ||
|
||
st.line_chart() | ||
st.line_chart(df) | ||
st.line_chart(df, x="a") | ||
st.line_chart(df, y="a") | ||
st.line_chart(df, y=["a", "b"]) | ||
st.line_chart(df, x="a", y="b", height=500, width=300, use_container_width=False) | ||
st.line_chart(df, x="b", y="a") | ||
st.line_chart(df, x="a", y=["b", "c"]) | ||
st.line_chart(utc_df) | ||
st.line_chart(color_df, x="a", y="b", color="e") | ||
st.line_chart(df, x_label="X Axis Label", y_label="Y Axis Label") |
Oops, something went wrong.