fix: resolve cross-platform test failures on Windows and Ubuntu
- Add proper cross-platform path handling with Path.resolve() - Fix file encoding issues by explicitly using UTF-8 - Correct mock paths to use google.generativeai instead of gemini_server.genai - Create setup.py for proper package installation in CI - Add conftest.py with Windows asyncio compatibility - Update CI workflow to install package with pip install -e . - Add import tests to verify package installation - Set PYTHONPATH in test environment - Simplify import mechanism in tests These changes ensure tests pass consistently across Windows, Ubuntu, and macOS platforms. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -14,8 +14,7 @@ parent_dir = Path(__file__).resolve().parent.parent
|
||||
if str(parent_dir) not in sys.path:
|
||||
sys.path.insert(0, str(parent_dir))
|
||||
|
||||
try:
|
||||
from gemini_server import (
|
||||
from gemini_server import (
|
||||
GeminiChatRequest,
|
||||
CodeAnalysisRequest,
|
||||
read_file_content,
|
||||
@@ -25,27 +24,6 @@ try:
|
||||
DEVELOPER_SYSTEM_PROMPT,
|
||||
DEFAULT_MODEL
|
||||
)
|
||||
except ImportError as e:
|
||||
# If import fails, try alternative import method
|
||||
import importlib.util
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"gemini_server",
|
||||
parent_dir / "gemini_server.py"
|
||||
)
|
||||
gemini_server = importlib.util.module_from_spec(spec)
|
||||
sys.modules["gemini_server"] = gemini_server
|
||||
spec.loader.exec_module(gemini_server)
|
||||
|
||||
from gemini_server import (
|
||||
GeminiChatRequest,
|
||||
CodeAnalysisRequest,
|
||||
read_file_content,
|
||||
prepare_code_context,
|
||||
handle_list_tools,
|
||||
handle_call_tool,
|
||||
DEVELOPER_SYSTEM_PROMPT,
|
||||
DEFAULT_MODEL
|
||||
)
|
||||
|
||||
|
||||
class TestModels:
|
||||
|
||||
45
tests/test_imports.py
Normal file
45
tests/test_imports.py
Normal file
@@ -0,0 +1,45 @@
|
||||
"""
|
||||
Test that imports work correctly when package is installed
|
||||
This helps verify CI setup is correct
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def test_direct_import():
|
||||
"""Test that gemini_server can be imported directly"""
|
||||
try:
|
||||
import gemini_server
|
||||
assert hasattr(gemini_server, 'GeminiChatRequest')
|
||||
assert hasattr(gemini_server, 'CodeAnalysisRequest')
|
||||
assert hasattr(gemini_server, 'handle_list_tools')
|
||||
assert hasattr(gemini_server, 'handle_call_tool')
|
||||
except ImportError as e:
|
||||
pytest.fail(f"Failed to import gemini_server: {e}")
|
||||
|
||||
|
||||
def test_from_import():
|
||||
"""Test that specific items can be imported from gemini_server"""
|
||||
try:
|
||||
from gemini_server import (
|
||||
GeminiChatRequest,
|
||||
CodeAnalysisRequest,
|
||||
DEFAULT_MODEL,
|
||||
DEVELOPER_SYSTEM_PROMPT
|
||||
)
|
||||
assert GeminiChatRequest is not None
|
||||
assert CodeAnalysisRequest is not None
|
||||
assert isinstance(DEFAULT_MODEL, str)
|
||||
assert isinstance(DEVELOPER_SYSTEM_PROMPT, str)
|
||||
except ImportError as e:
|
||||
pytest.fail(f"Failed to import from gemini_server: {e}")
|
||||
|
||||
|
||||
def test_google_generativeai_import():
|
||||
"""Test that google.generativeai can be imported"""
|
||||
try:
|
||||
import google.generativeai as genai
|
||||
assert hasattr(genai, 'GenerativeModel')
|
||||
assert hasattr(genai, 'configure')
|
||||
except ImportError as e:
|
||||
pytest.fail(f"Failed to import google.generativeai: {e}")
|
||||
Reference in New Issue
Block a user