Remove deprecated modules and files related to the backtesting framework, including backtest.py, cli.py, config.py, data.py, intrabar.py, logging_utils.py, market_costs.py, metrics.py, trade.py, and supertrend indicators. Introduce a new structure for the backtesting engine with improved organization and functionality, including a CLI handler, data manager, and reporting capabilities. Update dependencies in pyproject.toml to support the new architecture.
This commit is contained in:
69
tests/test_data_manager.py
Normal file
69
tests/test_data_manager.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""Tests for DataManager functionality."""
|
||||
import pytest
|
||||
|
||||
from engine.data_manager import DataManager
|
||||
from engine.market import MarketType
|
||||
|
||||
|
||||
class TestDataManager:
|
||||
"""Test suite for DataManager class."""
|
||||
|
||||
def test_init_creates_data_dir(self, tmp_path):
|
||||
"""Test that DataManager creates data directory on init."""
|
||||
data_dir = tmp_path / "test_data"
|
||||
dm = DataManager(data_dir=str(data_dir))
|
||||
assert data_dir.exists()
|
||||
|
||||
def test_get_data_path_spot(self, tmp_path):
|
||||
"""Test data path generation for spot market."""
|
||||
dm = DataManager(data_dir=str(tmp_path))
|
||||
path = dm._get_data_path("okx", "BTC/USDT", "1m", MarketType.SPOT)
|
||||
|
||||
expected = tmp_path / "okx" / "spot" / "BTC-USDT" / "1m.csv"
|
||||
assert path == expected
|
||||
|
||||
def test_get_data_path_perpetual(self, tmp_path):
|
||||
"""Test data path generation for perpetual market."""
|
||||
dm = DataManager(data_dir=str(tmp_path))
|
||||
path = dm._get_data_path("okx", "BTC/USDT", "1h", MarketType.PERPETUAL)
|
||||
|
||||
expected = tmp_path / "okx" / "perpetual" / "BTC-USDT" / "1h.csv"
|
||||
assert path == expected
|
||||
|
||||
def test_load_data_file_not_found(self, tmp_path):
|
||||
"""Test that load_data raises FileNotFoundError for missing data."""
|
||||
dm = DataManager(data_dir=str(tmp_path))
|
||||
|
||||
with pytest.raises(FileNotFoundError):
|
||||
dm.load_data("okx", "BTC/USDT", "1m", MarketType.SPOT)
|
||||
|
||||
|
||||
@pytest.mark.network
|
||||
class TestDataManagerDownload:
|
||||
"""Tests requiring network access (marked for selective running)."""
|
||||
|
||||
def test_download_spot_data(self):
|
||||
"""Test downloading spot market data."""
|
||||
dm = DataManager()
|
||||
df = dm.download_data(
|
||||
"okx", "BTC/USDT", "1m",
|
||||
start_date="2025-01-01",
|
||||
market_type=MarketType.SPOT
|
||||
)
|
||||
|
||||
assert df is not None
|
||||
assert 'open' in df.columns
|
||||
assert 'close' in df.columns
|
||||
|
||||
def test_download_perpetual_data(self):
|
||||
"""Test downloading perpetual market data."""
|
||||
dm = DataManager()
|
||||
df = dm.download_data(
|
||||
"okx", "BTC/USDT", "1m",
|
||||
start_date="2025-01-01",
|
||||
market_type=MarketType.PERPETUAL
|
||||
)
|
||||
|
||||
assert df is not None
|
||||
assert 'open' in df.columns
|
||||
assert 'close' in df.columns
|
||||
Reference in New Issue
Block a user