feat: 实现CutThenThink P0阶段核心功能
项目初始化 - 创建完整项目结构(src/, data/, docs/, examples/, tests/) - 配置requirements.txt依赖 - 创建.gitignore P0基础框架 - 数据库模型:Record模型,6种分类类型 - 配置管理:YAML配置,支持AI/OCR/云存储/UI配置 - OCR模块:PaddleOCR本地识别,支持云端扩展 - AI模块:支持OpenAI/Claude/通义/Ollama,6种分类 - 存储模块:完整CRUD,搜索,统计,导入导出 - 主窗口框架:侧边栏导航,米白配色方案 - 图片处理:截图/剪贴板/文件选择/图片预览 - 处理流程整合:OCR→AI→存储串联,Markdown展示,剪贴板复制 - 分类浏览:卡片网格展示,分类筛选,搜索,详情查看 技术栈 - PyQt6 + SQLAlchemy + PaddleOCR + OpenAI/Claude SDK - 共47个Python文件,4000+行代码 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
167
tests/test_storage.py
Normal file
167
tests/test_storage.py
Normal file
@@ -0,0 +1,167 @@
|
||||
"""
|
||||
存储模块测试脚本
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# 添加项目根目录到路径
|
||||
project_root = Path(__file__).parent.parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
from src.core.storage import Storage
|
||||
|
||||
|
||||
def test_storage():
|
||||
"""测试存储模块的所有功能"""
|
||||
|
||||
print("=" * 60)
|
||||
print("存储模块测试")
|
||||
print("=" * 60)
|
||||
|
||||
# 创建存储实例(使用临时测试目录)
|
||||
test_data_dir = Path(__file__).parent.parent / "data" / "test"
|
||||
storage = Storage(str(test_data_dir))
|
||||
|
||||
# 测试 1: 创建记录
|
||||
print("\n[测试 1] 创建记录")
|
||||
print("-" * 60)
|
||||
|
||||
record1 = storage.create(
|
||||
title="第一篇笔记",
|
||||
content="这是第一篇笔记的内容",
|
||||
category="工作",
|
||||
tags=["重要", "待办"]
|
||||
)
|
||||
print(f"✓ 创建记录 1: {record1['id']} - {record1['title']}")
|
||||
|
||||
record2 = storage.create(
|
||||
title="学习 Python",
|
||||
content="Python 是一门强大的编程语言",
|
||||
category="学习",
|
||||
tags=["编程", "Python"]
|
||||
)
|
||||
print(f"✓ 创建记录 2: {record2['id']} - {record2['title']}")
|
||||
|
||||
record3 = storage.create(
|
||||
title="购物清单",
|
||||
content="牛奶、面包、鸡蛋",
|
||||
category="生活",
|
||||
tags=["购物"]
|
||||
)
|
||||
print(f"✓ 创建记录 3: {record3['id']} - {record3['title']}")
|
||||
|
||||
# 测试 2: 查询单个记录
|
||||
print("\n[测试 2] 查询单个记录")
|
||||
print("-" * 60)
|
||||
|
||||
found_record = storage.get_by_id(record1["id"])
|
||||
print(f"✓ 查询记录 ID {record1['id']}: {found_record['title']}")
|
||||
|
||||
# 测试 3: 查询所有记录
|
||||
print("\n[测试 3] 查询所有记录")
|
||||
print("-" * 60)
|
||||
|
||||
all_records = storage.get_all()
|
||||
print(f"✓ 共有 {len(all_records)} 条记录:")
|
||||
for r in all_records:
|
||||
print(f" - {r['id']}: {r['title']} [{r['category']}]")
|
||||
|
||||
# 测试 4: 按分类查询
|
||||
print("\n[测试 4] 按分类查询")
|
||||
print("-" * 60)
|
||||
|
||||
work_records = storage.get_by_category("工作")
|
||||
print(f"✓ '工作' 分类下的记录 ({len(work_records)} 条):")
|
||||
for r in work_records:
|
||||
print(f" - {r['title']}")
|
||||
|
||||
# 测试 5: 获取所有分类
|
||||
print("\n[测试 5] 获取所有分类")
|
||||
print("-" * 60)
|
||||
|
||||
categories = storage.get_categories()
|
||||
print(f"✓ 所有分类 ({len(categories)} 个):")
|
||||
for cat in categories:
|
||||
print(f" - {cat}")
|
||||
|
||||
# 测试 6: 搜索功能
|
||||
print("\n[测试 6] 搜索功能")
|
||||
print("-" * 60)
|
||||
|
||||
# 搜索标题
|
||||
results = storage.search("Python")
|
||||
print(f"✓ 搜索 'Python' ({len(results)} 条结果):")
|
||||
for r in results:
|
||||
print(f" - {r['title']}")
|
||||
|
||||
# 搜索内容
|
||||
results = storage.search("牛奶")
|
||||
print(f"✓ 搜索 '牛奶' ({len(results)} 条结果):")
|
||||
for r in results:
|
||||
print(f" - {r['title']}")
|
||||
|
||||
# 搜索标签
|
||||
results = storage.search("重要")
|
||||
print(f"✓ 搜索 '重要' ({len(results)} 条结果):")
|
||||
for r in results:
|
||||
print(f" - {r['title']}")
|
||||
|
||||
# 测试 7: 更新记录
|
||||
print("\n[测试 7] 更新记录")
|
||||
print("-" * 60)
|
||||
|
||||
updated_record = storage.update(
|
||||
record1["id"],
|
||||
title="第一篇笔记(已更新)",
|
||||
content="这是更新后的内容"
|
||||
)
|
||||
print(f"✓ 更新记录: {updated_record['id']}")
|
||||
print(f" 新标题: {updated_record['title']}")
|
||||
print(f" 更新时间: {updated_record['updated_at']}")
|
||||
|
||||
# 测试 8: 获取统计信息
|
||||
print("\n[测试 8] 获取统计信息")
|
||||
print("-" * 60)
|
||||
|
||||
stats = storage.get_stats()
|
||||
print(f"✓ 统计信息:")
|
||||
print(f" - 总记录数: {stats['total_records']}")
|
||||
print(f" - 总分类数: {stats['total_categories']}")
|
||||
print(f" - 各分类记录数:")
|
||||
for cat, count in stats['categories'].items():
|
||||
print(f" · {cat}: {count}")
|
||||
|
||||
# 测试 9: 删除记录
|
||||
print("\n[测试 9] 删除记录")
|
||||
print("-" * 60)
|
||||
|
||||
delete_success = storage.delete(record3["id"])
|
||||
print(f"✓ 删除记录 {record3['id']}: {'成功' if delete_success else '失败'}")
|
||||
|
||||
remaining_records = storage.get_all()
|
||||
print(f" 剩余记录数: {len(remaining_records)}")
|
||||
|
||||
# 测试 10: 导入导出
|
||||
print("\n[测试 10] 导入导出")
|
||||
print("-" * 60)
|
||||
|
||||
exported_data = storage.export_data()
|
||||
print(f"✓ 导出数据: {len(exported_data)} 条记录")
|
||||
|
||||
# 创建新的存储实例测试导入
|
||||
test_import_dir = Path(__file__).parent.parent / "data" / "test_import"
|
||||
import_storage = Storage(str(test_import_dir))
|
||||
|
||||
imported_count = import_storage.import_data(exported_data, merge=False)
|
||||
print(f"✓ 导入数据: {imported_count} 条记录")
|
||||
|
||||
imported_records = import_storage.get_all()
|
||||
print(f" 导入后记录数: {len(imported_records)}")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("所有测试完成!")
|
||||
print("=" * 60)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_storage()
|
||||
Reference in New Issue
Block a user