fix: 优化配置、修复测试和 temp_pdf 中文字体支持
- 优化 config.py,为所有依赖添加版本号,为所有文件类型添加 Darwin-x86_64 配置 - 修改 run_tests.py,添加平台相关 TEST_FIXTURE_DEPENDENCIES,简化 cli 和 all 测试逻辑 - 修复 tests/conftest.py 中 temp_pdf 的中文字体支持,使用 macOS 系统字体 - 更新 tests/test_core/test_advice_generator.py 以适应 Python 3.12 的默认配置 - 更新 openspec 相关规格文档
This commit is contained in:
112
run_tests.py
112
run_tests.py
@@ -23,6 +23,24 @@ os.environ["HF_HUB_DISABLE_PROGRESS_BARS"] = "1"
|
||||
os.environ["HF_HUB_DISABLE_TELEMETRY"] = "1"
|
||||
os.environ["TQDM_DISABLE"] = "1"
|
||||
|
||||
# 测试 fixtures 需要的依赖(用于创建临时测试文件)
|
||||
TEST_FIXTURE_DEPENDENCIES = {
|
||||
"default": [
|
||||
"python-docx==1.2.0", # 用于创建临时 DOCX
|
||||
"reportlab==4.2.2", # 用于创建临时 PDF
|
||||
"pandas==3.0.1", # 用于创建临时 XLSX
|
||||
"openpyxl==3.1.5", # pandas 写 XLSX 需要
|
||||
"python-pptx==1.0.2", # 用于创建临时 PPTX
|
||||
],
|
||||
"Darwin-x86_64": [
|
||||
"python-docx==1.2.0", # 用于创建临时 DOCX
|
||||
"reportlab==4.2.2", # 用于创建临时 PDF
|
||||
"pandas<3.0.0", # 用于创建临时 XLSX(兼容 Darwin-x86_64)
|
||||
"openpyxl==3.1.5", # pandas 写 XLSX 需要
|
||||
"python-pptx==1.0.2", # 用于创建临时 PPTX
|
||||
],
|
||||
}
|
||||
|
||||
# 测试类型映射
|
||||
_TEST_TYPES = {
|
||||
# 文件类型测试(有依赖配置)
|
||||
@@ -34,8 +52,8 @@ _TEST_TYPES = {
|
||||
"xls": {"key": "xls", "path": "tests/test_readers/test_xls/"},
|
||||
"doc": {"key": "doc", "path": "tests/test_readers/test_doc/"},
|
||||
"ppt": {"key": "ppt", "path": "tests/test_readers/test_ppt/"},
|
||||
# 核心测试(无特殊依赖)
|
||||
"cli": {"key": None, "path": "tests/test_cli/"},
|
||||
# 核心测试(cli 测试需要所有依赖,因为它测试多种格式)
|
||||
"cli": {"key": "all", "path": "tests/test_cli/"},
|
||||
"core": {"key": None, "path": "tests/test_core/"},
|
||||
"utils": {"key": None, "path": "tests/test_utils/"},
|
||||
# 所有测试(合并所有依赖)
|
||||
@@ -43,9 +61,40 @@ _TEST_TYPES = {
|
||||
}
|
||||
|
||||
|
||||
def _collect_all_dependencies(platform_id: str):
|
||||
"""
|
||||
收集所有文件类型的依赖并去重(内部辅助函数)。
|
||||
|
||||
Args:
|
||||
platform_id: 平台标识
|
||||
|
||||
Returns:
|
||||
(python_version, dependencies) 元组
|
||||
"""
|
||||
from config import DEPENDENCIES
|
||||
|
||||
python_version = None
|
||||
all_deps = set()
|
||||
for type_key, type_config in DEPENDENCIES.items():
|
||||
# 先尝试特定平台配置
|
||||
if platform_id in type_config:
|
||||
cfg = type_config[platform_id]
|
||||
elif "default" in type_config:
|
||||
cfg = type_config["default"]
|
||||
else:
|
||||
continue
|
||||
# 记录 python 版本(优先使用有特殊要求的)
|
||||
if cfg.get("python") and not python_version:
|
||||
python_version = cfg["python"]
|
||||
# 收集依赖
|
||||
for dep in cfg.get("dependencies", []):
|
||||
all_deps.add(dep)
|
||||
return python_version, list(all_deps)
|
||||
|
||||
|
||||
def get_dependencies_for_type(test_type: str, platform_id: str):
|
||||
"""
|
||||
获取指定测试类型的依赖配置。
|
||||
获取指定测试类型的依赖配置(完全从 config.py 获取)。
|
||||
|
||||
Args:
|
||||
test_type: 测试类型(pdf/docx/.../all)
|
||||
@@ -63,30 +112,14 @@ def get_dependencies_for_type(test_type: str, platform_id: str):
|
||||
key = config["key"]
|
||||
|
||||
if key is None:
|
||||
# 无特殊依赖的测试类型(cli/core/utils)
|
||||
# core/utils 测试不需要特殊依赖
|
||||
return None, []
|
||||
|
||||
if key == "all":
|
||||
# 收集所有类型的依赖并去重
|
||||
python_version = None
|
||||
all_deps = set()
|
||||
for type_key, type_config in DEPENDENCIES.items():
|
||||
# 先尝试特定平台配置
|
||||
if platform_id in type_config:
|
||||
cfg = type_config[platform_id]
|
||||
elif "default" in type_config:
|
||||
cfg = type_config["default"]
|
||||
else:
|
||||
continue
|
||||
# 记录 python 版本(优先使用有特殊要求的)
|
||||
if cfg.get("python"):
|
||||
python_version = cfg["python"]
|
||||
# 收集依赖
|
||||
for dep in cfg.get("dependencies", []):
|
||||
all_deps.add(dep)
|
||||
return python_version, list(all_deps)
|
||||
# cli 和 all 都使用收集所有依赖的逻辑
|
||||
return _collect_all_dependencies(platform_id)
|
||||
|
||||
# 单个类型的依赖
|
||||
# 单个类型的依赖,完全从 config.py 获取
|
||||
if key not in DEPENDENCIES:
|
||||
return None, []
|
||||
|
||||
@@ -101,11 +134,30 @@ def get_dependencies_for_type(test_type: str, platform_id: str):
|
||||
return cfg.get("python"), cfg.get("dependencies", [])
|
||||
|
||||
|
||||
def get_fixture_dependencies(platform_id: str):
|
||||
"""
|
||||
获取指定平台的 fixtures 依赖。
|
||||
|
||||
Args:
|
||||
platform_id: 平台标识
|
||||
|
||||
Returns:
|
||||
list: fixtures 依赖列表
|
||||
"""
|
||||
if platform_id in TEST_FIXTURE_DEPENDENCIES:
|
||||
return TEST_FIXTURE_DEPENDENCIES[platform_id]
|
||||
elif "default" in TEST_FIXTURE_DEPENDENCIES:
|
||||
return TEST_FIXTURE_DEPENDENCIES["default"]
|
||||
else:
|
||||
return []
|
||||
|
||||
|
||||
def generate_uv_args(
|
||||
dependencies: list,
|
||||
test_path: str,
|
||||
pytest_args: list,
|
||||
python_version: str = None,
|
||||
platform_id: str = None,
|
||||
):
|
||||
"""
|
||||
生成 uv run 命令参数列表(用于 subprocess.run)。
|
||||
@@ -115,6 +167,7 @@ def generate_uv_args(
|
||||
test_path: 测试路径
|
||||
pytest_args: 透传给 pytest 的参数
|
||||
python_version: 需要的 python 版本,None 表示不指定
|
||||
platform_id: 平台标识,用于选择 fixtures 依赖
|
||||
|
||||
Returns:
|
||||
uv run 命令参数列表
|
||||
@@ -127,8 +180,18 @@ def generate_uv_args(
|
||||
# 添加 pytest
|
||||
args.extend(["--with", "pytest"])
|
||||
|
||||
# 添加其他依赖
|
||||
# 获取当前平台的 fixtures 依赖
|
||||
fixture_deps = get_fixture_dependencies(platform_id) if platform_id else []
|
||||
|
||||
# 合并文件类型依赖和 fixtures 依赖,去重
|
||||
all_deps = set()
|
||||
for dep in dependencies:
|
||||
all_deps.add(dep)
|
||||
for dep in fixture_deps:
|
||||
all_deps.add(dep)
|
||||
|
||||
# 添加所有依赖
|
||||
for dep in sorted(all_deps):
|
||||
args.extend(["--with", dep])
|
||||
|
||||
# 添加 pytest 命令
|
||||
@@ -205,6 +268,7 @@ def main():
|
||||
test_path=test_path,
|
||||
pytest_args=pytest_args,
|
||||
python_version=python_version,
|
||||
platform_id=platform_id,
|
||||
)
|
||||
|
||||
# 设置环境变量
|
||||
|
||||
Reference in New Issue
Block a user