Adapt tests to load start_* methods from optimize

This commit is contained in:
Matthias 2019-05-25 20:01:43 +02:00
parent 236c392d28
commit 65a4862d1f
3 changed files with 17 additions and 16 deletions

View File

@ -18,8 +18,8 @@ from freqtrade.data.btanalysis import evaluate_result_multi
from freqtrade.data.converter import parse_ticker_dataframe from freqtrade.data.converter import parse_ticker_dataframe
from freqtrade.data.dataprovider import DataProvider from freqtrade.data.dataprovider import DataProvider
from freqtrade.data.history import get_timeframe from freqtrade.data.history import get_timeframe
from freqtrade.optimize.backtesting import (Backtesting, setup_configuration, from freqtrade.optimize import setup_configuration, start_backtesting
start) from freqtrade.optimize.backtesting import Backtesting
from freqtrade.state import RunMode from freqtrade.state import RunMode
from freqtrade.strategy.default_strategy import DefaultStrategy from freqtrade.strategy.default_strategy import DefaultStrategy
from freqtrade.strategy.interface import SellType from freqtrade.strategy.interface import SellType
@ -178,7 +178,7 @@ def test_setup_configuration_without_arguments(mocker, default_conf, caplog) ->
'backtesting' 'backtesting'
] ]
config = setup_configuration(get_args(args)) config = setup_configuration(get_args(args), RunMode.BACKTEST)
assert 'max_open_trades' in config assert 'max_open_trades' in config
assert 'stake_currency' in config assert 'stake_currency' in config
assert 'stake_amount' in config assert 'stake_amount' in config
@ -228,7 +228,7 @@ def test_setup_bt_configuration_with_arguments(mocker, default_conf, caplog) ->
'--export-filename', 'foo_bar.json' '--export-filename', 'foo_bar.json'
] ]
config = setup_configuration(get_args(args)) config = setup_configuration(get_args(args), RunMode.BACKTEST)
assert 'max_open_trades' in config assert 'max_open_trades' in config
assert 'stake_currency' in config assert 'stake_currency' in config
assert 'stake_amount' in config assert 'stake_amount' in config
@ -290,7 +290,7 @@ def test_setup_configuration_unlimited_stake_amount(mocker, default_conf, caplog
] ]
with pytest.raises(DependencyException, match=r'.*stake amount.*'): with pytest.raises(DependencyException, match=r'.*stake amount.*'):
setup_configuration(get_args(args)) setup_configuration(get_args(args), RunMode.BACKTEST)
def test_start(mocker, fee, default_conf, caplog) -> None: def test_start(mocker, fee, default_conf, caplog) -> None:
@ -307,7 +307,7 @@ def test_start(mocker, fee, default_conf, caplog) -> None:
'backtesting' 'backtesting'
] ]
args = get_args(args) args = get_args(args)
start(args) start_backtesting(args)
assert log_has( assert log_has(
'Starting freqtrade in Backtesting mode', 'Starting freqtrade in Backtesting mode',
caplog.record_tuples caplog.record_tuples
@ -847,7 +847,7 @@ def test_backtest_start_live(default_conf, mocker, caplog):
'--disable-max-market-positions' '--disable-max-market-positions'
] ]
args = get_args(args) args = get_args(args)
start(args) start_backtesting(args)
# check the logs, that will contain the backtest result # check the logs, that will contain the backtest result
exists = [ exists = [
'Parameter -i/--ticker-interval detected ... Using ticker_interval: 1m ...', 'Parameter -i/--ticker-interval detected ... Using ticker_interval: 1m ...',
@ -901,7 +901,7 @@ def test_backtest_start_multi_strat(default_conf, mocker, caplog):
'TestStrategy', 'TestStrategy',
] ]
args = get_args(args) args = get_args(args)
start(args) start_backtesting(args)
# 2 backtests, 4 tables # 2 backtests, 4 tables
assert backtestmock.call_count == 2 assert backtestmock.call_count == 2
assert gen_table_mock.call_count == 4 assert gen_table_mock.call_count == 4

View File

@ -11,7 +11,8 @@ from freqtrade import DependencyException
from freqtrade.data.converter import parse_ticker_dataframe from freqtrade.data.converter import parse_ticker_dataframe
from freqtrade.data.history import load_tickerdata_file from freqtrade.data.history import load_tickerdata_file
from freqtrade.optimize.default_hyperopt import DefaultHyperOpts from freqtrade.optimize.default_hyperopt import DefaultHyperOpts
from freqtrade.optimize.hyperopt import Hyperopt, setup_configuration, start from freqtrade.optimize.hyperopt import Hyperopt
from freqtrade.optimize import setup_configuration, start_hyperopt
from freqtrade.resolvers.hyperopt_resolver import HyperOptResolver from freqtrade.resolvers.hyperopt_resolver import HyperOptResolver
from freqtrade.state import RunMode from freqtrade.state import RunMode
from freqtrade.tests.conftest import log_has, log_has_re, patch_exchange from freqtrade.tests.conftest import log_has, log_has_re, patch_exchange
@ -52,7 +53,7 @@ def test_setup_hyperopt_configuration_without_arguments(mocker, default_conf, ca
'hyperopt' 'hyperopt'
] ]
config = setup_configuration(get_args(args)) config = setup_configuration(get_args(args), RunMode.HYPEROPT)
assert 'max_open_trades' in config assert 'max_open_trades' in config
assert 'stake_currency' in config assert 'stake_currency' in config
assert 'stake_amount' in config assert 'stake_amount' in config
@ -100,7 +101,7 @@ def test_setup_hyperopt_configuration_with_arguments(mocker, default_conf, caplo
'--print-all' '--print-all'
] ]
config = setup_configuration(get_args(args)) config = setup_configuration(get_args(args), RunMode.HYPEROPT)
assert 'max_open_trades' in config assert 'max_open_trades' in config
assert 'stake_currency' in config assert 'stake_currency' in config
assert 'stake_amount' in config assert 'stake_amount' in config
@ -183,7 +184,7 @@ def test_start(mocker, default_conf, caplog) -> None:
'--epochs', '5' '--epochs', '5'
] ]
args = get_args(args) args = get_args(args)
start(args) start_hyperopt(args)
import pprint import pprint
pprint.pprint(caplog.record_tuples) pprint.pprint(caplog.record_tuples)
@ -214,7 +215,7 @@ def test_start_no_data(mocker, default_conf, caplog) -> None:
'--epochs', '5' '--epochs', '5'
] ]
args = get_args(args) args = get_args(args)
start(args) start_hyperopt(args)
import pprint import pprint
pprint.pprint(caplog.record_tuples) pprint.pprint(caplog.record_tuples)
@ -239,7 +240,7 @@ def test_start_failure(mocker, default_conf, caplog) -> None:
] ]
args = get_args(args) args = get_args(args)
with pytest.raises(DependencyException): with pytest.raises(DependencyException):
start(args) start_hyperopt(args)
assert log_has( assert log_has(
"Please don't use --strategy for hyperopt.", "Please don't use --strategy for hyperopt.",
caplog.record_tuples caplog.record_tuples

View File

@ -19,7 +19,7 @@ def test_parse_args_backtesting(mocker) -> None:
Test that main() can start backtesting and also ensure we can pass some specific arguments Test that main() can start backtesting and also ensure we can pass some specific arguments
further argument parsing is done in test_arguments.py further argument parsing is done in test_arguments.py
""" """
backtesting_mock = mocker.patch('freqtrade.optimize.backtesting.start', MagicMock()) backtesting_mock = mocker.patch('freqtrade.optimize.start_backtesting', MagicMock())
main(['backtesting']) main(['backtesting'])
assert backtesting_mock.call_count == 1 assert backtesting_mock.call_count == 1
call_args = backtesting_mock.call_args[0][0] call_args = backtesting_mock.call_args[0][0]
@ -32,7 +32,7 @@ def test_parse_args_backtesting(mocker) -> None:
def test_main_start_hyperopt(mocker) -> None: def test_main_start_hyperopt(mocker) -> None:
hyperopt_mock = mocker.patch('freqtrade.optimize.hyperopt.start', MagicMock()) hyperopt_mock = mocker.patch('freqtrade.optimize.start_hyperopt', MagicMock())
main(['hyperopt']) main(['hyperopt'])
assert hyperopt_mock.call_count == 1 assert hyperopt_mock.call_count == 1
call_args = hyperopt_mock.call_args[0][0] call_args = hyperopt_mock.call_args[0][0]