-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fetch_string_and_headers compat: raise in and out of pyodide
Currently only the not_in_pyodide will raise on non-success, because this is the default behavior of urllib, the in_pyodide will not, so I added a raise_for_status. It is better to raise, as otherwise the package parser will potentially get proper URL and not manage to parse it, and decide there is no wheels, while we actually just got an error (404, or maybe 500). In addition wraps both case in a custom local HttpStatusError, so that we can actually catch these errors in the right places when we encounter them. Also add handling for PyPI 404 Now that warehouse set cors to 404, (pypi/warehouse#16339) we need to change the checked exceptions as there is no more network errors.
- Loading branch information
Showing
9 changed files
with
124 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,37 @@ | ||
""" | ||
test that function in compati behave the same | ||
""" | ||
|
||
import pytest | ||
from pytest_pyodide import run_in_pyodide | ||
|
||
|
||
@pytest.mark.driver_timeout(10) | ||
def test_404(selenium_standalone_micropip, httpserver, request): | ||
selenium_standalone_micropip.set_script_timeout(11) | ||
|
||
@run_in_pyodide(packages=["micropip", "packaging"]) | ||
async def _inner_test_404_raise(selenium, url): | ||
import pyodide | ||
import pytest | ||
from packaging.version import parse | ||
|
||
from micropip._compat import HttpStatusError, fetch_string_and_headers | ||
|
||
if parse(pyodide.__version__) > parse("0.27"): | ||
ExpectedErrorClass = HttpStatusError | ||
else: | ||
ExpectedErrorClass = OSError | ||
|
||
with pytest.raises(ExpectedErrorClass): | ||
await fetch_string_and_headers(url, {}) | ||
|
||
httpserver.expect_request("/404").respond_with_data( | ||
"Not found", | ||
status=404, | ||
content_type="text/plain", | ||
headers={"Access-Control-Allow-Origin": "*"}, | ||
) | ||
url_404 = httpserver.url_for("/404") | ||
_inner_test_404_raise(selenium_standalone_micropip, url_404) |
This file contains 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