-
-
Notifications
You must be signed in to change notification settings - Fork 20
Make sure load_package() fails when a url returns a 404
#184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| """Tests for ``SeleniumBrowserRunner.load_package``. | ||
|
|
||
| Pyodide's ``pyodide.loadPackage`` does not raise when a package cannot be | ||
| loaded (e.g. the wheel URL 404s or the package name is unknown); it only | ||
| invokes the ``errorCallback`` option. Our ``load_package`` wrapper collects | ||
| those callback messages and turns them into a ``RuntimeError`` so that the | ||
| failure is reported at the call site rather than surfacing later as a | ||
| confusing ``ModuleNotFoundError`` inside Pyodide. | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| def test_load_package_succeeds(selenium): | ||
| """Sanity check: loading a package that exists in the Pyodide dist | ||
| must not raise, and the package must be importable afterwards.""" | ||
| selenium.load_package("micropip") | ||
| # If the package is really loaded, importing it in Pyodide succeeds. | ||
| selenium.run_js("await pyodide.runPythonAsync('import micropip');") | ||
|
|
||
|
|
||
| def test_load_package_bad_url_raises(selenium): | ||
| """A URL that 404s must cause load_package to raise, and the error | ||
| message must mention the failure reported by Pyodide.""" | ||
| bad_url = ( | ||
| f"http://{selenium.server_hostname}:{selenium.server_port}" | ||
| "/does-not-exist-pytest_pyodide_test.whl" | ||
| ) | ||
| with pytest.raises(RuntimeError) as exc_info: | ||
| selenium.load_package(bad_url) | ||
|
|
||
| msg = str(exc_info.value) | ||
| assert "loadPackage" in msg | ||
| assert bad_url in msg | ||
|
|
||
|
|
||
| def test_load_package_unknown_name_raises(selenium): | ||
| """An unknown package name must also cause load_package to raise.""" | ||
| with pytest.raises(RuntimeError) as exc_info: | ||
| selenium.load_package("definitely-not-a-real-package-xyz") | ||
|
|
||
| msg = str(exc_info.value) | ||
| assert "loadPackage" in msg | ||
| assert "definitely-not-a-real-package-xyz" in msg | ||
|
|
||
|
|
||
| def test_load_package_partial_failure_raises(selenium): | ||
| """If a list contains both a valid and an invalid package, the call | ||
| must still raise so the failure is not silently swallowed.""" | ||
| with pytest.raises(RuntimeError) as exc_info: | ||
| selenium.load_package(["micropip", "definitely-not-a-real-package-xyz"]) | ||
|
|
||
| msg = str(exc_info.value) | ||
| assert "definitely-not-a-real-package-xyz" in msg |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(No actions required for this PR)
I wonder if we should change this behavior. I am not sure why we designed in that way at the first place.
I guess it was when loadPackage was unstable, we wanted a failure in a single package resolution failure does not block loading other packages. But now, I guess it is weird to make loadPackage silently success even when the package load fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.