From 8d95e76d2625f5e0f30af8383895623588642883 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 5 Apr 2022 20:43:39 +0200 Subject: [PATCH] Add tests for new naming definitions --- freqtrade/resolvers/strategy_resolver.py | 12 +++++----- tests/strategy/strats/strategy_test_v2.py | 2 ++ tests/strategy/test_strategy_loading.py | 27 ++++++++++++++--------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/freqtrade/resolvers/strategy_resolver.py b/freqtrade/resolvers/strategy_resolver.py index cbb5f0321..76515026c 100644 --- a/freqtrade/resolvers/strategy_resolver.py +++ b/freqtrade/resolvers/strategy_resolver.py @@ -173,6 +173,12 @@ class StrategyResolver(IResolver): def validate_strategy(strategy: IStrategy) -> IStrategy: if strategy.config.get('trading_mode', TradingMode.SPOT) != TradingMode.SPOT: # Require new method + warn_deprecated_setting(strategy, 'sell_profit_only', 'exit_profit_only', True) + warn_deprecated_setting(strategy, 'sell_profit_offset', 'exit_profit_offset', True) + warn_deprecated_setting(strategy, 'use_sell_signal', 'use_exit_signal', True) + warn_deprecated_setting(strategy, 'ignore_roi_if_buy_signal', + 'ignore_roi_if_entry_signal', True) + if not check_override(strategy, IStrategy, 'populate_entry_trend'): raise OperationalException("`populate_entry_trend` must be implemented.") if not check_override(strategy, IStrategy, 'populate_exit_trend'): @@ -187,11 +193,7 @@ class StrategyResolver(IResolver): if check_override(strategy, IStrategy, 'custom_sell'): raise OperationalException( "Please migrate your implementation of `custom_sell` to `custom_exit`.") - warn_deprecated_setting(strategy, 'sell_profit_only', 'exit_profit_only', True) - warn_deprecated_setting(strategy, 'sell_profit_offset', 'exit_profit_offset', True) - warn_deprecated_setting(strategy, 'use_sell_signal', 'use_exit_signal', True) - warn_deprecated_setting(strategy, 'ignore_roi_if_buy_signal', - 'ignore_roi_if_entry_signal', True) + else: # TODO: Implementing one of the following methods should show a deprecation warning # buy_trend and sell_trend, custom_sell diff --git a/tests/strategy/strats/strategy_test_v2.py b/tests/strategy/strats/strategy_test_v2.py index a9ca7d9e2..8996b227a 100644 --- a/tests/strategy/strats/strategy_test_v2.py +++ b/tests/strategy/strats/strategy_test_v2.py @@ -50,6 +50,8 @@ class StrategyTestV2(IStrategy): 'entry': 'gtc', 'exit': 'gtc', } + # Test legacy use_sell_signal definition + use_sell_signal = False # By default this strategy does not use Position Adjustments position_adjustment_enable = False diff --git a/tests/strategy/test_strategy_loading.py b/tests/strategy/test_strategy_loading.py index 32003cd16..e74a2a022 100644 --- a/tests/strategy/test_strategy_loading.py +++ b/tests/strategy/test_strategy_loading.py @@ -143,16 +143,6 @@ def test_strategy_can_short(caplog, default_conf): assert isinstance(strat, IStrategy) -def test_strategy_implements_populate_entry(caplog, default_conf): - caplog.set_level(logging.INFO) - default_conf.update({ - 'strategy': "StrategyTestV2", - }) - default_conf['trading_mode'] = 'futures' - with pytest.raises(OperationalException, match="`populate_entry_trend` must be implemented."): - StrategyResolver.load_strategy(default_conf) - - def test_strategy_override_minimal_roi(caplog, default_conf): caplog.set_level(logging.INFO) default_conf.update({ @@ -391,7 +381,22 @@ def test_deprecate_populate_indicators(result, default_conf): @pytest.mark.filterwarnings("ignore:deprecated") -def test_missing_implements(default_conf): +def test_missing_implements(default_conf, caplog): + + default_location = Path(__file__).parent / "strats" + default_conf.update({'strategy': 'StrategyTestV2', + 'strategy_path': default_location}) + StrategyResolver.load_strategy(default_conf) + + log_has_re(r"DEPRECATED: .*use_sell_signal.*use_exit_signal.", caplog) + + default_conf['trading_mode'] = 'futures' + with pytest.raises(OperationalException, + match=r"DEPRECATED: .*use_sell_signal.*use_exit_signal."): + StrategyResolver.load_strategy(default_conf) + + default_conf['trading_mode'] = 'spot' + default_location = Path(__file__).parent / "strats/broken_strats" default_conf.update({'strategy': 'TestStrategyNoImplements', 'strategy_path': default_location})