mirror of
https://github.com/lllin000/PaperForge.git
synced 2026-07-22 17:00:23 +00:00
- Update all pipeline.worker.scripts patches to paperforge.worker.* - Fix test_base_views.py and test_base_preservation.py imports - Update test_legacy_worker_compat.py for new module paths - Fix OCR test patches to target correct module namespaces
101 lines
3.7 KiB
Python
101 lines
3.7 KiB
Python
"""Tests for the 8-view Base generation system (Phase 3, Plan 01)."""
|
|
import pytest
|
|
from pathlib import Path
|
|
from paperforge.worker.base_views import (
|
|
build_base_views,
|
|
substitute_config_placeholders,
|
|
)
|
|
|
|
|
|
class TestBuildBaseViews:
|
|
def test_returns_exactly_8_views(self):
|
|
views = build_base_views("骨科")
|
|
assert len(views) == 8
|
|
|
|
def test_all_view_names_present(self):
|
|
views = build_base_views("骨科")
|
|
names = [v["name"] for v in views]
|
|
expected = [
|
|
"控制面板", "推荐分析", "待 OCR", "OCR 完成",
|
|
"待深度阅读", "深度阅读完成", "正式卡片", "全记录"
|
|
]
|
|
assert names == expected
|
|
|
|
def test_each_view_has_required_keys(self):
|
|
views = build_base_views("骨科")
|
|
for v in views:
|
|
assert "name" in v
|
|
assert "order" in v
|
|
assert "filter" in v
|
|
assert isinstance(v["order"], list)
|
|
assert len(v["order"]) > 0
|
|
|
|
def test_control_panel_has_no_filter(self):
|
|
views = build_base_views("骨科")
|
|
cp = next(v for v in views if v["name"] == "控制面板")
|
|
assert cp["filter"] is None
|
|
|
|
def test_pending_ocr_filter(self):
|
|
views = build_base_views("骨科")
|
|
pending = next(v for v in views if v["name"] == "待 OCR")
|
|
assert 'do_ocr = true' in pending["filter"]
|
|
assert 'ocr_status = "pending"' in pending["filter"]
|
|
|
|
def test_ocr_done_filter(self):
|
|
views = build_base_views("骨科")
|
|
done = next(v for v in views if v["name"] == "OCR 完成")
|
|
assert 'ocr_status = "done"' in done["filter"]
|
|
|
|
def test_deep_reading_pending_filter(self):
|
|
views = build_base_views("骨科")
|
|
pending = next(v for v in views if v["name"] == "待深度阅读")
|
|
assert "analyze = true" in pending["filter"]
|
|
assert 'ocr_status = "done"' in pending["filter"]
|
|
assert 'deep_reading_status = "pending"' in pending["filter"]
|
|
|
|
|
|
class TestSubstituteConfigPlaceholders:
|
|
def test_substitutes_library_records(self, tmp_path):
|
|
content = "${LIBRARY_RECORDS}/骨科"
|
|
vault = tmp_path / "Vault"
|
|
vault.mkdir()
|
|
lib_rec = vault / "03_Resources" / "LiteratureControl" / "library-records"
|
|
lib_rec.mkdir(parents=True)
|
|
result = substitute_config_placeholders(
|
|
content,
|
|
{"library_records": lib_rec, "vault": vault}
|
|
)
|
|
assert "${LIBRARY_RECORDS}" not in result
|
|
assert "03_Resources/LiteratureControl/library-records" in result
|
|
|
|
def test_substitutes_multiple_placeholders(self, tmp_path):
|
|
content = "${LIBRARY_RECORDS} and ${LITERATURE}"
|
|
vault = tmp_path / "Vault"
|
|
vault.mkdir()
|
|
lib_rec = vault / "LR"
|
|
lit = vault / "LIT"
|
|
lib_rec.mkdir()
|
|
lit.mkdir()
|
|
result = substitute_config_placeholders(
|
|
content,
|
|
{"library_records": lib_rec, "literature": lit, "vault": vault}
|
|
)
|
|
assert "${LIBRARY_RECORDS}" not in result
|
|
assert "${LITERATURE}" not in result
|
|
|
|
def test_unknown_placeholder_unchanged(self):
|
|
content = "${UNKNOWN_PLACEHOLDER}/骨科"
|
|
result = substitute_config_placeholders(content, {})
|
|
assert "${UNKNOWN_PLACEHOLDER}" in result
|
|
|
|
def test_backslash_conversion(self, tmp_path):
|
|
content = "${LIBRARY_RECORDS}"
|
|
vault = tmp_path / "Vault"
|
|
vault.mkdir()
|
|
lib_rec = vault / "LR"
|
|
lib_rec.mkdir()
|
|
result = substitute_config_placeholders(
|
|
content,
|
|
{"library_records": lib_rec, "vault": vault}
|
|
)
|
|
assert "\\" not in result # Should use forward slash
|