Files
cibuildwheel/unit_test/download_test.py
T

38 lines
1.1 KiB
Python
Raw Normal View History

2026-05-28 00:20:08 +02:00
from __future__ import annotations
import ssl
2021-01-06 13:50:58 -05:00
import certifi
import pytest
2025-01-27 20:35:56 +01:00
from cibuildwheel.util.file import download
2026-05-28 00:20:08 +02:00
TYPE_CHECKING = False
if TYPE_CHECKING:
from pathlib import Path
DOWNLOAD_URL = "https://cdn.jsdelivr.net/gh/pypa/cibuildwheel@v1.6.3/requirements-dev.txt"
2026-04-01 10:23:02 -04:00
def test_download(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
2021-05-03 11:45:43 -04:00
monkeypatch.delenv("SSL_CERT_FILE", raising=False)
dest = tmp_path / "file.txt"
download(DOWNLOAD_URL, dest)
assert len(dest.read_bytes()) == 134
2026-04-01 10:23:02 -04:00
def test_download_good_ssl_cert_file(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
2021-05-03 11:45:43 -04:00
monkeypatch.setenv("SSL_CERT_FILE", certifi.where())
dest = tmp_path / "file.txt"
download(DOWNLOAD_URL, dest)
assert len(dest.read_bytes()) == 134
2026-04-01 10:23:02 -04:00
def test_download_bad_ssl_cert_file(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
2021-05-03 11:45:43 -04:00
bad_cafile = tmp_path / "ca.pem"
bad_cafile.write_text("bad certificates")
monkeypatch.setenv("SSL_CERT_FILE", str(bad_cafile))
dest = tmp_path / "file.txt"
with pytest.raises(ssl.SSLError):
download(DOWNLOAD_URL, dest)