Skip to content
31 changes: 31 additions & 0 deletions tests/playwright/examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
def test_examples(page: Page, ex_app_path: str) -> None:

skip_on_windows_with_timezonefinder(ex_app_path)
skip_airmass_on_3_9(ex_app_path)

validate_example(page, ex_app_path)

Expand All @@ -33,3 +34,33 @@ def skip_on_windows_with_timezonefinder(ex_app_path: str) -> None:
pytest.skip(
"timezonefinder has difficulty compiling on windows. Skipping example app. posit-dev/py-shiny#1651"
)


def skip_airmass_on_3_9(ex_app_path: str) -> None:
print(ex_app_path)
if ex_app_path != "examples/airmass/app.py":
return

import sys

if sys.version_info[:2] != (3, 9):
return

try:
# Astropy loads `numpy` at run time
import astropy.coordinates as _ # pyright: ignore # noqa: F401
import astropy.units as __ # pyright: ignore # noqa: F401

# Future proofing: if astropy is _actually_ loading, raise an error
raise RuntimeError(
"This code believes astropy and numpy have difficulty loading on python 3.9. Please remove this check if it is no longer true."
)
except AttributeError as e:
if "numpy" in str(e) and "product" in str(e):
pytest.skip(
"astropy and numpy has difficulty loading on python 3.9. Skipping example app: airmass. posit-dev/py-shiny#1678"
)
return

# Future proofing: if the error is not what we expect, raise it
raise e
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import re

from playwright.sync_api import Page
from utils.deploy_utils import skip_on_python_version

from shiny.playwright import controller
from shiny.run import ShinyAppProc


@skip_on_python_version(
"3.9",
reason="Astropy (and numpy) hav difficulty loading on python 3.9. posit-dev/py-shiny#1678",
)
def test_data_frame_pandas_compatible(
page: Page,
local_app: ShinyAppProc,
Expand Down
35 changes: 34 additions & 1 deletion tests/playwright/utils/deploy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import tempfile
import time
import warnings
from typing import Any, Callable, List, TypeVar
from typing import Any, Callable, List, Optional, TypeVar

import pytest
import requests
Expand Down Expand Up @@ -68,6 +68,39 @@ def skip_on_webkit(fn: CallableT) -> CallableT:
return fn


def skip_on_python_version(
version: str,
reason: Optional[str] = None,
) -> Callable[[CallableT], CallableT]:

reason_str = reason or f"Do not run on python {version}"

is_valid_version = (
re.match(r"\d+", version)
or re.match(r"\d+\.\d+", version)
or re.match(r"\d+\.\d+\.\d+", version)
) is not None

assert is_valid_version

def _(fn: CallableT) -> CallableT:

versions_match = True
for i, v in enumerate(version.split(".")):
if sys.version_info[i] != int(v):
versions_match = False
break

fn = pytest.mark.skipif(
versions_match,
reason=reason_str,
)(fn)

return fn

return _


def run_command(cmd: str) -> str:
output = subprocess.run(
cmd,
Expand Down
Loading