Files
cibuildwheel/test/test_ssl.py
T
ff9508a3e1 [2.x] Update virtualenv URLs to avoid blob URLs (#2775)
* [2.x] Update virtualenv URLs to avoid blob URLs

It looks like many people are hitting the HTTP 429 for old versions of cibuildwheel. These hosted versions of virtualenv should work, let's see...

* Write the correct version strings

* ci: some updates based on main branch

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* ci: move to using latest images

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* chore: fix up style checks

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* ci: newer azure images too

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* tests: use new SSL test from main

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Drop `build`'s installation from Pyodide build tools

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
2026-03-16 19:24:46 +00:00

45 lines
1.5 KiB
Python

import textwrap
import pytest
from . import test_projects, utils
project_with_ssl_tests = test_projects.new_c_project(
setup_py_add=textwrap.dedent(
r"""
import ssl, time, urllib.request, urllib.error
def check_https(context=None):
# google hosts this endpoint that returns a 204 No Content, it's used for
# connectivity checks in Android & Chrome
url = "https://google.com/generate_204"
for i in range(5):
try:
urllib.request.urlopen(url, context=context, timeout=5)
return
except (OSError, urllib.error.URLError) as e:
print(f"Attempt {i+1}: Could not connect to {url}: {e}")
time.sleep(2 ** i) # Backoff: 1s, 2s, 4s, 8s...
raise ConnectionError(f"Could not connect to {url} after retries.")
check_https()
check_https(context=ssl.SSLContext(ssl.PROTOCOL_TLSv1_2))
"""
)
)
@pytest.mark.flaky(reruns=2)
def test(tmp_path):
# this test checks that SSL is working in the build environment using
# some checks in setup.py.
project_dir = tmp_path / "project"
project_with_ssl_tests.generate(project_dir)
actual_wheels = utils.cibuildwheel_run(project_dir)
expected_wheels = utils.expected_wheels("spam", "0.1.0")
assert set(actual_wheels) == set(expected_wheels)