Merge pull request #2002 from hroff-1902/refactor/arguments2

minor: refactoring arguments and configuration
This commit is contained in:
Matthias
2019-07-08 16:56:25 +02:00
committed by GitHub
8 changed files with 108 additions and 85 deletions

View File

@@ -227,7 +227,7 @@ def default_conf():
},
"initial_state": "running",
"db_url": "sqlite://",
"loglevel": logging.DEBUG,
"verbosity": 3,
}
return configuration

View File

@@ -19,7 +19,7 @@ def test_parse_args_defaults() -> None:
assert args.config == ['config.json']
assert args.strategy_path is None
assert args.datadir is None
assert args.loglevel == 0
assert args.verbosity == 0
def test_parse_args_config() -> None:
@@ -42,10 +42,10 @@ def test_parse_args_db_url() -> None:
def test_parse_args_verbose() -> None:
args = Arguments(['-v'], '').get_parsed_arg()
assert args.loglevel == 1
assert args.verbosity == 1
args = Arguments(['--verbose'], '').get_parsed_arg()
assert args.loglevel == 1
assert args.verbosity == 1
def test_common_scripts_options() -> None:
@@ -146,7 +146,7 @@ def test_parse_args_backtesting_custom() -> None:
call_args = Arguments(args, '').get_parsed_arg()
assert call_args.config == ['test_conf.json']
assert call_args.live is True
assert call_args.loglevel == 0
assert call_args.verbosity == 0
assert call_args.subparser == 'backtesting'
assert call_args.func is not None
assert call_args.ticker_interval == '1m'
@@ -165,7 +165,7 @@ def test_parse_args_hyperopt_custom() -> None:
call_args = Arguments(args, '').get_parsed_arg()
assert call_args.config == ['test_conf.json']
assert call_args.epochs == 20
assert call_args.loglevel == 0
assert call_args.verbosity == 0
assert call_args.subparser == 'hyperopt'
assert call_args.spaces == ['buy']
assert call_args.func is not None

View File

@@ -12,8 +12,9 @@ from jsonschema import Draft4Validator, ValidationError, validate
from freqtrade import OperationalException, constants
from freqtrade.arguments import Arguments
from freqtrade.configuration import Configuration, set_loggers
from freqtrade.configuration import Configuration
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
@@ -524,7 +525,7 @@ def test_cli_verbose_with_params(default_conf, mocker, caplog) -> None:
mocker.patch('freqtrade.configuration.open', mocker.mock_open(
read_data=json.dumps(default_conf)))
# Prevent setting loggers
mocker.patch('freqtrade.configuration.set_loggers', MagicMock)
mocker.patch('freqtrade.loggers._set_loggers', MagicMock)
arglist = ['-vvv']
args = Arguments(arglist, '').get_parsed_arg()
@@ -546,7 +547,7 @@ def test_set_loggers() -> None:
previous_value2 = logging.getLogger('ccxt.base.exchange').level
previous_value3 = logging.getLogger('telegram').level
set_loggers()
_set_loggers()
value1 = logging.getLogger('requests').level
assert previous_value1 is not value1
@@ -560,13 +561,13 @@ def test_set_loggers() -> None:
assert previous_value3 is not value3
assert value3 is logging.INFO
set_loggers(log_level=2)
_set_loggers(verbosity=2)
assert logging.getLogger('requests').level is logging.DEBUG
assert logging.getLogger('ccxt.base.exchange').level is logging.INFO
assert logging.getLogger('telegram').level is logging.INFO
set_loggers(log_level=3)
_set_loggers(verbosity=3)
assert logging.getLogger('requests').level is logging.DEBUG
assert logging.getLogger('ccxt.base.exchange').level is logging.DEBUG

View File

@@ -27,7 +27,7 @@ def test_parse_args_backtesting(mocker) -> None:
call_args = backtesting_mock.call_args[0][0]
assert call_args.config == ['config.json']
assert call_args.live is False
assert call_args.loglevel == 0
assert call_args.verbosity == 0
assert call_args.subparser == 'backtesting'
assert call_args.func is not None
assert call_args.ticker_interval is None
@@ -41,7 +41,7 @@ def test_main_start_hyperopt(mocker) -> None:
assert hyperopt_mock.call_count == 1
call_args = hyperopt_mock.call_args[0][0]
assert call_args.config == ['config.json']
assert call_args.loglevel == 0
assert call_args.verbosity == 0
assert call_args.subparser == 'hyperopt'
assert call_args.func is not None