From 65489c894d9cd2dc9383b8cff57e75a2ecf8a2de Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 12 Nov 2019 13:33:37 +0100 Subject: [PATCH] Add no-arg test --- freqtrade/configuration/arguments.py | 2 +- freqtrade/utils.py | 6 ++---- tests/test_utils.py | 10 +++++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/freqtrade/configuration/arguments.py b/freqtrade/configuration/arguments.py index 4ba2d04c4..5cc56a8bc 100644 --- a/freqtrade/configuration/arguments.py +++ b/freqtrade/configuration/arguments.py @@ -56,7 +56,7 @@ ARGS_PLOT_PROFIT = ["pairs", "timerange", "export", "exportfilename", "db_url", NO_CONF_REQURIED = ["download-data", "list-timeframes", "list-markets", "list-pairs", "plot-dataframe", "plot-profit"] -NO_CONF_ALLOWED = ["create-userdir", "list-exchanges","new-hyperopt", "new-strategy"] +NO_CONF_ALLOWED = ["create-userdir", "list-exchanges", "new-hyperopt", "new-strategy"] class Arguments: diff --git a/freqtrade/utils.py b/freqtrade/utils.py index dd61cfcab..314ec4f36 100644 --- a/freqtrade/utils.py +++ b/freqtrade/utils.py @@ -111,8 +111,7 @@ def start_new_strategy(args: Dict[str, Any]) -> None: logger.info(f"Writing strategy to `{new_path}`.") new_path.write_text(strategy_text) else: - logger.warning("`new-strategy` requires --strategy to be set.") - sys.exit(1) + raise OperationalException("`new-strategy` requires --strategy to be set.") def start_new_hyperopt(args: Dict[str, Any]) -> None: @@ -135,8 +134,7 @@ def start_new_hyperopt(args: Dict[str, Any]) -> None: logger.info(f"Writing hyperopt to `{new_path}`.") new_path.write_text(strategy_text) else: - logger.warning("`new-hyperopt` requires --hyperopt to be set.") - sys.exit(1) + raise OperationalException("`new-hyperopt` requires --hyperopt to be set.") def start_download_data(args: Dict[str, Any]) -> None: diff --git a/tests/test_utils.py b/tests/test_utils.py index 902d56082..c64050f38 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -469,7 +469,6 @@ def test_start_new_strategy(mocker, caplog): assert log_has_re("Writing strategy to .*", caplog) - def test_start_new_strategy_DefaultStrat(mocker, caplog): args = [ "new-strategy", @@ -481,6 +480,15 @@ def test_start_new_strategy_DefaultStrat(mocker, caplog): start_new_strategy(get_args(args)) +def test_start_new_strategy_no_arg(mocker, caplog): + args = [ + "new-strategy", + ] + with pytest.raises(OperationalException, + match="`new-strategy` requires --strategy to be set."): + start_new_strategy(get_args(args)) + + def test_download_data_keyboardInterrupt(mocker, caplog, markets): dl_mock = mocker.patch('freqtrade.utils.refresh_backtest_ohlcv_data', MagicMock(side_effect=KeyboardInterrupt))