Skip to content

Commit 9b5a817

Browse files
authored
test(templates): test py-shiny templates (#1998)
1 parent 51da1cc commit 9b5a817

File tree

5 files changed

+53
-6
lines changed

5 files changed

+53
-6
lines changed

.github/workflows/pytest.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ jobs:
193193
working-directory: examples/brownian/shinymediapipe
194194
run: |
195195
npm ci
196+
- name: Checkout py-shiny-templates repository
197+
uses: actions/checkout@v4
198+
with:
199+
repository: posit-dev/py-shiny-templates
200+
path: py-shiny-templates
201+
202+
- name: Install py-shiny-templates dependencies
203+
if: matrix.python-version != '3.9'
204+
# Scikit-learn 1.7.0+ requires Python 3.10+
205+
run: |
206+
make ci-install-py-shiny-templates-deps
196207
197208
- name: Run example app tests
198209
timeout-minutes: 60

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ install-deps: FORCE ## install dependencies
223223
pip install -e ".[dev,test]" --upgrade
224224
ci-install-deps: FORCE
225225
uv pip install -e ".[dev,test]"
226+
ci-install-py-shiny-templates-deps: FORCE
227+
uv pip install -r py-shiny-templates/requirements.txt
226228

227229
install-docs: FORCE
228230
pip install -e ".[dev,test,doc]"

pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,7 @@ dev = [
113113
"anthropic",
114114
"google-generativeai;python_version>='3.9'",
115115
"langchain_core",
116-
# langsmith (needed for langchain_core) versions >= 0.3
117-
# (up to at least 0.3.2 as of 2025-01-29)
118-
# cause an `argparse.ArgumentError` when running `pytest`.
119-
# https://github.com/posit-dev/py-shiny/issues/1829
120-
"langsmith<0.3",
116+
"langsmith>=0.3.4",
121117
"openai",
122118
"ollama",
123119
"chatlas>=0.6.1",

tests/playwright/examples/example_apps.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pathlib import PurePath
55
from typing import Literal
66

7-
from playwright.sync_api import ConsoleMessage, Page
7+
from playwright.sync_api import ConsoleMessage, Page, expect
88

99
from shiny.run import ShinyAppProc, run_shiny_app
1010

@@ -91,11 +91,20 @@ def get_apps(path: str) -> typing.List[str]:
9191
"FutureWarning: use_inf_as_na option is deprecated",
9292
"pd.option_context('mode.use_inf_as_na", # continutation of line above,
9393
"RuntimeWarning: invalid value encountered in dot", # some groups didn't have enough data points to create a meaningful line
94+
"DatetimeIndex.format is deprecated and will be removed in a future version. Convert using index.astype(str) or index.map(formatter) instead.", # cufflinks package is using this method
95+
"Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`", # cufflinks package is using this method
9496
]
9597
app_allow_js_errors: typing.Dict[str, typing.List[str]] = {
9698
"examples/brownian": ["Failed to acquire camera feed:"],
9799
}
98100

101+
# Check for Shiny output errors, except for known exception cases
102+
app_allow_output_error = [
103+
"shiny/api-examples/SafeException/app-express.py",
104+
"shiny/api-examples/SafeException/app-core.py",
105+
"examples/global_pyplot/app.py",
106+
]
107+
99108

100109
# Altered from `shinytest2:::app_wait_for_idle()`
101110
# https://github.com/rstudio/shinytest2/blob/b8fdce681597e9610fc078aa6e376134c404f3bd/R/app-driver-wait.R
@@ -251,3 +260,8 @@ def on_console_msg(msg: ConsoleMessage) -> None:
251260
+ " had JavaScript console errors!\n"
252261
+ "* ".join(console_errors)
253262
)
263+
264+
if ex_app_path not in app_allow_output_error:
265+
# Ensure there are no output errors present
266+
error_locator = page.locator(".shiny-output-error")
267+
expect(error_locator).to_have_count(0)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sys
2+
from pathlib import Path
3+
4+
import pytest
5+
from conftest import here_root
6+
from example_apps import get_apps, reruns, reruns_delay, validate_example
7+
from playwright.sync_api import Page
8+
9+
if not Path(here_root / "py-shiny-templates").exists():
10+
pytest.skip(
11+
"./py-shiny-templates dir is not available. Skipping test.",
12+
allow_module_level=True,
13+
)
14+
15+
16+
@pytest.mark.skipif(
17+
sys.version_info[:2] == (3, 9),
18+
reason="Skipping test for Python 3.9 since scikit-learn pinned version is only supported on Python 3.10+",
19+
)
20+
@pytest.mark.only_browser("chromium")
21+
@pytest.mark.flaky(reruns=reruns, reruns_delay=reruns_delay)
22+
@pytest.mark.parametrize("ex_app_path", get_apps("py-shiny-templates"))
23+
def test_external_templates(page: Page, ex_app_path: str) -> None:
24+
validate_example(page, ex_app_path)

0 commit comments

Comments
 (0)