34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
import os
|
|
import sys
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
|
|
|
|
from backtest_strategy_instance import BacktestStrategyInstance
|
|
|
|
|
|
class TestBacktestStrategyInstanceConvertAsset:
|
|
"""Tests for backtest-specific asset conversion behavior."""
|
|
|
|
def test_convert_asset_uses_active_feed_for_matching_pair(self):
|
|
"""Backtest conversions should work for the active feed symbol."""
|
|
instance = BacktestStrategyInstance.__new__(BacktestStrategyInstance)
|
|
instance.exec_context = {'current_symbol': 'BTC/USDT'}
|
|
instance.get_current_price = MagicMock(return_value=50000.0)
|
|
|
|
result = BacktestStrategyInstance.convert_asset(instance, 10, 'USD', 'BTC')
|
|
|
|
assert result == pytest.approx(0.0002, rel=1e-6)
|
|
|
|
def test_convert_asset_returns_zero_for_unavailable_backtest_pair(self):
|
|
"""Backtest should not reuse the current feed price for unrelated symbols."""
|
|
instance = BacktestStrategyInstance.__new__(BacktestStrategyInstance)
|
|
instance.exec_context = {'current_symbol': 'BTC/USDT'}
|
|
instance.get_current_price = MagicMock(return_value=50000.0)
|
|
|
|
result = BacktestStrategyInstance.convert_asset(instance, 10, 'USD', 'ETH')
|
|
|
|
assert result == 0.0
|