get rid of patched_configuration_open() in tests

This commit is contained in:
hroff-1902 2019-07-15 01:44:25 +03:00
parent bbfbd87a9f
commit 9cae2900d4
5 changed files with 37 additions and 42 deletions

View File

@ -43,13 +43,6 @@ def get_args(args):
return Arguments(args, '').get_parsed_arg()
def patched_configuration_open(mocker, config):
file_mock = mocker.patch('freqtrade.configuration.configuration.open', mocker.mock_open(
read_data=json.dumps(config)
))
return file_mock
def patched_configuration_load_config_file(mocker, config) -> None:
mocker.patch(
'freqtrade.configuration.configuration.Configuration._load_config_file',

View File

@ -22,7 +22,7 @@ from freqtrade.state import RunMode
from freqtrade.strategy.default_strategy import DefaultStrategy
from freqtrade.strategy.interface import SellType
from freqtrade.tests.conftest import (get_args, log_has, log_has_re, patch_exchange,
patched_configuration_open)
patched_configuration_load_config_file)
def trim_dictlist(dict_list, num):
@ -165,7 +165,7 @@ def _trend_alternate(dataframe=None, metadata=None):
# Unit tests
def test_setup_configuration_without_arguments(mocker, default_conf, caplog) -> None:
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
args = [
'--config', 'config.json',
@ -203,7 +203,7 @@ def test_setup_configuration_without_arguments(mocker, default_conf, caplog) ->
def test_setup_bt_configuration_with_arguments(mocker, default_conf, caplog) -> None:
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
mocker.patch(
'freqtrade.configuration.configuration.create_datadir',
lambda c, x: x
@ -275,7 +275,7 @@ def test_setup_bt_configuration_with_arguments(mocker, default_conf, caplog) ->
def test_setup_configuration_unlimited_stake_amount(mocker, default_conf, caplog) -> None:
default_conf['stake_amount'] = constants.UNLIMITED_STAKE_AMOUNT
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
args = [
'--config', 'config.json',
@ -292,7 +292,7 @@ def test_start(mocker, fee, default_conf, caplog) -> None:
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
patch_exchange(mocker)
mocker.patch('freqtrade.optimize.backtesting.Backtesting.start', start_mock)
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
args = [
'--config', 'config.json',
@ -824,7 +824,7 @@ def test_backtest_start_live(default_conf, mocker, caplog):
patch_exchange(mocker, api_mock)
mocker.patch('freqtrade.optimize.backtesting.Backtesting.backtest', MagicMock())
mocker.patch('freqtrade.optimize.backtesting.Backtesting._generate_text_table', MagicMock())
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
args = [
'--config', 'config.json',
@ -874,7 +874,7 @@ def test_backtest_start_multi_strat(default_conf, mocker, caplog):
gen_strattable_mock = MagicMock()
mocker.patch('freqtrade.optimize.backtesting.Backtesting._generate_text_table_strategy',
gen_strattable_mock)
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
args = [
'--config', 'config.json',

View File

@ -8,11 +8,11 @@ from freqtrade.optimize import setup_configuration, start_edge
from freqtrade.optimize.edge_cli import EdgeCli
from freqtrade.state import RunMode
from freqtrade.tests.conftest import (get_args, log_has, log_has_re, patch_exchange,
patched_configuration_open)
patched_configuration_load_config_file)
def test_setup_configuration_without_arguments(mocker, default_conf, caplog) -> None:
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
args = [
'--config', 'config.json',
@ -44,7 +44,7 @@ def test_setup_configuration_without_arguments(mocker, default_conf, caplog) ->
def test_setup_edge_configuration_with_arguments(mocker, edge_conf, caplog) -> None:
patched_configuration_open(mocker, edge_conf)
patched_configuration_load_config_file(mocker, edge_conf)
mocker.patch(
'freqtrade.configuration.configuration.create_datadir',
lambda c, x: x
@ -91,7 +91,7 @@ def test_start(mocker, fee, edge_conf, caplog) -> None:
mocker.patch('freqtrade.exchange.Exchange.get_fee', fee)
patch_exchange(mocker)
mocker.patch('freqtrade.optimize.edge_cli.EdgeCli.start', start_mock)
patched_configuration_open(mocker, edge_conf)
patched_configuration_load_config_file(mocker, edge_conf)
args = [
'--config', 'config.json',

View File

@ -16,8 +16,7 @@ from freqtrade.optimize import setup_configuration, start_hyperopt
from freqtrade.resolvers.hyperopt_resolver import HyperOptResolver
from freqtrade.state import RunMode
from freqtrade.tests.conftest import (get_args, log_has, log_has_re, patch_exchange,
patched_configuration_load_config_file,
patched_configuration_open)
patched_configuration_load_config_file)
@pytest.fixture(scope='function')
@ -45,7 +44,7 @@ def create_trials(mocker, hyperopt) -> None:
def test_setup_hyperopt_configuration_without_arguments(mocker, default_conf, caplog) -> None:
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
args = [
'--config', 'config.json',
@ -81,7 +80,7 @@ def test_setup_hyperopt_configuration_without_arguments(mocker, default_conf, ca
def test_setup_hyperopt_configuration_with_arguments(mocker, default_conf, caplog) -> None:
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
mocker.patch(
'freqtrade.configuration.configuration.create_datadir',
lambda c, x: x

View File

@ -1,5 +1,5 @@
# pragma pylint: disable=missing-docstring, protected-access, invalid-name
import json
import logging
from argparse import Namespace
from copy import deepcopy
@ -17,7 +17,8 @@ from freqtrade.configuration.json_schema import validate_config_schema
from freqtrade.constants import DEFAULT_DB_DRYRUN_URL, DEFAULT_DB_PROD_URL
from freqtrade.loggers import _set_loggers
from freqtrade.state import RunMode
from freqtrade.tests.conftest import log_has, log_has_re, patched_configuration_open
from freqtrade.tests.conftest import (log_has, log_has_re,
patched_configuration_load_config_file)
@pytest.fixture(scope="function")
@ -51,7 +52,9 @@ def test_load_config_incorrect_stake_amount(default_conf) -> None:
def test_load_config_file(default_conf, mocker, caplog) -> None:
file_mock = patched_configuration_open(mocker, default_conf)
file_mock = mocker.patch('freqtrade.configuration.configuration.open', mocker.mock_open(
read_data=json.dumps(default_conf)
))
configuration = Configuration(Namespace())
validated_conf = configuration._load_config_file('somefile')
@ -61,7 +64,7 @@ def test_load_config_file(default_conf, mocker, caplog) -> None:
def test_load_config_max_open_trades_zero(default_conf, mocker, caplog) -> None:
default_conf['max_open_trades'] = 0
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
args = Arguments([], '').get_parsed_arg()
configuration = Configuration(args)
@ -106,7 +109,7 @@ def test_load_config_combine_dicts(default_conf, mocker, caplog) -> None:
def test_load_config_max_open_trades_minus_one(default_conf, mocker, caplog) -> None:
default_conf['max_open_trades'] = -1
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
args = Arguments([], '').get_parsed_arg()
configuration = Configuration(args)
@ -131,7 +134,7 @@ def test_load_config_file_exception(mocker) -> None:
def test_load_config(default_conf, mocker) -> None:
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
args = Arguments([], '').get_parsed_arg()
configuration = Configuration(args)
@ -143,7 +146,7 @@ def test_load_config(default_conf, mocker) -> None:
def test_load_config_with_params(default_conf, mocker) -> None:
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
arglist = [
'--dynamic-whitelist', '10',
@ -165,7 +168,7 @@ def test_load_config_with_params(default_conf, mocker) -> None:
conf = default_conf.copy()
conf["dry_run"] = False
conf["db_url"] = "sqlite:///path/to/db.sqlite"
patched_configuration_open(mocker, conf)
patched_configuration_load_config_file(mocker, conf)
arglist = [
'--strategy', 'TestStrategy',
@ -181,7 +184,7 @@ def test_load_config_with_params(default_conf, mocker) -> None:
conf = default_conf.copy()
conf["dry_run"] = True
conf["db_url"] = "sqlite:///path/to/db.sqlite"
patched_configuration_open(mocker, conf)
patched_configuration_load_config_file(mocker, conf)
arglist = [
'--strategy', 'TestStrategy',
@ -197,7 +200,7 @@ def test_load_config_with_params(default_conf, mocker) -> None:
conf = default_conf.copy()
conf["dry_run"] = False
del conf["db_url"]
patched_configuration_open(mocker, conf)
patched_configuration_load_config_file(mocker, conf)
arglist = [
'--strategy', 'TestStrategy',
@ -215,7 +218,7 @@ def test_load_config_with_params(default_conf, mocker) -> None:
conf = default_conf.copy()
conf["dry_run"] = True
conf["db_url"] = DEFAULT_DB_PROD_URL
patched_configuration_open(mocker, conf)
patched_configuration_load_config_file(mocker, conf)
arglist = [
'--strategy', 'TestStrategy',
@ -233,7 +236,7 @@ def test_load_custom_strategy(default_conf, mocker) -> None:
'strategy': 'CustomStrategy',
'strategy_path': '/tmp/strategies',
})
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
args = Arguments([], '').get_parsed_arg()
configuration = Configuration(args)
@ -244,7 +247,7 @@ def test_load_custom_strategy(default_conf, mocker) -> None:
def test_show_info(default_conf, mocker, caplog) -> None:
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
arglist = [
'--dynamic-whitelist', '10',
@ -268,7 +271,7 @@ def test_show_info(default_conf, mocker, caplog) -> None:
def test_setup_configuration_without_arguments(mocker, default_conf, caplog) -> None:
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
arglist = [
'--config', 'config.json',
@ -307,7 +310,7 @@ def test_setup_configuration_without_arguments(mocker, default_conf, caplog) ->
def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> None:
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
mocker.patch(
'freqtrade.configuration.configuration.create_datadir',
lambda c, x: x
@ -374,7 +377,7 @@ def test_setup_configuration_with_stratlist(mocker, default_conf, caplog) -> Non
"""
Test setup_configuration() function
"""
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
arglist = [
'--config', 'config.json',
@ -422,7 +425,7 @@ def test_setup_configuration_with_stratlist(mocker, default_conf, caplog) -> Non
def test_hyperopt_with_arguments(mocker, default_conf, caplog) -> None:
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
arglist = [
'hyperopt',
@ -497,7 +500,7 @@ def test_check_exchange(default_conf, caplog) -> None:
def test_cli_verbose_with_params(default_conf, mocker, caplog) -> None:
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
# Prevent setting loggers
mocker.patch('freqtrade.loggers._set_loggers', MagicMock)
@ -550,7 +553,7 @@ def test_set_loggers() -> None:
def test_set_logfile(default_conf, mocker):
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
arglist = [
'--logfile', 'test_file.log',
@ -567,7 +570,7 @@ def test_set_logfile(default_conf, mocker):
def test_load_config_warn_forcebuy(default_conf, mocker, caplog) -> None:
default_conf['forcebuy_enable'] = True
patched_configuration_open(mocker, default_conf)
patched_configuration_load_config_file(mocker, default_conf)
args = Arguments([], '').get_parsed_arg()
configuration = Configuration(args)