Add tests and test-strategies for custom "implements" requirements

This commit is contained in:
Matthias 2022-03-12 10:05:16 +01:00
parent 9460fd8d75
commit 6946203a7c
3 changed files with 43 additions and 1 deletions

View File

@ -227,7 +227,7 @@ class StrategyResolver(IResolver):
if type(strategy).populate_exit_trend == IStrategy.populate_exit_trend:
raise OperationalException("`populate_exit_trend` must be implemented.")
else:
# TODO: Implementing buy_trend and sell_trend should raise a deprecation.
if (type(strategy).populate_buy_trend == IStrategy.populate_buy_trend
and type(strategy).populate_entry_trend == IStrategy.populate_entry_trend):
raise OperationalException(

View File

@ -0,0 +1,16 @@
# The strategy which fails to load due to non-existent dependency
from pandas import DataFrame
from freqtrade.strategy.interface import IStrategy
class TestStrategyNoImplements(IStrategy):
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
return super().populate_indicators(dataframe, metadata)
class TestStrategyNoImplementSell(TestStrategyNoImplements):
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
return super().populate_entry_trend(dataframe, metadata)

View File

@ -391,6 +391,32 @@ def test_deprecate_populate_indicators(result, default_conf):
in str(w[-1].message)
@pytest.mark.filterwarnings("ignore:deprecated")
def test_missing_implements(result, default_conf):
default_location = Path(__file__).parent / "strats/broken_strats"
default_conf.update({'strategy': 'TestStrategyNoImplements',
'strategy_path': default_location})
with pytest.raises(OperationalException,
match=r"`populate_entry_trend` or `populate_buy_trend`.*"):
StrategyResolver.load_strategy(default_conf)
default_conf['strategy'] = 'TestStrategyNoImplementSell'
with pytest.raises(OperationalException,
match=r"`populate_exit_trend` or `populate_sell_trend`.*"):
StrategyResolver.load_strategy(default_conf)
default_conf['trading_mode'] = 'futures'
with pytest.raises(OperationalException,
match=r"`populate_exit_trend` must be implemented.*"):
StrategyResolver.load_strategy(default_conf)
default_conf['strategy'] = 'TestStrategyNoImplements'
with pytest.raises(OperationalException,
match=r"`populate_entry_trend` must be implemented.*"):
StrategyResolver.load_strategy(default_conf)
@pytest.mark.filterwarnings("ignore:deprecated")
def test_call_deprecated_function(result, default_conf, caplog):
default_location = Path(__file__).parent / "strats"