From acf663faac46139413bfa7853992b10944f3945e Mon Sep 17 00:00:00 2001 From: Karan Date: Fri, 19 Jan 2024 12:14:16 -0800 Subject: [PATCH] Fix deploy tests and use same app for tests (deploys + shiny) (#1025) --- tests/playwright/conftest.py | 7 ++++ .../playwright/deploys/apps/plotly_app/app.py | 9 +++-- .../deploys/apps/shiny-express-folium/app.py | 4 +- .../deploys/tests/test_dataframe.py | 3 ++ .../shiny/shiny-express/accordion/app.py | 12 ------ .../shiny-express/accordion/test_accordion.py | 8 ++-- .../shiny/shiny-express/dataframe/app.py | 24 ------------ .../shiny-express/dataframe/test_dataframe.py | 8 ++-- .../shiny/shiny-express/folium/app.py | 30 --------------- .../shiny/shiny-express/folium/test_folium.py | 8 ++-- .../shiny/shiny-express/page_default/app.py | 37 ------------------- .../page_default/test_page_default.py | 8 ++-- .../shiny/shiny-express/page_fillable/app.py | 11 ------ .../page_fillable/test_page_fillable.py | 8 ++-- .../shiny/shiny-express/page_fluid/app.py | 11 ------ .../page_fluid/test_page_fluid.py | 8 ++-- .../shiny/shiny-express/page_sidebar/app.py | 14 ------- .../page_sidebar/test_page_sidebar.py | 8 ++-- 18 files changed, 53 insertions(+), 165 deletions(-) delete mode 100644 tests/playwright/shiny/shiny-express/accordion/app.py delete mode 100644 tests/playwright/shiny/shiny-express/dataframe/app.py delete mode 100644 tests/playwright/shiny/shiny-express/folium/app.py delete mode 100644 tests/playwright/shiny/shiny-express/page_default/app.py delete mode 100644 tests/playwright/shiny/shiny-express/page_fillable/app.py delete mode 100644 tests/playwright/shiny/shiny-express/page_fluid/app.py delete mode 100644 tests/playwright/shiny/shiny-express/page_sidebar/app.py diff --git a/tests/playwright/conftest.py b/tests/playwright/conftest.py index b8120ae9f..ce7de4cfd 100644 --- a/tests/playwright/conftest.py +++ b/tests/playwright/conftest.py @@ -203,6 +203,13 @@ def create_doc_example_fixture(example_name: str, scope: str = "module"): ) +def create_deploys_fixture(app: Union[PurePath, str], scope: str = "module"): + """Used to create app fixtures from apps in tests/playwright/deploys/apps""" + return create_app_fixture( + here_root / "tests/playwright/deploys/apps" / app / "app.py", scope + ) + + def x_create_doc_example_fixture(example_name: str, scope: str = "module"): """Used to create app fixtures from apps in py-shiny/shiny/examples""" return create_app_fixture( diff --git a/tests/playwright/deploys/apps/plotly_app/app.py b/tests/playwright/deploys/apps/plotly_app/app.py index 1120f7b1e..25a097526 100644 --- a/tests/playwright/deploys/apps/plotly_app/app.py +++ b/tests/playwright/deploys/apps/plotly_app/app.py @@ -1,4 +1,5 @@ # App altered from: https://github.com/rstudio/py-shiny/blob/main/shiny/api-examples/data_frame/app.py +import pandas # noqa: F401 (this line needed for Shinylive to load plotly.express) import plotly.express as px import plotly.graph_objs as go from shinywidgets import output_widget, render_widget @@ -31,19 +32,19 @@ " Select one or more countries in the table below to see more information.", ), ui.layout_column_wrap( - 1, ui.card( ui.output_data_frame("summary_data"), ), ui.layout_column_wrap( - 1 / 2, ui.card( output_widget("country_detail_pop", height="100%"), ), ui.card( output_widget("country_detail_percap", height="100%"), ), + width=1 / 2, ), + width=1, ), ) @@ -60,8 +61,10 @@ def summary_data(): @reactive.calc def filtered_df(): + # input.summary_data_selected_rows() is a tuple, so we must convert it to list, + # as that's what Pandas requires for indexing. selected_idx = list(req(input.summary_data_selected_rows())) - countries = summary_df["country"][selected_idx] + countries = summary_df.iloc[selected_idx]["country"] # Filter data for selected countries return df[df["country"].isin(countries)] diff --git a/tests/playwright/deploys/apps/shiny-express-folium/app.py b/tests/playwright/deploys/apps/shiny-express-folium/app.py index 15dac58e2..a6d5e8ad1 100644 --- a/tests/playwright/deploys/apps/shiny-express-folium/app.py +++ b/tests/playwright/deploys/apps/shiny-express-folium/app.py @@ -12,7 +12,7 @@ with ui.card(id="card"): "Static Map" - folium.Map( + folium.Map( # pyright: ignore[reportUnknownMemberType,reportGeneralTypeIssues] location=locations_coords["San Francisco"], tiles="USGS.USTopo", zoom_start=12 ) ui.input_radio_buttons( @@ -22,7 +22,7 @@ @render.display def folium_map(): "Map inside of render display call" - folium.Map( + folium.Map( # pyright: ignore[reportUnknownMemberType,reportGeneralTypeIssues] location=locations_coords[input.location()], tiles="cartodb positron", zoom_start=12, diff --git a/tests/playwright/deploys/tests/test_dataframe.py b/tests/playwright/deploys/tests/test_dataframe.py index 93bd32500..9141f5ccc 100644 --- a/tests/playwright/deploys/tests/test_dataframe.py +++ b/tests/playwright/deploys/tests/test_dataframe.py @@ -21,3 +21,6 @@ def test_express_dataframe(page: Page, location: str) -> None: page_url = deploy(location, APP_NAME, app_file_path) page.goto(page_url, timeout=PAGE_TIMEOUT) verify_express_dataframe(page) + + +# TODO-Karan: Add a way to run the deploy tests locally without deploys for the playwright-shiny cmd diff --git a/tests/playwright/shiny/shiny-express/accordion/app.py b/tests/playwright/shiny/shiny-express/accordion/app.py deleted file mode 100644 index 60d79fc2c..000000000 --- a/tests/playwright/shiny/shiny-express/accordion/app.py +++ /dev/null @@ -1,12 +0,0 @@ -from shiny import render -from shiny.express import input, ui - -with ui.accordion(id="express_accordion", open=["Panel 1", "Panel 2"]): - with ui.accordion_panel("Panel 1"): - ui.input_slider("n", "N", 1, 100, 50) - - with ui.accordion_panel("Panel 2"): - - @render.text - def txt(): - return f"n = {input.n()}" diff --git a/tests/playwright/shiny/shiny-express/accordion/test_accordion.py b/tests/playwright/shiny/shiny-express/accordion/test_accordion.py index 86d81773e..80edbc6e9 100644 --- a/tests/playwright/shiny/shiny-express/accordion/test_accordion.py +++ b/tests/playwright/shiny/shiny-express/accordion/test_accordion.py @@ -1,8 +1,10 @@ -from conftest import ShinyAppProc +from conftest import ShinyAppProc, create_deploys_fixture from playwright.sync_api import Page from utils.express_utils import verify_express_accordion +app = create_deploys_fixture("shiny-express-accordion") -def test_express_accordion(page: Page, local_app: ShinyAppProc) -> None: - page.goto(local_app.url) + +def test_express_accordion(page: Page, app: ShinyAppProc) -> None: + page.goto(app.url) verify_express_accordion(page) diff --git a/tests/playwright/shiny/shiny-express/dataframe/app.py b/tests/playwright/shiny/shiny-express/dataframe/app.py deleted file mode 100644 index 5902c0a78..000000000 --- a/tests/playwright/shiny/shiny-express/dataframe/app.py +++ /dev/null @@ -1,24 +0,0 @@ -import pandas as pd - -from shiny import render -from shiny.express import ui - -data = { - "A": [1, 2, 3, 4, 5, 6], - "B": ["a", "b", "c", "d", "e", "f"], - "C": [10.1, 20.2, 30.3, 40.4, 50.5, 60.6], - "D": ["apple", "banana", "cherry", "date", "elderberry", "fig"], - "E": [True, False, True, False, True, False], - "F": ["John", "Jane", "Jim", "Jessie", "Jack", "Jill"], -} - -df = pd.DataFrame(data) - -ui.page_opts(fillable=True) - -with ui.card(id="card"): - ui.h2("Below is a sample dataframe") - - @render.data_frame - def sample_data_frame(id: str = "dataframe"): - return df diff --git a/tests/playwright/shiny/shiny-express/dataframe/test_dataframe.py b/tests/playwright/shiny/shiny-express/dataframe/test_dataframe.py index 05a53c4ae..d48a15c29 100644 --- a/tests/playwright/shiny/shiny-express/dataframe/test_dataframe.py +++ b/tests/playwright/shiny/shiny-express/dataframe/test_dataframe.py @@ -1,8 +1,10 @@ -from conftest import ShinyAppProc +from conftest import ShinyAppProc, create_deploys_fixture from playwright.sync_api import Page from utils.express_utils import verify_express_dataframe +app = create_deploys_fixture("shiny-express-dataframe") -def test_page_default(page: Page, local_app: ShinyAppProc) -> None: - page.goto(local_app.url) + +def test_page_default(page: Page, app: ShinyAppProc) -> None: + page.goto(app.url) verify_express_dataframe(page) diff --git a/tests/playwright/shiny/shiny-express/folium/app.py b/tests/playwright/shiny/shiny-express/folium/app.py deleted file mode 100644 index a6d5e8ad1..000000000 --- a/tests/playwright/shiny/shiny-express/folium/app.py +++ /dev/null @@ -1,30 +0,0 @@ -import folium # pyright: ignore[reportMissingTypeStubs] - -from shiny import render -from shiny.express import input, ui - -locations_coords = { - "San Francisco": (37.79554, -122.39348), - "Los Angeles": (34.05026, -118.25768), - "New York": (40.71222, -74.00490), -} -ui.page_opts(full_width=False) - -with ui.card(id="card"): - "Static Map" - folium.Map( # pyright: ignore[reportUnknownMemberType,reportGeneralTypeIssues] - location=locations_coords["San Francisco"], tiles="USGS.USTopo", zoom_start=12 - ) - ui.input_radio_buttons( - "location", "Location", ["San Francisco", "New York", "Los Angeles"] - ) - - @render.display - def folium_map(): - "Map inside of render display call" - folium.Map( # pyright: ignore[reportUnknownMemberType,reportGeneralTypeIssues] - location=locations_coords[input.location()], - tiles="cartodb positron", - zoom_start=12, - ) - input.location() diff --git a/tests/playwright/shiny/shiny-express/folium/test_folium.py b/tests/playwright/shiny/shiny-express/folium/test_folium.py index bb126e7ab..0296aaab5 100644 --- a/tests/playwright/shiny/shiny-express/folium/test_folium.py +++ b/tests/playwright/shiny/shiny-express/folium/test_folium.py @@ -1,8 +1,10 @@ -from conftest import ShinyAppProc +from conftest import ShinyAppProc, create_deploys_fixture from playwright.sync_api import Page from utils.express_utils import verify_express_folium_render +app = create_deploys_fixture("shiny-express-folium") -def test_folium_map(page: Page, local_app: ShinyAppProc) -> None: - page.goto(local_app.url) + +def test_folium_map(page: Page, app: ShinyAppProc) -> None: + page.goto(app.url) verify_express_folium_render(page) diff --git a/tests/playwright/shiny/shiny-express/page_default/app.py b/tests/playwright/shiny/shiny-express/page_default/app.py deleted file mode 100644 index de1577c1b..000000000 --- a/tests/playwright/shiny/shiny-express/page_default/app.py +++ /dev/null @@ -1,37 +0,0 @@ -from shiny.express import ui - -ui.tags.style( - """ - #shell div{ - background-color: #00000022} -""" -) -with ui.div(id="shell"): - with ui.layout_columns(col_widths=[8, 4]): - "R1C1R1" - with ui.layout_columns(col_widths=[8, 4]): - with ui.div(): - ui.div("R1C1R2-R1C1R1") - - ui.div("R1C1R2-R1C1R2") - - "R1C1R2-R1C2" - - "R1C2" - -with ui.layout_columns(col_widths=[6, 6]): - # check height is below 300px - bounding box - with ui.navset_card_tab(id="express_navset_card_tab"): - with ui.nav_panel(title="Two"): - ... - - with ui.navset_tab(id="express_navset_tab"): - for fn_txt, fn in [ - ("pre", ui.pre), - ("div", ui.div), - ("span", ui.span), - ]: - with ui.nav_panel(title=fn_txt): - for i in range(3): - with fn(): - ui.HTML(f"{fn_txt} {i}") diff --git a/tests/playwright/shiny/shiny-express/page_default/test_page_default.py b/tests/playwright/shiny/shiny-express/page_default/test_page_default.py index 4107b8305..e815450c0 100644 --- a/tests/playwright/shiny/shiny-express/page_default/test_page_default.py +++ b/tests/playwright/shiny/shiny-express/page_default/test_page_default.py @@ -1,8 +1,10 @@ -from conftest import ShinyAppProc +from conftest import ShinyAppProc, create_deploys_fixture from playwright.sync_api import Page from utils.express_utils import verify_express_page_default +app = create_deploys_fixture("shiny-express-page-default") -def test_page_default(page: Page, local_app: ShinyAppProc) -> None: - page.goto(local_app.url) + +def test_page_default(page: Page, app: ShinyAppProc) -> None: + page.goto(app.url) verify_express_page_default(page) diff --git a/tests/playwright/shiny/shiny-express/page_fillable/app.py b/tests/playwright/shiny/shiny-express/page_fillable/app.py deleted file mode 100644 index 573e65fdb..000000000 --- a/tests/playwright/shiny/shiny-express/page_fillable/app.py +++ /dev/null @@ -1,11 +0,0 @@ -from shiny import render -from shiny.express import input, ui - -ui.page_opts(fillable=True) - -with ui.card(id="card"): - ui.input_slider("a", "A", 1, 100, 50) - - @render.code - def txt(): - return input.a() diff --git a/tests/playwright/shiny/shiny-express/page_fillable/test_page_fillable.py b/tests/playwright/shiny/shiny-express/page_fillable/test_page_fillable.py index 1978aa57c..c1fb518c9 100644 --- a/tests/playwright/shiny/shiny-express/page_fillable/test_page_fillable.py +++ b/tests/playwright/shiny/shiny-express/page_fillable/test_page_fillable.py @@ -1,8 +1,10 @@ -from conftest import ShinyAppProc +from conftest import ShinyAppProc, create_deploys_fixture from playwright.sync_api import Page from utils.express_utils import verify_express_page_fillable +app = create_deploys_fixture("shiny-express-page-fillable") -def test_express_page_fillable(page: Page, local_app: ShinyAppProc) -> None: - page.goto(local_app.url) + +def test_express_page_fillable(page: Page, app: ShinyAppProc) -> None: + page.goto(app.url) verify_express_page_fillable(page) diff --git a/tests/playwright/shiny/shiny-express/page_fluid/app.py b/tests/playwright/shiny/shiny-express/page_fluid/app.py deleted file mode 100644 index 1f5c0dae4..000000000 --- a/tests/playwright/shiny/shiny-express/page_fluid/app.py +++ /dev/null @@ -1,11 +0,0 @@ -from shiny import render -from shiny.express import input, ui - -ui.page_opts(full_width=True) - -with ui.card(id="card"): - ui.input_slider("a", "A", 1, 100, 50) - - @render.code - def txt(): - return input.a() diff --git a/tests/playwright/shiny/shiny-express/page_fluid/test_page_fluid.py b/tests/playwright/shiny/shiny-express/page_fluid/test_page_fluid.py index ccee4c6fe..6967af245 100644 --- a/tests/playwright/shiny/shiny-express/page_fluid/test_page_fluid.py +++ b/tests/playwright/shiny/shiny-express/page_fluid/test_page_fluid.py @@ -1,8 +1,10 @@ -from conftest import ShinyAppProc +from conftest import ShinyAppProc, create_deploys_fixture from playwright.sync_api import Page from utils.express_utils import verify_express_page_fluid +app = create_deploys_fixture("shiny-express-page-fluid") -def test_express_page_fluid(page: Page, local_app: ShinyAppProc) -> None: - page.goto(local_app.url) + +def test_express_page_fluid(page: Page, app: ShinyAppProc) -> None: + page.goto(app.url) verify_express_page_fluid(page) diff --git a/tests/playwright/shiny/shiny-express/page_sidebar/app.py b/tests/playwright/shiny/shiny-express/page_sidebar/app.py deleted file mode 100644 index 455326083..000000000 --- a/tests/playwright/shiny/shiny-express/page_sidebar/app.py +++ /dev/null @@ -1,14 +0,0 @@ -from shiny import render -from shiny.express import input, ui - -ui.page_opts(title="PageTitle") - -with ui.sidebar(id="sidebar", title="SidebarTitle"): - "Sidebar Content" - -with ui.card(id="card"): - ui.input_slider("a", "A", 1, 100, 50) - - @render.code - def txt(): - return input.a() diff --git a/tests/playwright/shiny/shiny-express/page_sidebar/test_page_sidebar.py b/tests/playwright/shiny/shiny-express/page_sidebar/test_page_sidebar.py index c41b7bedc..0aedf85a1 100644 --- a/tests/playwright/shiny/shiny-express/page_sidebar/test_page_sidebar.py +++ b/tests/playwright/shiny/shiny-express/page_sidebar/test_page_sidebar.py @@ -1,8 +1,10 @@ -from conftest import ShinyAppProc +from conftest import ShinyAppProc, create_deploys_fixture from playwright.sync_api import Page from utils.express_utils import verify_express_page_sidebar +app = create_deploys_fixture("shiny-express-page-sidebar") -def test_express_page_sidebar(page: Page, local_app: ShinyAppProc) -> None: - page.goto(local_app.url) + +def test_express_page_sidebar(page: Page, app: ShinyAppProc) -> None: + page.goto(app.url) verify_express_page_sidebar(page)