Files
windyboy f7e54692a9 Initial project setup: Obsidian intelligent journal organizer
- Add core agent architecture with Command + Skill pattern
- Implement Claude API integration for content analysis
- Add Obsidian REST API integration for vault operations
- Create conversational interface (v2.0) with natural language processing
- Add comprehensive configuration management and validation
- Include project documentation and developer guides
- Set up testing framework with unit, integration, and property tests
- Add Kiro specs for Claude API configuration and code quality improvements
- Configure project steering files for development guidelines
2025-12-31 17:55:10 +08:00

138 lines
3.4 KiB
Python

"""
Pytest configuration and shared fixtures for the journal organizer test suite.
"""
import pytest
import asyncio
import tempfile
import shutil
import sys
from pathlib import Path
from typing import Dict, Any, AsyncGenerator
from unittest.mock import Mock, AsyncMock
import yaml
# Add the project root to Python path for imports
sys.path.insert(0, str(Path(__file__).parent.parent))
from agent_core import Agent, SkillResult
from error_handling import ErrorHandler
@pytest.fixture(scope="session")
def event_loop():
"""Create an instance of the default event loop for the test session."""
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()
@pytest.fixture
def temp_dir():
"""Create a temporary directory for test files."""
temp_dir = tempfile.mkdtemp()
yield Path(temp_dir)
shutil.rmtree(temp_dir)
@pytest.fixture
def sample_config(temp_dir: Path) -> Dict[str, Any]:
"""Create a sample configuration for testing."""
vault_path = temp_dir / "test_vault"
vault_path.mkdir()
config = {
"obsidian": {
"vault_path": str(vault_path),
"rest_api": {
"url": "https://localhost:27123",
"api_key": "test-api-key",
"verify_ssl": False
}
},
"claude": {
"api_key": "test-claude-key",
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 4096
},
"journal": {
"daily_notes_folder": "Daily",
"date_format": "YYYY-MM-DD"
},
"output": {
"experiences_folder": "Knowledge/Experiences",
"lessons_folder": "Knowledge/Lessons"
}
}
return config
@pytest.fixture
def config_file(temp_dir: Path, sample_config: Dict[str, Any]) -> Path:
"""Create a temporary config file for testing."""
config_path = temp_dir / "test_config.yaml"
with open(config_path, 'w') as f:
yaml.dump(sample_config, f)
return config_path
@pytest.fixture
def mock_skill_result():
"""Create a mock SkillResult for testing."""
return SkillResult(
success=True,
data={"test": "data"},
message="Test operation completed"
)
@pytest.fixture
def mock_error_handler():
"""Create a mock ErrorHandler for testing."""
return Mock(spec=ErrorHandler)
@pytest.fixture
async def mock_aiohttp_session():
"""Create a mock aiohttp session for testing."""
session = AsyncMock()
session.get = AsyncMock()
session.post = AsyncMock()
session.put = AsyncMock()
session.delete = AsyncMock()
return session
@pytest.fixture
def sample_journal_content():
"""Sample journal content for testing."""
return """# 2024-01-15 Daily Journal
## 今天的经历
- 完成了项目的重要里程碑
- 与团队进行了有效的沟通
## 学到的东西
- 学会了新的Python异步编程技巧
- 理解了更好的错误处理模式
## 遇到的问题
- API调用偶尔超时
- 配置文件格式需要改进
## 明天的计划
- 优化API调用的重试机制
- 更新文档
"""
@pytest.fixture
def sample_obsidian_response():
"""Sample Obsidian API response for testing."""
return {
"content": "# Test Note\n\nThis is test content.",
"stat": {
"ctime": 1642204800000,
"mtime": 1642204800000,
"size": 35
}
}