mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-10 04:37:24 -04:00
test: improve test coverage from 61% to 84.81%
Major improvements: - Fixed all 42 broken tests (database connection leaks) - Added db_connection() context manager for proper cleanup - Created comprehensive test suites for undertested modules New test coverage: - tools/general_tools.py: 26 tests (97% coverage) - tools/price_tools.py: 11 tests (validates NASDAQ symbols, date handling) - api/price_data_manager.py: 12 tests (85% coverage) - api/routes/results_v2.py: 3 tests (98% coverage) - agent/reasoning_summarizer.py: 2 tests (87% coverage) - api/routes/period_metrics.py: 2 edge case tests (100% coverage) - agent/mock_provider: 1 test (100% coverage) Database fixes: - Added db_connection() context manager to prevent leaks - Updated 16+ test files to use context managers - Fixed drop_all_tables() to match new schema - Added CHECK constraint for action_type - Added ON DELETE CASCADE to trading_days foreign key Test improvements: - Updated SQL INSERT statements with all required fields - Fixed date parameter handling in API integration tests - Added edge case tests for validation functions - Fixed import errors across test suite Results: - Total coverage: 84.81% (was 61%) - Tests passing: 406 (was 364 with 42 failures) - Total lines covered: 6364 of 7504 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -31,8 +31,8 @@ class TestDatabaseHelpers:
|
||||
"""Test creating a new trading day record."""
|
||||
# Insert job first
|
||||
db.connection.execute(
|
||||
"INSERT INTO jobs (job_id, status) VALUES (?, ?)",
|
||||
("test-job", "running")
|
||||
"INSERT INTO jobs (job_id, config_path, status, date_range, models, created_at) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
("test-job", "configs/test.json", "running", '["2025-01-15"]', '["test-model"]', "2025-01-15T00:00:00Z")
|
||||
)
|
||||
|
||||
trading_day_id = db.create_trading_day(
|
||||
@@ -61,8 +61,8 @@ class TestDatabaseHelpers:
|
||||
"""Test retrieving previous trading day."""
|
||||
# Setup: Create job and two trading days
|
||||
db.connection.execute(
|
||||
"INSERT INTO jobs (job_id, status) VALUES (?, ?)",
|
||||
("test-job", "running")
|
||||
"INSERT INTO jobs (job_id, config_path, status, date_range, models, created_at) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
("test-job", "configs/test.json", "running", '["2025-01-15"]', '["test-model"]', "2025-01-15T00:00:00Z")
|
||||
)
|
||||
|
||||
day1_id = db.create_trading_day(
|
||||
@@ -103,8 +103,8 @@ class TestDatabaseHelpers:
|
||||
def test_get_previous_trading_day_with_weekend_gap(self, db):
|
||||
"""Test retrieving previous trading day across weekend."""
|
||||
db.connection.execute(
|
||||
"INSERT INTO jobs (job_id, status) VALUES (?, ?)",
|
||||
("test-job", "running")
|
||||
"INSERT INTO jobs (job_id, config_path, status, date_range, models, created_at) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
("test-job", "configs/test.json", "running", '["2025-01-15"]', '["test-model"]', "2025-01-15T00:00:00Z")
|
||||
)
|
||||
|
||||
# Friday
|
||||
@@ -171,8 +171,8 @@ class TestDatabaseHelpers:
|
||||
def test_get_ending_holdings(self, db):
|
||||
"""Test retrieving ending holdings for a trading day."""
|
||||
db.connection.execute(
|
||||
"INSERT INTO jobs (job_id, status) VALUES (?, ?)",
|
||||
("test-job", "running")
|
||||
"INSERT INTO jobs (job_id, config_path, status, date_range, models, created_at) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
("test-job", "configs/test.json", "running", '["2025-01-15"]', '["test-model"]', "2025-01-15T00:00:00Z")
|
||||
)
|
||||
|
||||
trading_day_id = db.create_trading_day(
|
||||
@@ -201,8 +201,8 @@ class TestDatabaseHelpers:
|
||||
def test_get_starting_holdings_first_day(self, db):
|
||||
"""Test starting holdings for first trading day (should be empty)."""
|
||||
db.connection.execute(
|
||||
"INSERT INTO jobs (job_id, status) VALUES (?, ?)",
|
||||
("test-job", "running")
|
||||
"INSERT INTO jobs (job_id, config_path, status, date_range, models, created_at) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
("test-job", "configs/test.json", "running", '["2025-01-15"]', '["test-model"]', "2025-01-15T00:00:00Z")
|
||||
)
|
||||
|
||||
trading_day_id = db.create_trading_day(
|
||||
@@ -224,8 +224,8 @@ class TestDatabaseHelpers:
|
||||
def test_get_starting_holdings_from_previous_day(self, db):
|
||||
"""Test starting holdings derived from previous day's ending."""
|
||||
db.connection.execute(
|
||||
"INSERT INTO jobs (job_id, status) VALUES (?, ?)",
|
||||
("test-job", "running")
|
||||
"INSERT INTO jobs (job_id, config_path, status, date_range, models, created_at) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
("test-job", "configs/test.json", "running", '["2025-01-15"]', '["test-model"]', "2025-01-15T00:00:00Z")
|
||||
)
|
||||
|
||||
# Day 1
|
||||
@@ -318,8 +318,8 @@ class TestDatabaseHelpers:
|
||||
def test_create_action(self, db):
|
||||
"""Test creating an action record."""
|
||||
db.connection.execute(
|
||||
"INSERT INTO jobs (job_id, status) VALUES (?, ?)",
|
||||
("test-job", "running")
|
||||
"INSERT INTO jobs (job_id, config_path, status, date_range, models, created_at) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
("test-job", "configs/test.json", "running", '["2025-01-15"]', '["test-model"]', "2025-01-15T00:00:00Z")
|
||||
)
|
||||
|
||||
trading_day_id = db.create_trading_day(
|
||||
@@ -355,8 +355,8 @@ class TestDatabaseHelpers:
|
||||
def test_get_actions(self, db):
|
||||
"""Test retrieving all actions for a trading day."""
|
||||
db.connection.execute(
|
||||
"INSERT INTO jobs (job_id, status) VALUES (?, ?)",
|
||||
("test-job", "running")
|
||||
"INSERT INTO jobs (job_id, config_path, status, date_range, models, created_at) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
("test-job", "configs/test.json", "running", '["2025-01-15"]', '["test-model"]', "2025-01-15T00:00:00Z")
|
||||
)
|
||||
|
||||
trading_day_id = db.create_trading_day(
|
||||
|
||||
Reference in New Issue
Block a user