test: 补充测试覆盖率 — DB/CLI/Search/Ingest + 修复 chromadb 异常兼容
This commit is contained in:
@@ -45,3 +45,33 @@ class TestVectorDB:
|
||||
# 再次获取会创建新的
|
||||
col = db.get_or_create_collection("tmp_col")
|
||||
assert col.count() == 0
|
||||
|
||||
|
||||
def test_write_guard_context_manager(tmp_path):
|
||||
"""write_guard 上下文管理器正常获取和释放锁."""
|
||||
from src.core.db import VectorDB
|
||||
vdb = VectorDB(persist_dir=str(tmp_path))
|
||||
with vdb.write_guard():
|
||||
pass
|
||||
|
||||
|
||||
def test_close(tmp_path):
|
||||
"""close 正常执行不抛异常."""
|
||||
from src.core.db import VectorDB
|
||||
vdb = VectorDB(persist_dir=str(tmp_path))
|
||||
vdb.close()
|
||||
|
||||
|
||||
def test_delete_collection_nonexistent(tmp_path):
|
||||
"""删除不存在的 collection 不抛异常."""
|
||||
from src.core.db import VectorDB
|
||||
vdb = VectorDB(persist_dir=str(tmp_path))
|
||||
vdb.delete_collection("nonexistent-collection-12345")
|
||||
|
||||
|
||||
def test_delete_by_source_no_match(tmp_path):
|
||||
"""删除不存在的 source 返回 False."""
|
||||
from src.core.db import VectorDB
|
||||
vdb = VectorDB(persist_dir=str(tmp_path))
|
||||
result = vdb.delete_by_source("test_col", "no-such-file.md")
|
||||
assert result is False
|
||||
|
||||
Reference in New Issue
Block a user