From 9b007e0c26cd81149206a13b1c679f626d0316f4 Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Thu, 5 Dec 2024 09:31:18 +0000 Subject: [PATCH 01/11] Add integration tests --- .github/workflows/main.yml | 41 +++++++++- tests/integration/test_integration.py | 79 +++++++++++++++++++ .../{ => integration}/test_remote_indexes.py | 2 +- 3 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 tests/integration/test_integration.py rename tests/{ => integration}/test_remote_indexes.py (98%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a445f62..9541607 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,6 +12,7 @@ concurrency: jobs: test: runs-on: ${{ matrix.os }} + needs: [check-integration-test-trigger] env: DISPLAY: :99 strategy: @@ -51,7 +52,19 @@ jobs: - name: Run tests shell: bash -l {0} run: | - pytest -v \ + pytest -v tests \ + --cov=micropip \ + --durations=10 \ + --dist-dir=./dist/ \ + --maxfail=15 \ + --runner=${{ matrix.test-config.runner }} \ + --rt ${{ matrix.test-config.runtime }} + + - name: Run integration tests + if: needs.check-integration-test-trigger.outputs.run-integration-test + shell: bash -l {0} + run: | + pytest -v tests \ --cov=micropip \ --durations=10 \ --dist-dir=./dist/ \ @@ -63,6 +76,32 @@ jobs: if: ${{ github.event.repo.name == 'pyodide/micropip' || github.event_name == 'pull_request' }} with: fail_ci_if_error: false + + check-integration-test-trigger: + name: test-integration-test-trigger + runs-on: ubuntu-latest + outputs: + run-integration-test: ${{ steps.check-integration-test-trigger.outputs.trigger }} + + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - id: check-integration-test-trigger + name: Check integration test trigger + shell: bash + run: | + set -e -x + + COMMIT_MSG=$(git log --no-merges -1 --oneline) + + # The integration tests will be triggered on push or on pull_request when the commit + # message contains "[integration]" or if it is pushed to main branch. + if [[ "$GITHUB_EVENT_NAME" == push && "$GITHUB_REF" == refs/heads/main || + "$COMMIT_MSG" =~ \[integration\] ]]; then + echo "trigger=true" >> "$GITHUB_OUTPUT" + fi deploy: runs-on: ubuntu-latest diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py new file mode 100644 index 0000000..f36bab3 --- /dev/null +++ b/tests/integration/test_integration.py @@ -0,0 +1,79 @@ +# integration tests for micropip +# these test often requires querying to the real packages existing in PyPI, +# to test the micropip's ability to install packages from real world package indexes. + +# To prevent sending many requests to remote servers, these tests are disabled by default. +# To run these tests locally, add `--integration` flag, when inovking pytest. + +from pytest_pyodide import run_in_pyodide + + +def test_integration_install_basic(selenium_standalone_micropip, pytestconfig): + pytestconfig.getoption("--integration", skip=True) + + @run_in_pyodide + async def _run(selenium): + import micropip + + await micropip.install("snowballstemmer") + + import snowballstemmer + + snowballstemmer.stemmer("english") + + _run(selenium_standalone_micropip) + + +def test_integration_list_basic(selenium_standalone_micropip, pytestconfig): + pytestconfig.getoption("--integration", skip=True) + + @run_in_pyodide + async def _run(selenium): + import micropip + + await micropip.install("snowballstemmer") + + packages = await micropip.list() + assert "snowballstemmer" in packages + + _run(selenium_standalone_micropip) + + +def test_integration_uninstall_basic(selenium_standalone_micropip, pytestconfig): + pytestconfig.getoption("--integration", skip=True) + + @run_in_pyodide + async def _run(selenium): + import micropip + + await micropip.install("snowballstemmer") + + import snowballstemmer + + snowballstemmer.stemmer("english") + + await micropip.uninstall("snowballstemmer") + + packages = await micropip.list() + assert "snowballstemmer" not in packages + + _run(selenium_standalone_micropip) + + +def test_integration_freeze_basic(selenium_standalone_micropip, pytestconfig): + pytestconfig.getoption("--integration", skip=True) + + @run_in_pyodide + async def _run(selenium): + import micropip + + await micropip.install("snowballstemmer") + + import snowballstemmer + + snowballstemmer.stemmer("english") + + lockfile = micropip.freeze() + assert "snowballstemmer" in lockfile["packages"] + + _run(selenium_standalone_micropip) diff --git a/tests/test_remote_indexes.py b/tests/integration/test_remote_indexes.py similarity index 98% rename from tests/test_remote_indexes.py rename to tests/integration/test_remote_indexes.py index f3928be..c8b9c18 100644 --- a/tests/test_remote_indexes.py +++ b/tests/integration/test_remote_indexes.py @@ -1,7 +1,7 @@ # This file contains tests that actually query remote package indexes, # to ensure that micropip works with real-world package indexes. # Since running these tests will send many requests to remote servers, -# these tests are disabled by default. +# these tests are disabled by default in CI. # # To run these tests, add `--run-remote-index-tests` flag, or # these tests can also be run in Github Actions manually. From 2f536461db8d27721f5ffb66d4e81b205a0bb7ae Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Thu, 5 Dec 2024 09:35:56 +0000 Subject: [PATCH 02/11] lint [integration] --- .github/workflows/main.yml | 4 ++-- .pre-commit-config.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9541607..ba2b0c1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -59,7 +59,7 @@ jobs: --maxfail=15 \ --runner=${{ matrix.test-config.runner }} \ --rt ${{ matrix.test-config.runtime }} - + - name: Run integration tests if: needs.check-integration-test-trigger.outputs.run-integration-test shell: bash -l {0} @@ -76,7 +76,7 @@ jobs: if: ${{ github.event.repo.name == 'pyodide/micropip' || github.event_name == 'pull_request' }} with: fail_ci_if_error: false - + check-integration-test-trigger: name: test-integration-test-trigger runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 57b9c82..65c5080 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ default_language_version: - python: "3.11" + python: "3.12" exclude: (^micropip/externals|^tests/vendored|^tests/test_data) repos: From 7e4cd40237eb8ccef72802ff9f6acbdb00245631 Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Thu, 5 Dec 2024 09:40:21 +0000 Subject: [PATCH 03/11] fix path and flag [integration] --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ba2b0c1..19e3456 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -64,7 +64,8 @@ jobs: if: needs.check-integration-test-trigger.outputs.run-integration-test shell: bash -l {0} run: | - pytest -v tests \ + pytest -v tests/integration \ + --integration \ --cov=micropip \ --durations=10 \ --dist-dir=./dist/ \ From 66aafcb52ab7215e895ca0626d135174d163de2d Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Thu, 5 Dec 2024 09:44:47 +0000 Subject: [PATCH 04/11] Fix pytest flag [integration] --- tests/conftest.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index b0151c3..84d0bce 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -23,6 +23,13 @@ def pytest_addoption(parser): help="Run tests that query remote package indexes.", ) + parser.addoption( + "--integration", + action="store_true", + default=None, + help="Run integration tests.", + ) + EMSCRIPTEN_VER = "3.1.14" PLATFORM = f"emscripten_{EMSCRIPTEN_VER.replace('.', '_')}_wasm32" From d66607b77179fa8eace62efbebfd99d16748994a Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Thu, 5 Dec 2024 09:53:07 +0000 Subject: [PATCH 05/11] fix test [integration] --- tests/integration/test_integration.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index f36bab3..cc7af73 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -33,7 +33,7 @@ async def _run(selenium): await micropip.install("snowballstemmer") - packages = await micropip.list() + packages = micropip.list() assert "snowballstemmer" in packages _run(selenium_standalone_micropip) @@ -52,7 +52,7 @@ async def _run(selenium): snowballstemmer.stemmer("english") - await micropip.uninstall("snowballstemmer") + micropip.uninstall("snowballstemmer") packages = await micropip.list() assert "snowballstemmer" not in packages @@ -65,6 +65,8 @@ def test_integration_freeze_basic(selenium_standalone_micropip, pytestconfig): @run_in_pyodide async def _run(selenium): + import json + import micropip await micropip.install("snowballstemmer") @@ -74,6 +76,6 @@ async def _run(selenium): snowballstemmer.stemmer("english") lockfile = micropip.freeze() - assert "snowballstemmer" in lockfile["packages"] + assert "snowballstemmer" in json.loads(lockfile) _run(selenium_standalone_micropip) From 1ee1598c868492ae35bd5e6e9cbfeb1cebcd1b2e Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Sat, 7 Dec 2024 19:13:31 +0900 Subject: [PATCH 06/11] Update tests/integration/test_integration.py Co-authored-by: Hood Chatham --- tests/integration/test_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index cc7af73..74316d4 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -3,7 +3,7 @@ # to test the micropip's ability to install packages from real world package indexes. # To prevent sending many requests to remote servers, these tests are disabled by default. -# To run these tests locally, add `--integration` flag, when inovking pytest. +# To run these tests locally, invoke pytest with the `--integration` flag. from pytest_pyodide import run_in_pyodide From 60c726d47eeebcb82250fbbbfe29034cda117b09 Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Sat, 7 Dec 2024 19:13:36 +0900 Subject: [PATCH 07/11] Update tests/integration/test_integration.py Co-authored-by: Hood Chatham --- tests/integration/test_integration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 74316d4..9f26de3 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -1,5 +1,5 @@ -# integration tests for micropip -# these test often requires querying to the real packages existing in PyPI, +# Integration tests for micropip +# These test often requires querying to the real packages existing in PyPI, # to test the micropip's ability to install packages from real world package indexes. # To prevent sending many requests to remote servers, these tests are disabled by default. From eb000e494f1788f9624b9843ee05bacca7d852cb Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Sat, 7 Dec 2024 10:17:47 +0000 Subject: [PATCH 08/11] Make decorator [integration] --- tests/integration/test_integration.py | 21 +++++++++++++-------- tests/integration/test_remote_indexes.py | 2 +- tests/test_install.py | 22 ---------------------- 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 9f26de3..6725b72 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -5,12 +5,20 @@ # To prevent sending many requests to remote servers, these tests are disabled by default. # To run these tests locally, invoke pytest with the `--integration` flag. +import pytest from pytest_pyodide import run_in_pyodide -def test_integration_install_basic(selenium_standalone_micropip, pytestconfig): - pytestconfig.getoption("--integration", skip=True) +def integration_test_only(func): + def wrapper(selenium_standalone_micropip, pytestconfig): + if not pytestconfig.getoption("--integration"): + pytest.skip("Integration tests are skipped. Use --integration to run them.") + func(selenium_standalone_micropip, pytestconfig) + return wrapper + +@integration_test_only +def test_integration_install_basic(selenium_standalone_micropip, pytestconfig): @run_in_pyodide async def _run(selenium): import micropip @@ -24,9 +32,8 @@ async def _run(selenium): _run(selenium_standalone_micropip) +@integration_test_only def test_integration_list_basic(selenium_standalone_micropip, pytestconfig): - pytestconfig.getoption("--integration", skip=True) - @run_in_pyodide async def _run(selenium): import micropip @@ -39,9 +46,8 @@ async def _run(selenium): _run(selenium_standalone_micropip) +@integration_test_only def test_integration_uninstall_basic(selenium_standalone_micropip, pytestconfig): - pytestconfig.getoption("--integration", skip=True) - @run_in_pyodide async def _run(selenium): import micropip @@ -60,9 +66,8 @@ async def _run(selenium): _run(selenium_standalone_micropip) +@integration_test_only def test_integration_freeze_basic(selenium_standalone_micropip, pytestconfig): - pytestconfig.getoption("--integration", skip=True) - @run_in_pyodide async def _run(selenium): import json diff --git a/tests/integration/test_remote_indexes.py b/tests/integration/test_remote_indexes.py index c8b9c18..f5bc808 100644 --- a/tests/integration/test_remote_indexes.py +++ b/tests/integration/test_remote_indexes.py @@ -1,7 +1,7 @@ # This file contains tests that actually query remote package indexes, # to ensure that micropip works with real-world package indexes. # Since running these tests will send many requests to remote servers, -# these tests are disabled by default in CI. +# these tests are disabled by default in CI and local testing. # # To run these tests, add `--run-remote-index-tests` flag, or # these tests can also be run in Github Actions manually. diff --git a/tests/test_install.py b/tests/test_install.py index aa89b0e..aa0d22e 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -6,28 +6,6 @@ import micropip -def test_install_simple(selenium_standalone_micropip): - selenium = selenium_standalone_micropip - assert ( - selenium.run_js( - """ - return await pyodide.runPythonAsync(` - import os - import micropip - from pyodide.ffi import to_js - # Package 'pyodide-micropip-test' has dependency on 'snowballstemmer' - # It is used to test markers support - await micropip.install('pyodide-micropip-test') - import snowballstemmer - stemmer = snowballstemmer.stemmer('english') - to_js(stemmer.stemWords('go going goes gone'.split())) - `); - """ - ) - == ["go", "go", "goe", "gone"] - ) - - def test_install_custom_url(selenium_standalone_micropip, wheel_catalog): selenium = selenium_standalone_micropip snowball_wheel = wheel_catalog.get("snowballstemmer") From 7e4a6f72ccdf1e7506804c15fedd38b5d14460e5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Dec 2024 10:18:58 +0000 Subject: [PATCH 09/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/integration/test_integration.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 6725b72..7d1bd53 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -14,6 +14,7 @@ def wrapper(selenium_standalone_micropip, pytestconfig): if not pytestconfig.getoption("--integration"): pytest.skip("Integration tests are skipped. Use --integration to run them.") func(selenium_standalone_micropip, pytestconfig) + return wrapper From 2faefd6176fa67c74a91faf6dc24c0f7afaf00b0 Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Sat, 7 Dec 2024 10:23:17 +0000 Subject: [PATCH 10/11] Fix test --- tests/integration/test_integration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 6725b72..23c3b7e 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -60,7 +60,7 @@ async def _run(selenium): micropip.uninstall("snowballstemmer") - packages = await micropip.list() + packages = micropip.list() assert "snowballstemmer" not in packages _run(selenium_standalone_micropip) @@ -81,6 +81,6 @@ async def _run(selenium): snowballstemmer.stemmer("english") lockfile = micropip.freeze() - assert "snowballstemmer" in json.loads(lockfile) + assert "snowballstemmer" in json.loads(lockfile)["packages"] _run(selenium_standalone_micropip) From d2dfcef1aa3d32e6636f3a5bab847284248a49ca Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Sat, 7 Dec 2024 10:23:37 +0000 Subject: [PATCH 11/11] [integration]