Skip to content

Commit

Permalink
Ensure shinylive assets are available for unit tests (#40)
Browse files Browse the repository at this point in the history
* Ensure shinylive assets are available for unit tests

* Undo skipping

* Use decorator to skip pytest tests (and ensure assets before running tests that need them)

* Temporarily set to False

* Revert "Temporarily set to False"

This reverts commit 9885455.
  • Loading branch information
cpsievert authored Sep 3, 2024
1 parent 3a899f6 commit 59ec7b0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
8 changes: 6 additions & 2 deletions tests/test_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

import shinylive._assets


# Don't run this test in CI, unless we're triggered by a release event. In the future,
# it would make sense to run this test when we're on an rc branch.
skip_if_not_release = (
os.environ.get("CI") == "true" and os.environ.get("GITHUB_EVENT_NAME") != "release"
)


@pytest.mark.skipif(
os.environ.get("CI") == "true" and os.environ.get("GITHUB_EVENT_NAME") != "release",
skip_if_not_release,
reason="Don't run this test in CI, unless we're on a release branch.",
)
def test_assets_available():
Expand Down
28 changes: 23 additions & 5 deletions tests/test_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import pytest

from shinylive._assets import ensure_shinylive_assets


def test_requirements_txt():
from shinylive._deps import _find_packages_in_requirements
Expand All @@ -30,14 +32,18 @@ def test_requirements_txt():
# because they require the assets to be installed. In the future, it would make sense to
# run this test when we're on an rc branch.
# ======================================================================================
if os.environ.get("CI") == "true" and os.environ.get("GITHUB_EVENT_NAME") != "release":
pytest.skip(
reason="Don't run this test in CI, unless we're on a release branch.",
allow_module_level=True,
)
skip_if_not_release = (
os.environ.get("CI") == "true" and os.environ.get("GITHUB_EVENT_NAME") != "release"
)


@pytest.mark.skipif(
skip_if_not_release,
reason="Don't run this test in CI, unless we're on a release branch.",
)
def test_module_to_package_key():
ensure_shinylive_assets()

from shinylive._deps import module_to_package_key

assert module_to_package_key("cv2") == "opencv-python"
Expand All @@ -50,7 +56,13 @@ def test_module_to_package_key():
assert module_to_package_key("foobar") is None


@pytest.mark.skipif(
skip_if_not_release,
reason="Don't run this test in CI, unless we're on a release branch.",
)
def test_dep_name_to_dep_key():
ensure_shinylive_assets()

from shinylive._deps import dep_name_to_dep_key

assert dep_name_to_dep_key("black") == "black"
Expand All @@ -74,7 +86,13 @@ def test_dep_name_to_dep_key():
assert dep_name_to_dep_key("distutils") == "distutils"


@pytest.mark.skipif(
skip_if_not_release,
reason="Don't run this test in CI, unless we're on a release branch.",
)
def test_find_recursive_deps():
ensure_shinylive_assets()

from shinylive._deps import _find_recursive_deps

# It is possible that these dependencies will change in future versions of Pyodide,
Expand Down

0 comments on commit 59ec7b0

Please sign in to comment.