From 03f3d0dc8bbff3cbe51da4438badeeed03a44850 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 4 Sep 2019 16:38:33 +0200 Subject: [PATCH 1/2] Remove desc from Arguments header --- freqtrade/configuration/arguments.py | 5 ++- freqtrade/main.py | 5 +-- freqtrade/tests/conftest.py | 2 +- freqtrade/tests/test_arguments.py | 47 +++++++++++++------------ freqtrade/tests/test_configuration.py | 50 +++++++++++++-------------- freqtrade/tests/test_main.py | 4 +-- 6 files changed, 55 insertions(+), 58 deletions(-) diff --git a/freqtrade/configuration/arguments.py b/freqtrade/configuration/arguments.py index 2c814b342..a8cd6686b 100644 --- a/freqtrade/configuration/arguments.py +++ b/freqtrade/configuration/arguments.py @@ -47,11 +47,10 @@ class Arguments(object): """ Arguments Class. Manage the arguments received by the cli """ - def __init__(self, args: Optional[List[str]], description: str, - no_default_config: bool = False) -> None: + def __init__(self, args: Optional[List[str]], no_default_config: bool = False) -> None: self.args = args self._parsed_arg: Optional[argparse.Namespace] = None - self.parser = argparse.ArgumentParser(description=description) + self.parser = argparse.ArgumentParser(description='Free, open source crypto trading bot') self._no_default_config = no_default_config def _load_args(self) -> None: diff --git a/freqtrade/main.py b/freqtrade/main.py index a96fd43c5..e65aa5fbb 100755 --- a/freqtrade/main.py +++ b/freqtrade/main.py @@ -31,10 +31,7 @@ def main(sysargv: List[str] = None) -> None: return_code: Any = 1 worker = None try: - arguments = Arguments( - sysargv, - 'Free, open source crypto trading bot' - ) + arguments = Arguments(sysargv) args: Namespace = arguments.get_parsed_arg() # A subcommand has been issued. diff --git a/freqtrade/tests/conftest.py b/freqtrade/tests/conftest.py index 654b959ca..79b03b057 100644 --- a/freqtrade/tests/conftest.py +++ b/freqtrade/tests/conftest.py @@ -45,7 +45,7 @@ def log_has_re(line, logs): def get_args(args): - return Arguments(args, '').get_parsed_arg() + return Arguments(args).get_parsed_arg() def patched_configuration_load_config_file(mocker, config) -> None: diff --git a/freqtrade/tests/test_arguments.py b/freqtrade/tests/test_arguments.py index 558642894..174038eff 100644 --- a/freqtrade/tests/test_arguments.py +++ b/freqtrade/tests/test_arguments.py @@ -9,13 +9,15 @@ from freqtrade.configuration.cli_options import check_int_positive # Parse common command-line-arguments. Used for all tools def test_parse_args_none() -> None: - arguments = Arguments([], '') + arguments = Arguments([]) assert isinstance(arguments, Arguments) + x = arguments.get_parsed_arg() + assert isinstance(x, argparse.Namespace) assert isinstance(arguments.parser, argparse.ArgumentParser) def test_parse_args_defaults() -> None: - args = Arguments([], '').get_parsed_arg() + args = Arguments([]).get_parsed_arg() assert args.config == ['config.json'] assert args.strategy_path is None assert args.datadir is None @@ -23,33 +25,32 @@ def test_parse_args_defaults() -> None: def test_parse_args_config() -> None: - args = Arguments(['-c', '/dev/null'], '').get_parsed_arg() + args = Arguments(['-c', '/dev/null']).get_parsed_arg() assert args.config == ['/dev/null'] - args = Arguments(['--config', '/dev/null'], '').get_parsed_arg() + args = Arguments(['--config', '/dev/null']).get_parsed_arg() assert args.config == ['/dev/null'] args = Arguments(['--config', '/dev/null', - '--config', '/dev/zero'], - '').get_parsed_arg() + '--config', '/dev/zero'],).get_parsed_arg() assert args.config == ['/dev/null', '/dev/zero'] def test_parse_args_db_url() -> None: - args = Arguments(['--db-url', 'sqlite:///test.sqlite'], '').get_parsed_arg() + args = Arguments(['--db-url', 'sqlite:///test.sqlite']).get_parsed_arg() assert args.db_url == 'sqlite:///test.sqlite' def test_parse_args_verbose() -> None: - args = Arguments(['-v'], '').get_parsed_arg() + args = Arguments(['-v']).get_parsed_arg() assert args.verbosity == 1 - args = Arguments(['--verbose'], '').get_parsed_arg() + args = Arguments(['--verbose']).get_parsed_arg() assert args.verbosity == 1 def test_common_scripts_options() -> None: - args = Arguments(['download-data', '-p', 'ETH/BTC', 'XRP/BTC'], '').get_parsed_arg() + args = Arguments(['download-data', '-p', 'ETH/BTC', 'XRP/BTC']).get_parsed_arg() assert args.pairs == ['ETH/BTC', 'XRP/BTC'] assert hasattr(args, "func") @@ -57,40 +58,40 @@ def test_common_scripts_options() -> None: def test_parse_args_version() -> None: with pytest.raises(SystemExit, match=r'0'): - Arguments(['--version'], '').get_parsed_arg() + Arguments(['--version']).get_parsed_arg() def test_parse_args_invalid() -> None: with pytest.raises(SystemExit, match=r'2'): - Arguments(['-c'], '').get_parsed_arg() + Arguments(['-c']).get_parsed_arg() def test_parse_args_strategy() -> None: - args = Arguments(['--strategy', 'SomeStrategy'], '').get_parsed_arg() + args = Arguments(['--strategy', 'SomeStrategy']).get_parsed_arg() assert args.strategy == 'SomeStrategy' def test_parse_args_strategy_invalid() -> None: with pytest.raises(SystemExit, match=r'2'): - Arguments(['--strategy'], '').get_parsed_arg() + Arguments(['--strategy']).get_parsed_arg() def test_parse_args_strategy_path() -> None: - args = Arguments(['--strategy-path', '/some/path'], '').get_parsed_arg() + args = Arguments(['--strategy-path', '/some/path']).get_parsed_arg() assert args.strategy_path == '/some/path' def test_parse_args_strategy_path_invalid() -> None: with pytest.raises(SystemExit, match=r'2'): - Arguments(['--strategy-path'], '').get_parsed_arg() + Arguments(['--strategy-path']).get_parsed_arg() def test_parse_args_backtesting_invalid() -> None: with pytest.raises(SystemExit, match=r'2'): - Arguments(['backtesting --ticker-interval'], '').get_parsed_arg() + Arguments(['backtesting --ticker-interval']).get_parsed_arg() with pytest.raises(SystemExit, match=r'2'): - Arguments(['backtesting --ticker-interval', 'abc'], '').get_parsed_arg() + Arguments(['backtesting --ticker-interval', 'abc']).get_parsed_arg() def test_parse_args_backtesting_custom() -> None: @@ -103,7 +104,7 @@ def test_parse_args_backtesting_custom() -> None: 'DefaultStrategy', 'SampleStrategy' ] - call_args = Arguments(args, '').get_parsed_arg() + call_args = Arguments(args).get_parsed_arg() assert call_args.config == ['test_conf.json'] assert call_args.verbosity == 0 assert call_args.subparser == 'backtesting' @@ -121,7 +122,7 @@ def test_parse_args_hyperopt_custom() -> None: '--epochs', '20', '--spaces', 'buy' ] - call_args = Arguments(args, '').get_parsed_arg() + call_args = Arguments(args).get_parsed_arg() assert call_args.config == ['test_conf.json'] assert call_args.epochs == 20 assert call_args.verbosity == 0 @@ -138,7 +139,7 @@ def test_download_data_options() -> None: '--days', '30', '--exchange', 'binance' ] - args = Arguments(args, '').get_parsed_arg() + args = Arguments(args).get_parsed_arg() assert args.pairs_file == 'file_with_pairs' assert args.datadir == 'datadir/directory' @@ -155,7 +156,7 @@ def test_plot_dataframe_options() -> None: '--plot-limit', '30', '-p', 'UNITTEST/BTC', ] - pargs = Arguments(args, '').get_parsed_arg() + pargs = Arguments(args).get_parsed_arg() assert pargs.indicators1 == ["sma10", "sma100"] assert pargs.indicators2 == ["macd", "fastd", "fastk"] @@ -170,7 +171,7 @@ def test_plot_profit_options() -> None: '--trade-source', 'DB', "--db-url", "sqlite:///whatever.sqlite", ] - pargs = Arguments(args, '').get_parsed_arg() + pargs = Arguments(args).get_parsed_arg() assert pargs.trade_source == "DB" assert pargs.pairs == ["UNITTEST/BTC"] diff --git a/freqtrade/tests/test_configuration.py b/freqtrade/tests/test_configuration.py index 5a70715a4..177d365d6 100644 --- a/freqtrade/tests/test_configuration.py +++ b/freqtrade/tests/test_configuration.py @@ -66,7 +66,7 @@ def test_load_config_file(default_conf, mocker, caplog) -> None: def test__args_to_config(caplog): arg_list = ['--strategy-path', 'TestTest'] - args = Arguments(arg_list, '').get_parsed_arg() + args = Arguments(arg_list).get_parsed_arg() configuration = Configuration(args) config = {} with warnings.catch_warnings(record=True) as w: @@ -93,7 +93,7 @@ def test_load_config_max_open_trades_zero(default_conf, mocker, caplog) -> None: default_conf['max_open_trades'] = 0 patched_configuration_load_config_file(mocker, default_conf) - args = Arguments([], '').get_parsed_arg() + args = Arguments([]).get_parsed_arg() configuration = Configuration(args) validated_conf = configuration.load_config() @@ -119,7 +119,7 @@ def test_load_config_combine_dicts(default_conf, mocker, caplog) -> None: ) arg_list = ['-c', 'test_conf.json', '--config', 'test2_conf.json', ] - args = Arguments(arg_list, '').get_parsed_arg() + args = Arguments(arg_list).get_parsed_arg() configuration = Configuration(args) validated_conf = configuration.load_config() @@ -167,7 +167,7 @@ def test_load_config_max_open_trades_minus_one(default_conf, mocker, caplog) -> default_conf['max_open_trades'] = -1 patched_configuration_load_config_file(mocker, default_conf) - args = Arguments([], '').get_parsed_arg() + args = Arguments([]).get_parsed_arg() configuration = Configuration(args) validated_conf = configuration.load_config() @@ -191,7 +191,7 @@ def test_load_config_file_exception(mocker) -> None: def test_load_config(default_conf, mocker) -> None: patched_configuration_load_config_file(mocker, default_conf) - args = Arguments([], '').get_parsed_arg() + args = Arguments([]).get_parsed_arg() configuration = Configuration(args) validated_conf = configuration.load_config() @@ -208,7 +208,7 @@ def test_load_config_with_params(default_conf, mocker) -> None: '--strategy-path', '/some/path', '--db-url', 'sqlite:///someurl', ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args) validated_conf = configuration.load_config() @@ -226,7 +226,7 @@ def test_load_config_with_params(default_conf, mocker) -> None: '--strategy', 'TestStrategy', '--strategy-path', '/some/path' ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args) validated_conf = configuration.load_config() @@ -242,7 +242,7 @@ def test_load_config_with_params(default_conf, mocker) -> None: '--strategy', 'TestStrategy', '--strategy-path', '/some/path' ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args) validated_conf = configuration.load_config() @@ -258,7 +258,7 @@ def test_load_config_with_params(default_conf, mocker) -> None: '--strategy', 'TestStrategy', '--strategy-path', '/some/path' ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args) validated_conf = configuration.load_config() @@ -276,7 +276,7 @@ def test_load_config_with_params(default_conf, mocker) -> None: '--strategy', 'TestStrategy', '--strategy-path', '/some/path' ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args) validated_conf = configuration.load_config() @@ -290,7 +290,7 @@ def test_load_custom_strategy(default_conf, mocker) -> None: }) patched_configuration_load_config_file(mocker, default_conf) - args = Arguments([], '').get_parsed_arg() + args = Arguments([]).get_parsed_arg() configuration = Configuration(args) validated_conf = configuration.load_config() @@ -305,7 +305,7 @@ def test_show_info(default_conf, mocker, caplog) -> None: '--strategy', 'TestStrategy', '--db-url', 'sqlite:///tmp/testdb', ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args) configuration.get_config() @@ -323,7 +323,7 @@ def test_setup_configuration_without_arguments(mocker, default_conf, caplog) -> 'backtesting' ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args) config = configuration.get_config() @@ -373,7 +373,7 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non '--export', '/bar/foo' ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args) config = configuration.get_config() @@ -423,7 +423,7 @@ def test_setup_configuration_with_stratlist(mocker, default_conf, caplog) -> Non 'TestStrategy' ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args, RunMode.BACKTEST) config = configuration.get_config() @@ -460,7 +460,7 @@ def test_hyperopt_with_arguments(mocker, default_conf, caplog) -> None: '--epochs', '10', '--spaces', 'all', ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args, RunMode.HYPEROPT) config = configuration.get_config() @@ -536,7 +536,7 @@ def test_cli_verbose_with_params(default_conf, mocker, caplog) -> None: # Prevent setting loggers mocker.patch('freqtrade.loggers._set_loggers', MagicMock) arglist = ['-vvv'] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args) validated_conf = configuration.load_config() @@ -589,7 +589,7 @@ def test_set_logfile(default_conf, mocker): arglist = [ '--logfile', 'test_file.log', ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args) validated_conf = configuration.load_config() @@ -603,7 +603,7 @@ def test_load_config_warn_forcebuy(default_conf, mocker, caplog) -> None: default_conf['forcebuy_enable'] = True patched_configuration_load_config_file(mocker, default_conf) - args = Arguments([], '').get_parsed_arg() + args = Arguments([]).get_parsed_arg() configuration = Configuration(args) validated_conf = configuration.load_config() @@ -778,7 +778,7 @@ def test_pairlist_resolving(): '--exchange', 'binance' ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args) config = configuration.get_config() @@ -794,7 +794,7 @@ def test_pairlist_resolving_with_config(mocker, default_conf): 'download-data', ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args) config = configuration.get_config() @@ -809,7 +809,7 @@ def test_pairlist_resolving_with_config(mocker, default_conf): '--pairs', 'ETH/BTC', 'XRP/BTC', ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args) config = configuration.get_config() @@ -831,7 +831,7 @@ def test_pairlist_resolving_with_config_pl(mocker, default_conf): '--pairs-file', 'pairs.json', ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args) config = configuration.get_config() @@ -853,7 +853,7 @@ def test_pairlist_resolving_with_config_pl_not_exists(mocker, default_conf): '--pairs-file', 'pairs.json', ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() with pytest.raises(OperationalException, match=r"No pairs file found with path.*"): configuration = Configuration(args) @@ -870,7 +870,7 @@ def test_pairlist_resolving_fallback(mocker): '--exchange', 'binance' ] - args = Arguments(arglist, '').get_parsed_arg() + args = Arguments(arglist).get_parsed_arg() configuration = Configuration(args) config = configuration.get_config() diff --git a/freqtrade/tests/test_main.py b/freqtrade/tests/test_main.py index db5a438d0..a0fd8218b 100644 --- a/freqtrade/tests/test_main.py +++ b/freqtrade/tests/test_main.py @@ -117,7 +117,7 @@ def test_main_reload_conf(mocker, default_conf, caplog) -> None: mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock()) mocker.patch('freqtrade.freqtradebot.persistence.init', MagicMock()) - args = Arguments(['-c', 'config.json.example'], '').get_parsed_arg() + args = Arguments(['-c', 'config.json.example']).get_parsed_arg() worker = Worker(args=args, config=default_conf) with pytest.raises(SystemExit): main(['-c', 'config.json.example']) @@ -139,7 +139,7 @@ def test_reconfigure(mocker, default_conf) -> None: mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock()) mocker.patch('freqtrade.freqtradebot.persistence.init', MagicMock()) - args = Arguments(['-c', 'config.json.example'], '').get_parsed_arg() + args = Arguments(['-c', 'config.json.example']).get_parsed_arg() worker = Worker(args=args, config=default_conf) freqtrade = worker.freqtrade From 5ce63cd54a33098b298da5b8d4c9177828a8e025 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 4 Sep 2019 16:39:23 +0200 Subject: [PATCH 2/2] Remove no_config_ argument from Arguments --- freqtrade/configuration/arguments.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/freqtrade/configuration/arguments.py b/freqtrade/configuration/arguments.py index a8cd6686b..addbfcf67 100644 --- a/freqtrade/configuration/arguments.py +++ b/freqtrade/configuration/arguments.py @@ -47,11 +47,10 @@ class Arguments(object): """ Arguments Class. Manage the arguments received by the cli """ - def __init__(self, args: Optional[List[str]], no_default_config: bool = False) -> None: + def __init__(self, args: Optional[List[str]]) -> None: self.args = args self._parsed_arg: Optional[argparse.Namespace] = None self.parser = argparse.ArgumentParser(description='Free, open source crypto trading bot') - self._no_default_config = no_default_config def _load_args(self) -> None: self._build_args(optionlist=ARGS_MAIN) @@ -77,7 +76,7 @@ class Arguments(object): # Workaround issue in argparse with action='append' and default value # (see https://bugs.python.org/issue16399) # Allow no-config for certain commands (like downloading / plotting) - if (not self._no_default_config and parsed_arg.config is None + if (parsed_arg.config is None and not ('subparser' in parsed_arg and parsed_arg.subparser in NO_CONF_REQURIED)): parsed_arg.config = [constants.DEFAULT_CONFIG]