-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from joemarshall/main
patched requests at lower level
- Loading branch information
Showing
8 changed files
with
480 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
.* | ||
!.github | ||
tests/pyodide | ||
build | ||
dist | ||
__pycache__ | ||
*.egg-info/ |
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,28 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
|
||
|
||
# install chrome | ||
wget -nc https://dl-ssl.google.com/linux/linux_signing_key.pub | ||
cat linux_signing_key.pub | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/linux_signing_key.gpg >/dev/null | ||
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/chrome.list' | ||
sudo apt update | ||
sudo apt install google-chrome-stable | ||
|
||
|
||
# pyodide build and test | ||
pip install pytest | ||
pip install pyodide-build pytest-pyodide | ||
# install chromedriver stuff for selenium to control chrome | ||
pip install selenium webdriver-manager | ||
pip install chromedriver-binary-auto | ||
# make sure chromedriver is on path | ||
export PATH=$PATH:`chromedriver-path` | ||
|
||
# run the tests | ||
cd tests | ||
# get pyodide to tests/pyodide | ||
wget https://github.com/pyodide/pyodide/releases/download/0.21.0/pyodide-build-0.21.0.tar.bz2 | ||
tar xjf pyodide-build-0.21.0.tar.bz2 | ||
pytest . --dist-dir ./pyodide --rt chrome -v |
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,73 @@ | ||
from pathlib import Path | ||
import glob | ||
|
||
from pytest_pyodide import run_in_pyodide, spawn_web_server | ||
from pytest import fixture | ||
|
||
@fixture(scope="module") | ||
def dist_dir(request): | ||
# return pyodide dist dir relative to top level of webserver | ||
p=Path(request.config.getoption('--dist-dir')).resolve() | ||
p=p.relative_to(Path(__file__).parent.parent) | ||
return p | ||
|
||
@fixture(scope="module") | ||
def web_server_base(): | ||
server_folder=Path(__file__).parent.parent | ||
with spawn_web_server(server_folder) as server: | ||
server_hostname, server_port, _ = server | ||
base_url=f"http://{server_hostname}:{server_port}/" | ||
yield base_url | ||
|
||
def _install_package(selenium,base_url): | ||
wheel_folder=Path(__file__).parent.parent / "dist" | ||
|
||
selenium.run_js( | ||
f""" | ||
await pyodide.loadPackage("micropip"); | ||
""" | ||
) | ||
selenium.run_async(f'import micropip\nawait micropip.install("requests")') | ||
|
||
for wheel in wheel_folder.glob("*.whl"): | ||
url = base_url +"dist/" + str(wheel.name) | ||
selenium.run_async(f'await micropip.install("{url}")') | ||
|
||
selenium.run( | ||
""" | ||
import pyodide_http | ||
pyodide_http.patch_all() | ||
import requests | ||
""" | ||
) | ||
|
||
|
||
def test_install_package(selenium_standalone,web_server_base): | ||
_install_package(selenium_standalone,web_server_base) | ||
|
||
|
||
def test_requests_get(selenium_standalone,dist_dir,web_server_base): | ||
_install_package(selenium_standalone,web_server_base) | ||
|
||
@run_in_pyodide | ||
def test_fn(selenium_standalone,base_url): | ||
import requests | ||
print("get:",base_url) | ||
resp=requests.get(f"{base_url}/yt-4.0.4-cp310-cp310-emscripten_3_1_14_wasm32.whl") | ||
data=resp.content | ||
return len(data) | ||
|
||
assert test_fn(selenium_standalone,f"{web_server_base}{dist_dir}/")==11373926 | ||
|
||
def test_requests_404(selenium_standalone,dist_dir,web_server_base): | ||
_install_package(selenium_standalone,web_server_base) | ||
|
||
@run_in_pyodide | ||
def test_fn(selenium_standalone,base_url): | ||
import requests | ||
print("get:",base_url) | ||
resp=requests.get(f"{base_url}/surely_this_file_does_not_exist.hopefully.") | ||
response=resp.status_code | ||
return response | ||
|
||
assert test_fn(selenium_standalone,f"{web_server_base}{dist_dir}/")==404 |
Oops, something went wrong.