|
7 | 7 | import pytest |
8 | 8 |
|
9 | 9 | from hk_equity_snapshot_pipelines.input_sources import ( |
| 10 | + DEFAULT_REMOTE_COPY_TIMEOUT_SECONDS, |
| 11 | + _default_https_copy, |
10 | 12 | resolve_hk_snapshot_inputs, |
11 | 13 | resolve_input_source, |
12 | 14 | source_needs_gcloud, |
@@ -68,6 +70,36 @@ def fake_copy(source: str, target: Path) -> None: |
68 | 70 | assert resolved.exists() |
69 | 71 |
|
70 | 72 |
|
| 73 | +def test_default_https_copy_uses_timeout_and_streams_response(monkeypatch, tmp_path): |
| 74 | + calls: list[tuple[str, float]] = [] |
| 75 | + |
| 76 | + class FakeResponse: |
| 77 | + def __init__(self) -> None: |
| 78 | + self._payload = b"symbol,sector\n00001,Financials\n" |
| 79 | + |
| 80 | + def __enter__(self) -> "FakeResponse": |
| 81 | + return self |
| 82 | + |
| 83 | + def __exit__(self, *args: object) -> None: |
| 84 | + return None |
| 85 | + |
| 86 | + def read(self, size: int = -1) -> bytes: |
| 87 | + payload, self._payload = self._payload, b"" |
| 88 | + return payload |
| 89 | + |
| 90 | + def fake_urlopen(request, *, timeout: float): |
| 91 | + calls.append((request.full_url, timeout)) |
| 92 | + return FakeResponse() |
| 93 | + |
| 94 | + monkeypatch.setattr("hk_equity_snapshot_pipelines.input_sources.urlopen", fake_urlopen) |
| 95 | + target = tmp_path / "factor_snapshot.csv" |
| 96 | + |
| 97 | + _default_https_copy("https://example.com/factor_snapshot.csv", target) |
| 98 | + |
| 99 | + assert target.read_text(encoding="utf-8") == "symbol,sector\n00001,Financials\n" |
| 100 | + assert calls == [("https://example.com/factor_snapshot.csv", DEFAULT_REMOTE_COPY_TIMEOUT_SECONDS)] |
| 101 | + |
| 102 | + |
71 | 103 | def test_resolve_input_source_rejects_secret_like_remote_uri(tmp_path): |
72 | 104 | with pytest.raises(ValueError, match="must not contain token"): |
73 | 105 | resolve_input_source( |
|
0 commit comments