Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

test: align URL download fixtures with source transport

myhlolib5d028fd144e
diff --git a/tests/unittest/test_router_cascade.py b/tests/unittest/test_router_cascade.py
index fb275bba..21bea04f 100644
--- a/tests/unittest/test_router_cascade.py
+++ b/tests/unittest/test_router_cascade.py
@@ -12,7 +12,6 @@ import zipfile
from collections.abc import AsyncIterator
from contextlib import AsyncExitStack, asynccontextmanager
from pathlib import Path
-from types import SimpleNamespace
from typing import Any
import httpx
@@ -192,11 +191,11 @@ def test_cascade_can_cancel_while_downstream_submission_is_blocked(tmp_path: Pat
def test_cascade_renews_worker_results_while_outer_lease_is_active(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
"""内层等待外部租约结束期间,仍须续租底层结果并保持下载可用。"""
- def download_client(**kwargs: Any) -> httpx.AsyncClient:
+ def download_transport() -> httpx.MockTransport:
"""仅隔离 URL 源站,Tasks、Files、租约和打包都执行真实实现。"""
- return httpx.AsyncClient(transport=httpx.MockTransport(lambda request: httpx.Response(200, content=HTML)), **kwargs)
+ return httpx.MockTransport(lambda request: httpx.Response(200, content=HTML))
- monkeypatch.setattr(api_server, "httpx", SimpleNamespace(AsyncClient=download_client))
+ monkeypatch.setattr(api_server, "UrlSourceTransport", download_transport)
async def scenario() -> None:
"""用短 worker 保留期验证三级链路,并检查外部租约释放后的清理交接。"""
diff --git a/tests/unittest/test_task_file_states.py b/tests/unittest/test_task_file_states.py
index 7003ab9c..e68c90b5 100644
--- a/tests/unittest/test_task_file_states.py
+++ b/tests/unittest/test_task_file_states.py
@@ -5,7 +5,7 @@ from __future__ import annotations
import asyncio
import threading
import time
-from collections.abc import AsyncIterator
+from collections.abc import AsyncIterator, Callable
from pathlib import Path
from types import SimpleNamespace
from typing import Any
@@ -21,14 +21,14 @@ from mineru.parser import api_server
from mineru.parser.base import ParseResult
-def _install_downloads(monkeypatch: pytest.MonkeyPatch, handler: Any) -> None:
+def _install_downloads(monkeypatch: pytest.MonkeyPatch, handler: Callable[[httpx.Request], httpx.Response]) -> None:
"""只隔离源站下载,保留客户端到 API 的真实协议和任务调度。"""
- def client(**kwargs: Any) -> httpx.AsyncClient:
- """为每次源下载创建独立 HTTPX 客户端,不修改全局 HTTPX 对象。"""
- return httpx.AsyncClient(transport=httpx.MockTransport(handler), **kwargs)
+ def download_transport() -> httpx.MockTransport:
+ """每次下载仅替换源站传输,继续使用真实 HTTPX 客户端。"""
+ return httpx.MockTransport(handler)
- monkeypatch.setattr(api_server, "httpx", SimpleNamespace(AsyncClient=client))
+ monkeypatch.setattr(api_server, "UrlSourceTransport", download_transport)
def _url_task(client: TestClient, name: str = "remote") -> dict[str, Any]: