124 lines
3.4 KiB
Python
124 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test workspace rename functionality.
|
|
"""
|
|
import sys
|
|
import os
|
|
import asyncio
|
|
from pathlib import Path
|
|
|
|
# Add LightRAG-main to path
|
|
sys.path.insert(0, 'LightRAG-main')
|
|
|
|
from lightrag.api.workspace_manager import WorkspaceManager
|
|
from lightrag.api.config import global_args
|
|
|
|
# Mock args
|
|
class Args:
|
|
working_dir = 'rag_storage_test'
|
|
input_dir = 'inputs_test'
|
|
workspace = ''
|
|
llm_binding = 'openai'
|
|
embedding_binding = 'openai'
|
|
rerank_binding = 'null'
|
|
llm_model = 'gpt-3.5-turbo'
|
|
embedding_model = 'text-embedding-ada-002'
|
|
embedding_dim = 1536
|
|
llm_binding_host = None
|
|
embedding_binding_host = None
|
|
llm_binding_api_key = None
|
|
embedding_binding_api_key = None
|
|
rerank_binding_api_key = None
|
|
rerank_model = None
|
|
rerank_binding_host = None
|
|
max_async = 1
|
|
summary_max_tokens = 100
|
|
summary_context_size = 100
|
|
chunk_size = 512
|
|
chunk_overlap_size = 50
|
|
kv_storage = 'sqlite'
|
|
graph_storage = 'sqlite'
|
|
vector_storage = 'qdrant'
|
|
doc_status_storage = 'sqlite'
|
|
enable_llm_cache_for_extract = False
|
|
enable_llm_cache = False
|
|
max_graph_nodes = 1000
|
|
cosine_threshold = 0.7
|
|
min_rerank_score = 0.0
|
|
related_chunk_number = 5
|
|
embedding_func_max_async = 1
|
|
embedding_batch_num = 1
|
|
max_parallel_insert = 1
|
|
summary_language = 'en'
|
|
force_llm_summary_on_merge = False
|
|
entity_types = ''
|
|
|
|
async def test_rename():
|
|
# Clean up previous test directories
|
|
import shutil
|
|
if Path('rag_storage_test').exists():
|
|
shutil.rmtree('rag_storage_test')
|
|
if Path('inputs_test').exists():
|
|
shutil.rmtree('inputs_test')
|
|
|
|
args = Args()
|
|
manager = WorkspaceManager(args)
|
|
|
|
print("Creating workspace 'test_old'...")
|
|
manager.create_workspace('test_old')
|
|
|
|
# Verify it exists
|
|
assert manager.workspace_exists('test_old')
|
|
print("Workspace created.")
|
|
|
|
# Rename
|
|
print("Renaming 'test_old' to 'test_new'...")
|
|
await manager.rename_workspace('test_old', 'test_new')
|
|
|
|
# Verify old doesn't exist
|
|
assert not manager.workspace_exists('test_old')
|
|
assert manager.workspace_exists('test_new')
|
|
print("Rename successful.")
|
|
|
|
# List workspaces
|
|
workspaces = manager.list_workspaces()
|
|
print(f"Workspaces: {workspaces}")
|
|
assert 'test_new' in workspaces
|
|
|
|
# Clean up
|
|
await manager.delete_workspace('test_new')
|
|
print("Cleanup done.")
|
|
|
|
# Test error cases
|
|
print("\nTesting error cases...")
|
|
# Rename non-existent workspace
|
|
try:
|
|
await manager.rename_workspace('nonexistent', 'new')
|
|
print("ERROR: Should have raised ValueError")
|
|
except ValueError as e:
|
|
print(f"Expected error: {e}")
|
|
|
|
# Rename to existing workspace
|
|
manager.create_workspace('existing')
|
|
manager.create_workspace('other')
|
|
try:
|
|
await manager.rename_workspace('existing', 'other')
|
|
print("ERROR: Should have raised ValueError")
|
|
except ValueError as e:
|
|
print(f"Expected error: {e}")
|
|
|
|
# Invalid new name
|
|
try:
|
|
await manager.rename_workspace('existing', 'invalid name!')
|
|
print("ERROR: Should have raised ValueError")
|
|
except ValueError as e:
|
|
print(f"Expected error: {e}")
|
|
|
|
# Clean up
|
|
await manager.delete_workspace('existing')
|
|
await manager.delete_workspace('other')
|
|
|
|
print("\nAll tests passed!")
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(test_rename()) |