2025-11-04 05:17:27 +01:00
|
|
|
import os
|
|
|
|
|
import tempfile
|
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
2025-11-04 08:09:12 +01:00
|
|
|
import pytest
|
|
|
|
|
|
2025-11-04 05:17:27 +01:00
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def temp_dir():
|
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
|
|
|
yield tmpdir
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def mock_api_response():
|
|
|
|
|
return {
|
2025-11-04 08:09:12 +01:00
|
|
|
"choices": [{"message": {"role": "assistant", "content": "Test response"}}],
|
|
|
|
|
"usage": {"prompt_tokens": 10, "completion_tokens": 5, "total_tokens": 15},
|
2025-11-04 05:17:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def mock_args():
|
|
|
|
|
args = MagicMock()
|
|
|
|
|
args.message = None
|
|
|
|
|
args.model = None
|
|
|
|
|
args.api_url = None
|
|
|
|
|
args.model_list_url = None
|
|
|
|
|
args.interactive = False
|
|
|
|
|
args.verbose = False
|
|
|
|
|
args.no_syntax = False
|
|
|
|
|
args.include_env = False
|
|
|
|
|
args.context = None
|
|
|
|
|
args.api_mode = False
|
|
|
|
|
return args
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def sample_context_file(temp_dir):
|
2025-11-04 08:09:12 +01:00
|
|
|
context_path = os.path.join(temp_dir, ".rcontext.txt")
|
|
|
|
|
with open(context_path, "w") as f:
|
|
|
|
|
f.write("Sample context content\n")
|
2025-11-04 05:17:27 +01:00
|
|
|
return context_path
|