diff --git a/tests/freqai/test_freqai_backtesting.py b/tests/freqai/test_freqai_backtesting.py index bb0a71e2c..a92742b86 100644 --- a/tests/freqai/test_freqai_backtesting.py +++ b/tests/freqai/test_freqai_backtesting.py @@ -1,16 +1,18 @@ +from copy import deepcopy +from datetime import datetime, timezone from pathlib import Path -from unittest.mock import PropertyMock +from unittest.mock import MagicMock, PropertyMock import pytest from freqtrade.commands.optimize_commands import start_backtesting from freqtrade.exceptions import OperationalException -from tests.conftest import (CURRENT_TEST_STRATEGY, get_args, patch_exchange, +from freqtrade.optimize.backtesting import Backtesting +from tests.conftest import (CURRENT_TEST_STRATEGY, get_args, log_has_re, patch_exchange, patched_configuration_load_config_file) -def test_backtest_start_backtest_list_freqai(freqai_conf, mocker, testdatadir): - # Tests detail-data loading +def test_freqai_backtest_start_backtest_list(freqai_conf, mocker, testdatadir): patch_exchange(mocker) mocker.patch('freqtrade.plugins.pairlistmanager.PairListManager.whitelist', @@ -31,3 +33,25 @@ def test_backtest_start_backtest_list_freqai(freqai_conf, mocker, testdatadir): with pytest.raises(OperationalException, match=r"You can't use strategy_list and freqai at the same time\."): start_backtesting(args) + + +def test_freqai_backtest_load_data(freqai_conf, mocker, caplog): + patch_exchange(mocker) + + now = datetime.now(timezone.utc) + mocker.patch('freqtrade.plugins.pairlistmanager.PairListManager.whitelist', + PropertyMock(return_value=['HULUMULU/USDT', 'XRP/USDT'])) + mocker.patch('freqtrade.optimize.backtesting.history.load_data') + mocker.patch('freqtrade.optimize.backtesting.history.get_timerange', return_value=(now, now)) + backtesting = Backtesting(deepcopy(freqai_conf)) + backtesting.load_bt_data() + + assert log_has_re('Increasing startup_candle_count for freqai to.*', caplog) + + del freqai_conf['freqai']['startup_candles'] + backtesting = Backtesting(freqai_conf) + with pytest.raises(OperationalException, + match=r'FreqAI backtesting module.*startup_candles in config.'): + backtesting.load_bt_data() + + Backtesting.cleanup()