extract backtesting abort functionality
This commit is contained in:
@@ -346,6 +346,20 @@ def test_data_to_dataframe_bt(default_conf, mocker, testdatadir) -> None:
|
||||
assert processed['UNITTEST/BTC'].equals(processed2['UNITTEST/BTC'])
|
||||
|
||||
|
||||
def test_backtest_abort(default_conf, mocker, testdatadir) -> None:
|
||||
patch_exchange(mocker)
|
||||
backtesting = Backtesting(default_conf)
|
||||
backtesting.check_abort()
|
||||
|
||||
backtesting.abort = True
|
||||
|
||||
with pytest.raises(DependencyException, match="Stop requested"):
|
||||
backtesting.check_abort()
|
||||
# abort flag resets
|
||||
assert backtesting.abort is False
|
||||
assert backtesting.progress.progress == 0
|
||||
|
||||
|
||||
def test_backtesting_start(default_conf, mocker, testdatadir, caplog) -> None:
|
||||
def get_timerange(input1):
|
||||
return Arrow(2017, 11, 14, 21, 17), Arrow(2017, 11, 14, 22, 59)
|
||||
|
@@ -1252,10 +1252,6 @@ def test_api_backtesting(botclient, mocker, fee):
|
||||
assert not result['running']
|
||||
assert result['status_msg'] == 'Backtest reset'
|
||||
|
||||
# bt_mock = mocker.patch('freqtrade.optimize.backtesting.Backtesting.backtest_one_strategy',
|
||||
# return_value=(1, 2))
|
||||
# stats_mock = mocker.patch('freqtrade.optimize.optimize_reports.generate_backtest_stats')
|
||||
# bt_mock.load_bt_data = MagicMock(return_value=(xxx, 'asdfadf'))
|
||||
# start backtesting
|
||||
data = {
|
||||
"strategy": "DefaultStrategy",
|
||||
@@ -1285,6 +1281,13 @@ def test_api_backtesting(botclient, mocker, fee):
|
||||
assert result['progress'] == 1
|
||||
assert result['backtest_result']
|
||||
|
||||
rc = client_get(client, f"{BASE_URI}/backtest/abort")
|
||||
assert_response(rc)
|
||||
result = rc.json()
|
||||
assert result['status'] == 'not_running'
|
||||
assert not result['running']
|
||||
assert result['status_msg'] == 'Backtest ended'
|
||||
|
||||
# Delete backtesting to avoid leakage since the backtest-object may stick around.
|
||||
rc = client_delete(client, f"{BASE_URI}/backtest")
|
||||
assert_response(rc)
|
||||
|
Reference in New Issue
Block a user