fix: resolve CI linting errors - remove unused imports
This commit is contained in:
108
app/codexchange-cli/tests/conftest.py
Normal file
108
app/codexchange-cli/tests/conftest.py
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
import pytest
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
from codexchange.models import Language, ConversionRequest, ConversionResult
|
||||||
|
from codexchange.config import ConfigSettings
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_python_code():
|
||||||
|
"""Sample Python code for testing."""
|
||||||
|
return '''def hello_world():
|
||||||
|
"""Print a greeting message."""
|
||||||
|
print("Hello, World!")
|
||||||
|
|
||||||
|
# This is a comment
|
||||||
|
def add(a, b):
|
||||||
|
"""Add two numbers."""
|
||||||
|
return a + b
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_javascript_code():
|
||||||
|
"""Sample JavaScript code for testing."""
|
||||||
|
return '''function helloWorld() {
|
||||||
|
// Print a greeting message
|
||||||
|
console.log("Hello, World!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is a comment
|
||||||
|
function add(a, b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def sample_typescript_code():
|
||||||
|
"""Sample TypeScript code for testing."""
|
||||||
|
return '''function helloWorld(): void {
|
||||||
|
// Print a greeting message
|
||||||
|
console.log("Hello, World!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is a comment
|
||||||
|
function add(a: number, b: number): number {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_ollama_service():
|
||||||
|
"""Mock Ollama service for testing."""
|
||||||
|
mock_service = MagicMock()
|
||||||
|
mock_service.test_connection.return_value = True
|
||||||
|
mock_service.list_models.return_value = []
|
||||||
|
mock_service.generate.return_value = "converted code"
|
||||||
|
return mock_service
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_config():
|
||||||
|
"""Mock configuration for testing."""
|
||||||
|
return ConfigSettings(
|
||||||
|
ollama_host="http://localhost:11434",
|
||||||
|
default_model="codellama",
|
||||||
|
timeout=300,
|
||||||
|
verbose=False
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def conversion_request(sample_python_code):
|
||||||
|
"""Sample conversion request for testing."""
|
||||||
|
return ConversionRequest(
|
||||||
|
source_code=sample_python_code,
|
||||||
|
source_language=Language.PYTHON,
|
||||||
|
target_language=Language.JAVASCRIPT,
|
||||||
|
model="codellama"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def successful_conversion_result(sample_python_code):
|
||||||
|
"""Sample successful conversion result for testing."""
|
||||||
|
return ConversionResult(
|
||||||
|
success=True,
|
||||||
|
converted_code="// Converted from Python\nconsole.log('Hello');",
|
||||||
|
original_code=sample_python_code,
|
||||||
|
source_language=Language.PYTHON,
|
||||||
|
target_language=Language.JAVASCRIPT,
|
||||||
|
model="codellama",
|
||||||
|
syntax_verified=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def failed_conversion_result(sample_python_code):
|
||||||
|
"""Sample failed conversion result for testing."""
|
||||||
|
return ConversionResult(
|
||||||
|
success=False,
|
||||||
|
original_code=sample_python_code,
|
||||||
|
source_language=Language.PYTHON,
|
||||||
|
target_language=Language.JAVASCRIPT,
|
||||||
|
model="codellama",
|
||||||
|
error_message="Connection failed"
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user