Skip to content

Commit 78fdc9b

Browse files
committed
Fix test suite, test credentials option
1 parent ba644ff commit 78fdc9b

File tree

4 files changed

+68
-18
lines changed

4 files changed

+68
-18
lines changed

setup_test_env.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,27 @@ set -e
44

55

66
# install chrome
7-
wget -nc https://dl-ssl.google.com/linux/linux_signing_key.pub
8-
cat linux_signing_key.pub | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/linux_signing_key.gpg >/dev/null
9-
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/chrome.list'
10-
sudo apt update
11-
sudo apt install google-chrome-stable
7+
wget -nc https://dl-ssl.google.com/linux/linux_signing_key.pub
8+
cat linux_signing_key.pub | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/linux_signing_key.gpg >/dev/null
9+
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/chrome.list'
10+
sudo apt update
11+
sudo apt install google-chrome-stable
1212

1313

1414
# pyodide build and test
15-
pip install pytest
16-
pip install pyodide-build pytest-pyodide
15+
pip install pytest
16+
pip install pyodide-build pytest-pyodide
1717
# install chromedriver stuff for selenium to control chrome
18-
pip install selenium webdriver-manager
18+
pip install selenium webdriver-manager
1919
pip install chromedriver-binary-auto
2020
# make sure chromedriver is on path
2121
export PATH=$PATH:`chromedriver-path`
2222

2323
# run the tests
2424
cd tests
2525
# get pyodide to tests/pyodide
26-
wget https://github.com/pyodide/pyodide/releases/download/0.21.0/pyodide-build-0.21.0.tar.bz2
27-
tar xjf pyodide-build-0.21.0.tar.bz2
28-
pytest . --dist-dir ./pyodide --rt chrome -v
26+
wget https://github.com/pyodide/pyodide/releases/download/0.25.1/pyodide-0.25.1.tar.bz2
27+
tar xjf pyodide-0.25.1.tar.bz2
28+
cp "$(python3 -c 'import os.path; import pytest_pyodide; print(os.path.dirname(pytest_pyodide.__file__))')/_templates/test.html" pyodide/
29+
cp "$(python3 -c 'import os.path; import pytest_pyodide; print(os.path.dirname(pytest_pyodide.__file__))')/_templates/webworker_dev.js" pyodide/
30+
pytest . --dist-dir ./pyodide --rt chrome -v

tests/pyodide_worker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
importScripts("https://cdn.jsdelivr.net/pyodide/v0.21.3/full/pyodide.js");
1+
importScripts("https://cdn.jsdelivr.net/pyodide/v0.25.1/full/pyodide.js");
22

33
onmessage = async function (e) {
44
try {
@@ -25,4 +25,4 @@ onmessage = async function (e) {
2525
// if you prefer onerror events
2626
// setTimeout(() => { throw err; });
2727
}
28-
};
28+
};

tests/test_non_streaming.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from pathlib import Path
2+
import os.path
23
import glob
34

45
from pytest_pyodide import run_in_pyodide, spawn_web_server
5-
from pytest import fixture
6+
from pytest import fixture, fail
67

78

89
@fixture(scope="module")
@@ -43,6 +44,9 @@ def _install_package(selenium, base_url):
4344
import requests
4445
"""
4546
)
47+
break
48+
else:
49+
fail(f"no pre-built *.whl found in {os.path.relpath(wheel_folder)}")
4650

4751

4852
def test_install_package(selenium_standalone, web_server_base):
@@ -56,15 +60,52 @@ def test_requests_get(selenium_standalone, dist_dir, web_server_base):
5660
def test_fn(selenium_standalone, base_url):
5761
import requests
5862

63+
import pyodide_http._requests
64+
assert pyodide_http._requests._IS_PATCHED
65+
66+
import pyodide_http as ph
67+
5968
print("get:", base_url)
60-
url = f"{base_url}/yt-4.0.4-cp310-cp310-emscripten_3_1_14_wasm32.whl"
61-
resp = requests.get(url)
69+
url = f"{base_url}/yt-4.1.4-cp311-cp311-emscripten_3_1_46_wasm32.whl"
70+
71+
# The test web server sets "Access-Control-Allow-Origin: *" which disallows sending credentials.
72+
# Credentials are explicitly disabled, although that's the default, to exercise the option code.
73+
with ph.option_context(with_credentials=False):
74+
resp = requests.get(url)
75+
6276
data = resp.content
6377
assert resp.request.url == url
6478

6579
return len(data)
6680

67-
assert test_fn(selenium_standalone, f"{web_server_base}{dist_dir}/") == 11373926
81+
assert test_fn(selenium_standalone, f"{web_server_base}{dist_dir}/") == 78336150
82+
83+
84+
def test_urllib_get(selenium_standalone, dist_dir, web_server_base):
85+
_install_package(selenium_standalone, web_server_base)
86+
87+
@run_in_pyodide
88+
def test_fn(selenium_standalone, base_url):
89+
import urllib.request
90+
91+
import pyodide_http._urllib
92+
assert pyodide_http._urllib._IS_PATCHED
93+
94+
import pyodide_http as ph
95+
96+
# The test web server sets "Access-Control-Allow-Origin: *" which disallows sending credentials.
97+
# Credentials are explicitly disabled, although that's the default, to exercise the option code.
98+
ph.set_with_credentials_option(False)
99+
100+
print("get:", base_url)
101+
url = f"{base_url}/yt-4.1.4-cp311-cp311-emscripten_3_1_46_wasm32.whl"
102+
with urllib.request.urlopen(url) as resp:
103+
data = resp.read()
104+
assert resp.url == url
105+
106+
return len(data)
107+
108+
assert test_fn(selenium_standalone, f"{web_server_base}{dist_dir}/") == 78336150
68109

69110

70111
def test_requests_404(selenium_standalone, dist_dir, web_server_base):
@@ -74,6 +115,9 @@ def test_requests_404(selenium_standalone, dist_dir, web_server_base):
74115
def test_fn(selenium_standalone, base_url):
75116
import requests
76117

118+
import pyodide_http._requests
119+
assert pyodide_http._requests._IS_PATCHED
120+
77121
print("get:", base_url)
78122
resp = requests.get(f"{base_url}/surely_this_file_does_not_exist.hopefully.")
79123
response = resp.status_code

tests/test_streaming.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
import socketserver
1010

1111
from pathlib import Path
12+
import os.path
1213
import glob
1314

1415
import pytest_pyodide
15-
from pytest import fixture
16+
from pytest import fixture, fail
1617
from pytest_pyodide import run_in_pyodide
1718

1819

@@ -160,6 +161,9 @@ def _install_package(selenium, base_url):
160161
import requests
161162
"""
162163
)
164+
break
165+
else:
166+
fail(f"no pre-built *.whl found in {os.path.relpath(wheel_folder)}")
163167

164168

165169
def get_install_package_code(base_url):

0 commit comments

Comments
 (0)