Files

51 lines
1.6 KiB
Python
Raw Permalink Normal View History

2026-05-28 00:20:08 +02:00
from __future__ import annotations
2020-05-02 22:50:52 +01:00
import textwrap
import pytest
2021-01-06 13:50:58 -05:00
from . import test_projects, utils
2020-05-02 16:54:19 +01:00
2026-05-28 00:20:08 +02:00
TYPE_CHECKING = False
if TYPE_CHECKING:
from pathlib import Path
project_with_ssl_tests = test_projects.new_c_project(
2021-04-30 17:56:34 -04:00
setup_py_add=textwrap.dedent(
2021-05-03 11:45:43 -04:00
r"""
import ssl, time, urllib.request, urllib.error
2020-05-02 16:54:19 +01:00
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"
2020-05-02 16:54:19 +01:00
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))
2021-05-03 11:45:43 -04:00
"""
2021-04-30 17:56:34 -04:00
)
2020-05-02 16:54:19 +01:00
)
2020-05-02 22:50:52 +01:00
@pytest.mark.flaky(reruns=2)
2026-04-01 10:23:02 -04:00
def test(tmp_path: Path) -> None:
2020-05-02 16:54:19 +01:00
# this test checks that SSL is working in the build environment using
# some checks in setup.py.
2021-05-03 11:45:43 -04:00
project_dir = tmp_path / "project"
2020-05-02 16:54:19 +01:00
project_with_ssl_tests.generate(project_dir)
2020-05-15 12:19:38 +01:00
actual_wheels = utils.cibuildwheel_run(project_dir)
2021-05-03 11:45:43 -04:00
expected_wheels = utils.expected_wheels("spam", "0.1.0")
2020-05-15 12:19:38 +01:00
assert set(actual_wheels) == set(expected_wheels)