ci: fix lint baseline and stabilize failing main tests
This commit is contained in:
@@ -208,7 +208,9 @@ def test_identify_failure_patterns_empty(optimizer: EvolutionOptimizer) -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_strategy_creates_file(optimizer: EvolutionOptimizer, tmp_path: Path) -> None:
|
||||
async def test_generate_strategy_creates_file(
|
||||
optimizer: EvolutionOptimizer, tmp_path: Path
|
||||
) -> None:
|
||||
"""Test that generate_strategy creates a strategy file."""
|
||||
failures = [
|
||||
{
|
||||
@@ -234,7 +236,9 @@ async def test_generate_strategy_creates_file(optimizer: EvolutionOptimizer, tmp
|
||||
return {"action": "HOLD", "confidence": 50, "rationale": "Waiting"}
|
||||
"""
|
||||
|
||||
with patch.object(optimizer._client.aio.models, "generate_content", new=AsyncMock(return_value=mock_response)):
|
||||
with patch.object(
|
||||
optimizer._client.aio.models, "generate_content", new=AsyncMock(return_value=mock_response)
|
||||
):
|
||||
with patch("src.evolution.optimizer.STRATEGIES_DIR", tmp_path):
|
||||
strategy_path = await optimizer.generate_strategy(failures)
|
||||
|
||||
@@ -247,7 +251,8 @@ async def test_generate_strategy_creates_file(optimizer: EvolutionOptimizer, tmp
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_strategy_saves_valid_python_code(
|
||||
optimizer: EvolutionOptimizer, tmp_path: Path,
|
||||
optimizer: EvolutionOptimizer,
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
"""Test that syntactically valid generated code is saved."""
|
||||
failures = [{"decision_id": "1", "timestamp": "2024-01-15T09:30:00+00:00"}]
|
||||
@@ -255,12 +260,14 @@ async def test_generate_strategy_saves_valid_python_code(
|
||||
mock_response = Mock()
|
||||
mock_response.text = (
|
||||
'price = market_data.get("current_price", 0)\n'
|
||||
'if price > 0:\n'
|
||||
"if price > 0:\n"
|
||||
' return {"action": "BUY", "confidence": 80, "rationale": "Positive price"}\n'
|
||||
'return {"action": "HOLD", "confidence": 50, "rationale": "No signal"}\n'
|
||||
)
|
||||
|
||||
with patch.object(optimizer._client.aio.models, "generate_content", new=AsyncMock(return_value=mock_response)):
|
||||
with patch.object(
|
||||
optimizer._client.aio.models, "generate_content", new=AsyncMock(return_value=mock_response)
|
||||
):
|
||||
with patch("src.evolution.optimizer.STRATEGIES_DIR", tmp_path):
|
||||
strategy_path = await optimizer.generate_strategy(failures)
|
||||
|
||||
@@ -270,7 +277,9 @@ async def test_generate_strategy_saves_valid_python_code(
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_strategy_blocks_invalid_python_code(
|
||||
optimizer: EvolutionOptimizer, tmp_path: Path, caplog: pytest.LogCaptureFixture,
|
||||
optimizer: EvolutionOptimizer,
|
||||
tmp_path: Path,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test that syntactically invalid generated code is not saved."""
|
||||
failures = [{"decision_id": "1", "timestamp": "2024-01-15T09:30:00+00:00"}]
|
||||
@@ -281,7 +290,9 @@ async def test_generate_strategy_blocks_invalid_python_code(
|
||||
' return {"action": "BUY", "confidence": 80, "rationale": "broken"}\n'
|
||||
)
|
||||
|
||||
with patch.object(optimizer._client.aio.models, "generate_content", new=AsyncMock(return_value=mock_response)):
|
||||
with patch.object(
|
||||
optimizer._client.aio.models, "generate_content", new=AsyncMock(return_value=mock_response)
|
||||
):
|
||||
with patch("src.evolution.optimizer.STRATEGIES_DIR", tmp_path):
|
||||
with caplog.at_level("WARNING"):
|
||||
strategy_path = await optimizer.generate_strategy(failures)
|
||||
@@ -310,6 +321,7 @@ def test_get_performance_summary() -> None:
|
||||
"""Test getting performance summary from trades table."""
|
||||
# Create a temporary database with trades
|
||||
import tempfile
|
||||
|
||||
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as tmp:
|
||||
tmp_path = tmp.name
|
||||
|
||||
@@ -604,7 +616,9 @@ def test_calculate_improvement_trend_declining(performance_tracker: PerformanceT
|
||||
assert trend["pnl_change"] == -250.0
|
||||
|
||||
|
||||
def test_calculate_improvement_trend_insufficient_data(performance_tracker: PerformanceTracker) -> None:
|
||||
def test_calculate_improvement_trend_insufficient_data(
|
||||
performance_tracker: PerformanceTracker,
|
||||
) -> None:
|
||||
"""Test improvement trend with insufficient data."""
|
||||
metrics = [
|
||||
StrategyMetrics(
|
||||
@@ -718,7 +732,9 @@ async def test_full_evolution_pipeline(optimizer: EvolutionOptimizer, tmp_path:
|
||||
mock_response = Mock()
|
||||
mock_response.text = 'return {"action": "HOLD", "confidence": 50, "rationale": "Test"}'
|
||||
|
||||
with patch.object(optimizer._client.aio.models, "generate_content", new=AsyncMock(return_value=mock_response)):
|
||||
with patch.object(
|
||||
optimizer._client.aio.models, "generate_content", new=AsyncMock(return_value=mock_response)
|
||||
):
|
||||
with patch("src.evolution.optimizer.STRATEGIES_DIR", tmp_path):
|
||||
with patch("subprocess.run") as mock_run:
|
||||
mock_run.return_value = Mock(returncode=0, stdout="", stderr="")
|
||||
|
||||
Reference in New Issue
Block a user