Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
Add parameterized tests for VLM runtime and PDF mode routing progress labels
myhloli2a006634babf
diff --git a/tests/unittest/test_native_async_runtime.py b/tests/unittest/test_native_async_runtime.pyindex 32445a9a..a04a9c34 100644--- a/tests/unittest/test_native_async_runtime.py+++ b/tests/unittest/test_native_async_runtime.py@@ -363,3 +363,52 @@ def test_owner_cleanup_failure_still_closes_other_runtimes(monkeypatch: pytest.Massert not first._thread.is_alive()assert not second._thread.is_alive()assert clients[1].closed++[email protected]("enabled", [False, True])[email protected]("async_mode", [False, True])+def test_vllm_runtime_uses_standard_progress_label(+ monkeypatch: pytest.MonkeyPatch,+ capsys: pytest.CaptureFixture[str],+ enabled: bool,+ async_mode: bool,+) -> None:+ """同步桥接和原生异步入口都通过真实高层抽取显示同一文案,不创建嵌套进度。"""+ from PIL import Image+ from mineru_vl_utils import MinerUClient+ from mineru_vl_utils.structs import ContentBlock+ from mineru_vl_utils.vlm_client.vllm_async_engine_client import VllmAsyncEngineVlmClient++ backend = object.__new__(VllmAsyncEngineVlmClient)+ backend.max_concurrency = 2++ async def predict(image: Any, prompt: str = "", **kwargs: Any) -> str:+ """仅替换 GPU 单请求,保持真实异步批处理和布局回填。"""+ return "recognized"++ def create() -> MinerUClient:+ """在运行时线程创建高层客户端,复用已注入的无 GPU 后端。"""+ return MinerUClient(backend="vllm-async-engine", vllm_async_llm=object(), use_tqdm=enabled)++ monkeypatch.setattr(backend, "aio_predict", predict)+ monkeypatch.setattr("mineru_vl_utils.mineru_client.new_vlm_client", lambda **kwargs: backend)+ runtime = AsyncVlmPredictor(create, lambda _: None, backend="vllm-async-engine", max_concurrency=2)+ image = Image.new("RGB", (32, 32))+ blocks = [[ContentBlock("text", [0, 0, 1, 1])]]+ try:+ runtime.wait_ready()+ results = (+ asyncio.run(runtime.aio_batch_extract_with_layout([image], blocks))+ if async_mode+ else runtime.batch_extract_with_layout([image], blocks)+ )+ assert results[0][0].content == "recognized"+ stderr = capsys.readouterr().err+ assert ("VLM Predict" in stderr) is enabled+ assert "External Layout Extraction" not in stderr+ assert "Processed prompts" not in stderr+ if enabled:+ assert "1/1" in stderr+ finally:+ runtime.shutdown()+ image.close()diff --git a/tests/unittest/test_vlm_remote.py b/tests/unittest/test_vlm_remote.pyindex 5f8a8384..3b1397f6 100644--- a/tests/unittest/test_vlm_remote.py+++ b/tests/unittest/test_vlm_remote.py@@ -406,8 +406,11 @@ def test_remote_parse_inference_progress()assert "Remote VLM text" in result.markdown()stderr = capsys.readouterr().err- description = "Extraction" if tier == "standard" else "Two Step Extraction"+ description = "VLM Predict" if tier == "standard" else "Two Step Extraction"assert (description in stderr) is enabled+ if tier == "standard":+ assert "External Layout Extraction" not in stderr+ assert "Processed prompts" not in stderrif enabled:assert "100%" in stderrif tier == "advanced":@@ -441,3 +444,37 @@ def test_native_http_parse_never_calls_sync_analysis_or_inference()assert "Remote VLM text" in result.markdown()forbidden.assert_not_called()++[email protected](("ocr_mode", "resolved_mode"), [("txt", "txt"), ("ocr", "ocr"), ("auto", "txt"), ("auto", "ocr")])[email protected]("async_mode", [False, True])+def test_standard_progress_label_survives_pdf_mode_routing(+ openai_server: _OpenAIServer,+ hybrid_stub: None,+ tmp_path: Path,+ monkeypatch: pytest.MonkeyPatch,+ capsys: pytest.CaptureFixture[str],+ ocr_mode: str,+ resolved_mode: str,+ async_mode: bool,+) -> None:+ """TXT/OCR 及 auto 的两个分类分支均保留同名推理进度,并走真实 PDF 和 HTTP 流程。"""+ from mineru.backend.analysis.pdf import pipeline++ monkeypatch.setattr(config.model, "vlm", _settings(openai_server))+ monkeypatch.setattr(pipeline.PDFDocument, "classify", lambda self: resolved_mode)+ context = pipeline.HybridLocalModelContextSingleton().get_model()+ # 公式块在 TXT 下仍需 VLM 抽取,避免测试被原生正文跳过逻辑短路。+ context.layout_model.batch_predict.return_value = [[{"bbox": [20, 20, 250, 80], "label": "display_formula"}]]+ source = _pdf_input(tmp_path)+ result = (+ asyncio.run(parse_async(source, tier="standard", ocr_mode=ocr_mode))+ if async_mode+ else parse(source, tier="standard", ocr_mode=ocr_mode)+ )+ assert result.middle_json.extensions["mineru"]["parse_mode"] == resolved_mode+ assert any(body is not None for _, _, body in openai_server.requests)+ stderr = capsys.readouterr().err+ assert "VLM Predict" in stderr+ assert "100%" in stderr+ assert "External Layout Extraction" not in stderr