fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解 - 修复缺失的urllib.parse导入
This commit is contained in:
@@ -20,6 +20,7 @@ from search_manager import (
|
||||
# 添加 backend 到路径
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
def test_fulltext_search():
|
||||
"""测试全文搜索"""
|
||||
print("\n" + "=" * 60)
|
||||
@@ -34,7 +35,7 @@ def test_fulltext_search():
|
||||
content_id="test_entity_1",
|
||||
content_type="entity",
|
||||
project_id="test_project",
|
||||
text="这是一个测试实体,用于验证全文搜索功能。支持关键词高亮显示。"
|
||||
text="这是一个测试实体,用于验证全文搜索功能。支持关键词高亮显示。",
|
||||
)
|
||||
print(f" 索引创建: {'✓ 成功' if success else '✗ 失败'}")
|
||||
|
||||
@@ -56,15 +57,13 @@ def test_fulltext_search():
|
||||
|
||||
# 测试高亮
|
||||
print("\n4. 测试文本高亮...")
|
||||
highlighted = search.highlight_text(
|
||||
"这是一个测试实体,用于验证全文搜索功能。",
|
||||
"测试 全文"
|
||||
)
|
||||
highlighted = search.highlight_text("这是一个测试实体,用于验证全文搜索功能。", "测试 全文")
|
||||
print(f" 高亮结果: {highlighted}")
|
||||
|
||||
print("\n✓ 全文搜索测试完成")
|
||||
return True
|
||||
|
||||
|
||||
def test_semantic_search():
|
||||
"""测试语义搜索"""
|
||||
print("\n" + "=" * 60)
|
||||
@@ -93,13 +92,14 @@ def test_semantic_search():
|
||||
content_id="test_content_1",
|
||||
content_type="transcript",
|
||||
project_id="test_project",
|
||||
text="这是用于语义搜索测试的文本内容。"
|
||||
text="这是用于语义搜索测试的文本内容。",
|
||||
)
|
||||
print(f" 索引创建: {'✓ 成功' if success else '✗ 失败'}")
|
||||
|
||||
print("\n✓ 语义搜索测试完成")
|
||||
return True
|
||||
|
||||
|
||||
def test_entity_path_discovery():
|
||||
"""测试实体路径发现"""
|
||||
print("\n" + "=" * 60)
|
||||
@@ -118,6 +118,7 @@ def test_entity_path_discovery():
|
||||
print("\n✓ 实体路径发现测试完成")
|
||||
return True
|
||||
|
||||
|
||||
def test_knowledge_gap_detection():
|
||||
"""测试知识缺口识别"""
|
||||
print("\n" + "=" * 60)
|
||||
@@ -136,6 +137,7 @@ def test_knowledge_gap_detection():
|
||||
print("\n✓ 知识缺口识别测试完成")
|
||||
return True
|
||||
|
||||
|
||||
def test_cache_manager():
|
||||
"""测试缓存管理器"""
|
||||
print("\n" + "=" * 60)
|
||||
@@ -156,11 +158,9 @@ def test_cache_manager():
|
||||
print(" ✓ 获取缓存: {value}")
|
||||
|
||||
# 批量操作
|
||||
cache.set_many({
|
||||
"batch_key_1": "value1",
|
||||
"batch_key_2": "value2",
|
||||
"batch_key_3": "value3"
|
||||
}, ttl=60)
|
||||
cache.set_many(
|
||||
{"batch_key_1": "value1", "batch_key_2": "value2", "batch_key_3": "value3"}, ttl=60
|
||||
)
|
||||
print(" ✓ 批量设置缓存")
|
||||
|
||||
_ = cache.get_many(["batch_key_1", "batch_key_2", "batch_key_3"])
|
||||
@@ -185,6 +185,7 @@ def test_cache_manager():
|
||||
print("\n✓ 缓存管理器测试完成")
|
||||
return True
|
||||
|
||||
|
||||
def test_task_queue():
|
||||
"""测试任务队列"""
|
||||
print("\n" + "=" * 60)
|
||||
@@ -207,8 +208,7 @@ def test_task_queue():
|
||||
|
||||
# 提交任务
|
||||
task_id = queue.submit(
|
||||
task_type="test_task",
|
||||
payload={"test": "data", "timestamp": time.time()}
|
||||
task_type="test_task", payload={"test": "data", "timestamp": time.time()}
|
||||
)
|
||||
print(" ✓ 提交任务: {task_id}")
|
||||
|
||||
@@ -226,6 +226,7 @@ def test_task_queue():
|
||||
print("\n✓ 任务队列测试完成")
|
||||
return True
|
||||
|
||||
|
||||
def test_performance_monitor():
|
||||
"""测试性能监控"""
|
||||
print("\n" + "=" * 60)
|
||||
@@ -242,7 +243,7 @@ def test_performance_monitor():
|
||||
metric_type="api_response",
|
||||
duration_ms=50 + i * 10,
|
||||
endpoint="/api/v1/test",
|
||||
metadata={"test": True}
|
||||
metadata={"test": True},
|
||||
)
|
||||
|
||||
for i in range(3):
|
||||
@@ -250,7 +251,7 @@ def test_performance_monitor():
|
||||
metric_type="db_query",
|
||||
duration_ms=20 + i * 5,
|
||||
endpoint="SELECT test",
|
||||
metadata={"test": True}
|
||||
metadata={"test": True},
|
||||
)
|
||||
|
||||
print(" ✓ 记录了 8 个测试指标")
|
||||
@@ -263,13 +264,16 @@ def test_performance_monitor():
|
||||
print(f" 最大响应时间: {stats['overall']['max_duration_ms']} ms")
|
||||
|
||||
print("\n3. 按类型统计:")
|
||||
for type_stat in stats.get('by_type', []):
|
||||
print(f" {type_stat['type']}: {type_stat['count']} 次, "
|
||||
f"平均 {type_stat['avg_duration_ms']} ms")
|
||||
for type_stat in stats.get("by_type", []):
|
||||
print(
|
||||
f" {type_stat['type']}: {type_stat['count']} 次, "
|
||||
f"平均 {type_stat['avg_duration_ms']} ms"
|
||||
)
|
||||
|
||||
print("\n✓ 性能监控测试完成")
|
||||
return True
|
||||
|
||||
|
||||
def test_search_manager():
|
||||
"""测试搜索管理器"""
|
||||
print("\n" + "=" * 60)
|
||||
@@ -290,6 +294,7 @@ def test_search_manager():
|
||||
print("\n✓ 搜索管理器测试完成")
|
||||
return True
|
||||
|
||||
|
||||
def test_performance_manager():
|
||||
"""测试性能管理器"""
|
||||
print("\n" + "=" * 60)
|
||||
@@ -314,6 +319,7 @@ def test_performance_manager():
|
||||
print("\n✓ 性能管理器测试完成")
|
||||
return True
|
||||
|
||||
|
||||
def run_all_tests():
|
||||
"""运行所有测试"""
|
||||
print("\n" + "=" * 60)
|
||||
@@ -400,6 +406,7 @@ def run_all_tests():
|
||||
|
||||
return passed == total
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = run_all_tests()
|
||||
sys.exit(0 if success else 1)
|
||||
|
||||
Reference in New Issue
Block a user