Skip to content

Commit b76a581

Browse files
authored
test: Add skip for airmass example on python 3.9 (#1678)
1 parent 33f2c84 commit b76a581

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

tests/playwright/examples/test_examples.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
def test_examples(page: Page, ex_app_path: str) -> None:
1313

1414
skip_on_windows_with_timezonefinder(ex_app_path)
15+
skip_airmass_on_3_9(ex_app_path)
1516

1617
validate_example(page, ex_app_path)
1718

@@ -33,3 +34,33 @@ def skip_on_windows_with_timezonefinder(ex_app_path: str) -> None:
3334
pytest.skip(
3435
"timezonefinder has difficulty compiling on windows. Skipping example app. posit-dev/py-shiny#1651"
3536
)
37+
38+
39+
def skip_airmass_on_3_9(ex_app_path: str) -> None:
40+
print(ex_app_path)
41+
if ex_app_path != "examples/airmass/app.py":
42+
return
43+
44+
import sys
45+
46+
if sys.version_info[:2] != (3, 9):
47+
return
48+
49+
try:
50+
# Astropy loads `numpy` at run time
51+
import astropy.coordinates as _ # pyright: ignore # noqa: F401
52+
import astropy.units as __ # pyright: ignore # noqa: F401
53+
54+
# Future proofing: if astropy is _actually_ loading, raise an error
55+
raise RuntimeError(
56+
"This code believes astropy and numpy have difficulty loading on python 3.9. Please remove this check if it is no longer true."
57+
)
58+
except AttributeError as e:
59+
if "numpy" in str(e) and "product" in str(e):
60+
pytest.skip(
61+
"astropy and numpy has difficulty loading on python 3.9. Skipping example app: airmass. posit-dev/py-shiny#1678"
62+
)
63+
return
64+
65+
# Future proofing: if the error is not what we expect, raise it
66+
raise e

tests/playwright/shiny/components/data_frame/pandas_compatible/test_df_pandas_compatible.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import re
22

33
from playwright.sync_api import Page
4+
from utils.deploy_utils import skip_on_python_version
45

56
from shiny.playwright import controller
67
from shiny.run import ShinyAppProc
78

89

10+
@skip_on_python_version(
11+
"3.9",
12+
reason="Astropy (and numpy) hav difficulty loading on python 3.9. posit-dev/py-shiny#1678",
13+
)
914
def test_data_frame_pandas_compatible(
1015
page: Page,
1116
local_app: ShinyAppProc,

tests/playwright/utils/deploy_utils.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import tempfile
1010
import time
1111
import warnings
12-
from typing import Any, Callable, List, TypeVar
12+
from typing import Any, Callable, List, Optional, TypeVar
1313

1414
import pytest
1515
import requests
@@ -68,6 +68,39 @@ def skip_on_webkit(fn: CallableT) -> CallableT:
6868
return fn
6969

7070

71+
def skip_on_python_version(
72+
version: str,
73+
reason: Optional[str] = None,
74+
) -> Callable[[CallableT], CallableT]:
75+
76+
reason_str = reason or f"Do not run on python {version}"
77+
78+
is_valid_version = (
79+
re.match(r"\d+", version)
80+
or re.match(r"\d+\.\d+", version)
81+
or re.match(r"\d+\.\d+\.\d+", version)
82+
) is not None
83+
84+
assert is_valid_version
85+
86+
def _(fn: CallableT) -> CallableT:
87+
88+
versions_match = True
89+
for i, v in enumerate(version.split(".")):
90+
if sys.version_info[i] != int(v):
91+
versions_match = False
92+
break
93+
94+
fn = pytest.mark.skipif(
95+
versions_match,
96+
reason=reason_str,
97+
)(fn)
98+
99+
return fn
100+
101+
return _
102+
103+
71104
def run_command(cmd: str) -> str:
72105
output = subprocess.run(
73106
cmd,

0 commit comments

Comments
 (0)