Split updater_tests to be clearer

This commit is contained in:
Matthias 2023-03-12 16:26:12 +01:00
parent 0911cd72a2
commit b5c4f9ebe2

View File

@ -7,9 +7,11 @@ import pytest
from freqtrade.strategy.strategyupdater import StrategyUpdater
def test_strategy_updater(default_conf, caplog) -> None:
if sys.version_info < (3, 9):
pytest.skip("StrategyUpdater is not compatible with Python 3.8", allow_module_level=True)
if sys.version_info < (3, 9):
pytest.skip("StrategyUpdater is not compatible with Python 3.8", allow_module_level=True)
def test_strategy_updater_methods(default_conf, caplog) -> None:
instance_strategy_updater = StrategyUpdater()
modified_code1 = instance_strategy_updater.update_code("""
@ -25,11 +27,32 @@ class testClass(IStrategy):
def custom_sell():
pass
""")
assert "populate_entry_trend" in modified_code1
assert "populate_exit_trend" in modified_code1
assert "check_entry_timeout" in modified_code1
assert "check_exit_timeout" in modified_code1
assert "custom_exit" in modified_code1
assert "INTERFACE_VERSION = 3" in modified_code1
def test_strategy_updater_params(default_conf, caplog) -> None:
instance_strategy_updater = StrategyUpdater()
modified_code2 = instance_strategy_updater.update_code("""
ticker_interval = '15m'
buy_some_parameter = IntParameter(space='buy')
sell_some_parameter = IntParameter(space='sell')
""")
assert "timeframe" in modified_code2
# check for not editing hyperopt spaces
assert "space='buy'" in modified_code2
assert "space='sell'" in modified_code2
def test_strategy_updater_constants(default_conf, caplog) -> None:
instance_strategy_updater = StrategyUpdater()
modified_code3 = instance_strategy_updater.update_code("""
use_sell_signal = True
sell_profit_only = True
@ -37,15 +60,38 @@ sell_profit_offset = True
ignore_roi_if_buy_signal = True
forcebuy_enable = True
""")
modified_code4 = instance_strategy_updater.update_code("""
assert "use_exit_signal" in modified_code3
assert "exit_profit_only" in modified_code3
assert "exit_profit_offset" in modified_code3
assert "ignore_roi_if_entry_signal" in modified_code3
assert "force_entry_enable" in modified_code3
def test_strategy_updater_df_columns(default_conf, caplog) -> None:
instance_strategy_updater = StrategyUpdater()
modified_code = instance_strategy_updater.update_code("""
dataframe.loc[reduce(lambda x, y: x & y, conditions), ["buy", "buy_tag"]] = (1, "buy_signal_1")
dataframe.loc[reduce(lambda x, y: x & y, conditions), 'sell'] = 1
""")
modified_code5 = instance_strategy_updater.update_code("""
assert "enter_long" in modified_code
assert "exit_long" in modified_code
assert "enter_tag" in modified_code
def test_strategy_updater_method_params(default_conf, caplog) -> None:
instance_strategy_updater = StrategyUpdater()
modified_code = instance_strategy_updater.update_code("""
def confirm_trade_exit(sell_reason: str):
pass
""")
modified_code6 = instance_strategy_updater.update_code("""
assert "exit_reason" in modified_code
def test_strategy_updater_dicts(default_conf, caplog) -> None:
instance_strategy_updater = StrategyUpdater()
modified_code = instance_strategy_updater.update_code("""
order_time_in_force = {
'buy': 'gtc',
'sell': 'ioc'
@ -62,17 +108,44 @@ unfilledtimeout = {
}
""")
modified_code7 = instance_strategy_updater.update_code("""
assert "'entry': 'gtc'" in modified_code
assert "'exit': 'ioc'" in modified_code
assert "'entry': 'limit'" in modified_code
assert "'exit': 'market'" in modified_code
assert "'entry': 1" in modified_code
assert "'exit': 2" in modified_code
def test_strategy_updater_comparisons(default_conf, caplog) -> None:
instance_strategy_updater = StrategyUpdater()
modified_code = instance_strategy_updater.update_code("""
def confirm_trade_exit(sell_reason):
if (sell_reason == 'stop_loss'):
pass
""")
modified_code8 = instance_strategy_updater.update_code("""
assert "exit_reason" in modified_code
assert "exit_reason == 'stop_loss'" in modified_code
def test_strategy_updater_strings(default_conf, caplog) -> None:
instance_strategy_updater = StrategyUpdater()
modified_code = instance_strategy_updater.update_code("""
sell_reason == 'sell_signal'
sell_reason == 'force_sell'
sell_reason == 'emergency_sell'
""")
modified_code9 = instance_strategy_updater.update_code("""
# those tests currently don't work, next in line.
assert "exit_signal" in modified_code
assert "exit_reason" in modified_code
assert "force_exit" in modified_code
assert "emergency_exit" in modified_code
def test_strategy_updater_comments(default_conf, caplog) -> None:
instance_strategy_updater = StrategyUpdater()
modified_code = instance_strategy_updater.update_code("""
# This is the 1st comment
import talib.abstract as ta
# This is the 2nd comment
@ -89,49 +162,9 @@ class someStrategy(IStrategy):
# This is the 4th comment
stoploss = -0.1
""")
assert "This is the 1st comment" in modified_code
assert "This is the 2nd comment" in modified_code
assert "This is the 3rd comment" in modified_code
# currently still missing:
# Webhook terminology, Telegram notification settings, Strategy/Config settings
assert "populate_entry_trend" in modified_code1
assert "populate_exit_trend" in modified_code1
assert "check_entry_timeout" in modified_code1
assert "check_exit_timeout" in modified_code1
assert "custom_exit" in modified_code1
assert "INTERFACE_VERSION = 3" in modified_code1
assert "timeframe" in modified_code2
# check for not editing hyperopt spaces
assert "space='buy'" in modified_code2
assert "space='sell'" in modified_code2
assert "use_exit_signal" in modified_code3
assert "exit_profit_only" in modified_code3
assert "exit_profit_offset" in modified_code3
assert "ignore_roi_if_entry_signal" in modified_code3
assert "force_entry_enable" in modified_code3
assert "enter_long" in modified_code4
assert "exit_long" in modified_code4
assert "enter_tag" in modified_code4
assert "exit_reason" in modified_code5
assert "'entry': 'gtc'" in modified_code6
assert "'exit': 'ioc'" in modified_code6
assert "'entry': 'limit'" in modified_code6
assert "'exit': 'market'" in modified_code6
assert "'entry': 1" in modified_code6
assert "'exit': 2" in modified_code6
assert "exit_reason" in modified_code7
assert "exit_reason == 'stop_loss'" in modified_code7
# those tests currently don't work, next in line.
assert "exit_signal" in modified_code8
assert "exit_reason" in modified_code8
assert "force_exit" in modified_code8
assert "emergency_exit" in modified_code8
assert "This is the 1st comment" in modified_code9
assert "This is the 2nd comment" in modified_code9
assert "This is the 3rd comment" in modified_code9