Add default_conf to strategy tests
This commit is contained in:
parent
9de8d7276e
commit
333413d298
@ -64,15 +64,18 @@ def test_search_strategy():
|
||||
assert s is None
|
||||
|
||||
|
||||
def test_load_strategy(result):
|
||||
resolver = StrategyResolver({'strategy': 'TestStrategy'})
|
||||
def test_load_strategy(default_conf, result):
|
||||
default_conf.update({'strategy': 'TestStrategy'})
|
||||
resolver = StrategyResolver(default_conf)
|
||||
assert 'adx' in resolver.strategy.advise_indicators(result, {'pair': 'ETH/BTC'})
|
||||
|
||||
|
||||
def test_load_strategy_base64(result, caplog):
|
||||
def test_load_strategy_base64(result, caplog, default_conf):
|
||||
with open("user_data/strategies/test_strategy.py", "rb") as file:
|
||||
encoded_string = urlsafe_b64encode(file.read()).decode("utf-8")
|
||||
resolver = StrategyResolver({'strategy': 'TestStrategy:{}'.format(encoded_string)})
|
||||
default_conf.update({'strategy': 'TestStrategy:{}'.format(encoded_string)})
|
||||
|
||||
resolver = StrategyResolver(default_conf)
|
||||
assert 'adx' in resolver.strategy.advise_indicators(result, {'pair': 'ETH/BTC'})
|
||||
# Make sure strategy was loaded from base64 (using temp directory)!!
|
||||
assert log_has_re(r"Using resolved strategy TestStrategy from '"
|
||||
@ -80,47 +83,47 @@ def test_load_strategy_base64(result, caplog):
|
||||
caplog.record_tuples)
|
||||
|
||||
|
||||
def test_load_strategy_invalid_directory(result, caplog):
|
||||
resolver = StrategyResolver()
|
||||
def test_load_strategy_invalid_directory(result, caplog, default_conf):
|
||||
resolver = StrategyResolver(default_conf)
|
||||
extra_dir = Path.cwd() / 'some/path'
|
||||
resolver._load_strategy('TestStrategy', config={}, extra_dir=extra_dir)
|
||||
resolver._load_strategy('TestStrategy', config=default_conf, extra_dir=extra_dir)
|
||||
|
||||
assert log_has_re(r'Path .*' + r'some.*path.*' + r'.* does not exist', caplog.record_tuples)
|
||||
|
||||
assert 'adx' in resolver.strategy.advise_indicators(result, {'pair': 'ETH/BTC'})
|
||||
|
||||
|
||||
def test_load_not_found_strategy():
|
||||
strategy = StrategyResolver()
|
||||
def test_load_not_found_strategy(default_conf):
|
||||
strategy = StrategyResolver(default_conf)
|
||||
with pytest.raises(OperationalException,
|
||||
match=r"Impossible to load Strategy 'NotFoundStrategy'. "
|
||||
r"This class does not exist or contains Python code errors."):
|
||||
strategy._load_strategy(strategy_name='NotFoundStrategy', config={})
|
||||
strategy._load_strategy(strategy_name='NotFoundStrategy', config=default_conf)
|
||||
|
||||
|
||||
def test_load_staticmethod_importerror(mocker, caplog):
|
||||
def test_load_staticmethod_importerror(mocker, caplog, default_conf):
|
||||
mocker.patch("freqtrade.resolvers.strategy_resolver.import_strategy", Mock(
|
||||
side_effect=TypeError("can't pickle staticmethod objects")))
|
||||
with pytest.raises(OperationalException,
|
||||
match=r"Impossible to load Strategy 'DefaultStrategy'. "
|
||||
r"This class does not exist or contains Python code errors."):
|
||||
StrategyResolver()
|
||||
StrategyResolver(default_conf)
|
||||
assert log_has_re(r".*Error: can't pickle staticmethod objects", caplog.record_tuples)
|
||||
|
||||
|
||||
def test_strategy(result):
|
||||
config = {'strategy': 'DefaultStrategy'}
|
||||
def test_strategy(result, default_conf):
|
||||
default_conf.update({'strategy': 'DefaultStrategy'})
|
||||
|
||||
resolver = StrategyResolver(config)
|
||||
resolver = StrategyResolver(default_conf)
|
||||
metadata = {'pair': 'ETH/BTC'}
|
||||
assert resolver.strategy.minimal_roi[0] == 0.04
|
||||
assert config["minimal_roi"]['0'] == 0.04
|
||||
assert default_conf["minimal_roi"]['0'] == 0.04
|
||||
|
||||
assert resolver.strategy.stoploss == -0.10
|
||||
assert config['stoploss'] == -0.10
|
||||
assert default_conf['stoploss'] == -0.10
|
||||
|
||||
assert resolver.strategy.ticker_interval == '5m'
|
||||
assert config['ticker_interval'] == '5m'
|
||||
assert default_conf['ticker_interval'] == '5m'
|
||||
|
||||
df_indicators = resolver.strategy.advise_indicators(result, metadata=metadata)
|
||||
assert 'adx' in df_indicators
|
||||
@ -132,15 +135,15 @@ def test_strategy(result):
|
||||
assert 'sell' in dataframe.columns
|
||||
|
||||
|
||||
def test_strategy_override_minimal_roi(caplog):
|
||||
def test_strategy_override_minimal_roi(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
config = {
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'minimal_roi': {
|
||||
"0": 0.5
|
||||
}
|
||||
}
|
||||
resolver = StrategyResolver(config)
|
||||
})
|
||||
resolver = StrategyResolver(default_conf)
|
||||
|
||||
assert resolver.strategy.minimal_roi[0] == 0.5
|
||||
assert ('freqtrade.resolvers.strategy_resolver',
|
||||
@ -149,13 +152,13 @@ def test_strategy_override_minimal_roi(caplog):
|
||||
) in caplog.record_tuples
|
||||
|
||||
|
||||
def test_strategy_override_stoploss(caplog):
|
||||
def test_strategy_override_stoploss(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
config = {
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'stoploss': -0.5
|
||||
}
|
||||
resolver = StrategyResolver(config)
|
||||
})
|
||||
resolver = StrategyResolver(default_conf)
|
||||
|
||||
assert resolver.strategy.stoploss == -0.5
|
||||
assert ('freqtrade.resolvers.strategy_resolver',
|
||||
@ -164,13 +167,13 @@ def test_strategy_override_stoploss(caplog):
|
||||
) in caplog.record_tuples
|
||||
|
||||
|
||||
def test_strategy_override_trailing_stop(caplog):
|
||||
def test_strategy_override_trailing_stop(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
config = {
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'trailing_stop': True
|
||||
}
|
||||
resolver = StrategyResolver(config)
|
||||
})
|
||||
resolver = StrategyResolver(default_conf)
|
||||
|
||||
assert resolver.strategy.trailing_stop
|
||||
assert isinstance(resolver.strategy.trailing_stop, bool)
|
||||
@ -180,15 +183,15 @@ def test_strategy_override_trailing_stop(caplog):
|
||||
) in caplog.record_tuples
|
||||
|
||||
|
||||
def test_strategy_override_trailing_stop_positive(caplog):
|
||||
def test_strategy_override_trailing_stop_positive(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
config = {
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'trailing_stop_positive': -0.1,
|
||||
'trailing_stop_positive_offset': -0.2
|
||||
|
||||
}
|
||||
resolver = StrategyResolver(config)
|
||||
})
|
||||
resolver = StrategyResolver(default_conf)
|
||||
|
||||
assert resolver.strategy.trailing_stop_positive == -0.1
|
||||
assert ('freqtrade.resolvers.strategy_resolver',
|
||||
@ -203,15 +206,15 @@ def test_strategy_override_trailing_stop_positive(caplog):
|
||||
) in caplog.record_tuples
|
||||
|
||||
|
||||
def test_strategy_override_ticker_interval(caplog):
|
||||
def test_strategy_override_ticker_interval(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
|
||||
config = {
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'ticker_interval': 60,
|
||||
'stake_currency': 'ETH'
|
||||
}
|
||||
resolver = StrategyResolver(config)
|
||||
})
|
||||
resolver = StrategyResolver(default_conf)
|
||||
|
||||
assert resolver.strategy.ticker_interval == 60
|
||||
assert resolver.strategy.stake_currency == 'ETH'
|
||||
@ -221,14 +224,14 @@ def test_strategy_override_ticker_interval(caplog):
|
||||
) in caplog.record_tuples
|
||||
|
||||
|
||||
def test_strategy_override_process_only_new_candles(caplog):
|
||||
def test_strategy_override_process_only_new_candles(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
|
||||
config = {
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'process_only_new_candles': True
|
||||
}
|
||||
resolver = StrategyResolver(config)
|
||||
})
|
||||
resolver = StrategyResolver(default_conf)
|
||||
|
||||
assert resolver.strategy.process_only_new_candles
|
||||
assert ('freqtrade.resolvers.strategy_resolver',
|
||||
@ -237,7 +240,7 @@ def test_strategy_override_process_only_new_candles(caplog):
|
||||
) in caplog.record_tuples
|
||||
|
||||
|
||||
def test_strategy_override_order_types(caplog):
|
||||
def test_strategy_override_order_types(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
|
||||
order_types = {
|
||||
@ -246,12 +249,11 @@ def test_strategy_override_order_types(caplog):
|
||||
'stoploss': 'limit',
|
||||
'stoploss_on_exchange': True,
|
||||
}
|
||||
|
||||
config = {
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'order_types': order_types
|
||||
}
|
||||
resolver = StrategyResolver(config)
|
||||
})
|
||||
resolver = StrategyResolver(default_conf)
|
||||
|
||||
assert resolver.strategy.order_types
|
||||
for method in ['buy', 'sell', 'stoploss', 'stoploss_on_exchange']:
|
||||
@ -264,18 +266,18 @@ def test_strategy_override_order_types(caplog):
|
||||
" 'stoploss_on_exchange': True}."
|
||||
) in caplog.record_tuples
|
||||
|
||||
config = {
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'order_types': {'buy': 'market'}
|
||||
}
|
||||
})
|
||||
# Raise error for invalid configuration
|
||||
with pytest.raises(ImportError,
|
||||
match=r"Impossible to load Strategy 'DefaultStrategy'. "
|
||||
r"Order-types mapping is incomplete."):
|
||||
StrategyResolver(config)
|
||||
StrategyResolver(default_conf)
|
||||
|
||||
|
||||
def test_strategy_override_order_tif(caplog):
|
||||
def test_strategy_override_order_tif(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
|
||||
order_time_in_force = {
|
||||
@ -283,11 +285,11 @@ def test_strategy_override_order_tif(caplog):
|
||||
'sell': 'gtc',
|
||||
}
|
||||
|
||||
config = {
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'order_time_in_force': order_time_in_force
|
||||
}
|
||||
resolver = StrategyResolver(config)
|
||||
})
|
||||
resolver = StrategyResolver(default_conf)
|
||||
|
||||
assert resolver.strategy.order_time_in_force
|
||||
for method in ['buy', 'sell']:
|
||||
@ -299,36 +301,36 @@ def test_strategy_override_order_tif(caplog):
|
||||
" {'buy': 'fok', 'sell': 'gtc'}."
|
||||
) in caplog.record_tuples
|
||||
|
||||
config = {
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'order_time_in_force': {'buy': 'fok'}
|
||||
}
|
||||
})
|
||||
# Raise error for invalid configuration
|
||||
with pytest.raises(ImportError,
|
||||
match=r"Impossible to load Strategy 'DefaultStrategy'. "
|
||||
r"Order-time-in-force mapping is incomplete."):
|
||||
StrategyResolver(config)
|
||||
StrategyResolver(default_conf)
|
||||
|
||||
|
||||
def test_strategy_override_use_sell_signal(caplog):
|
||||
def test_strategy_override_use_sell_signal(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
config = {
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
}
|
||||
resolver = StrategyResolver(config)
|
||||
})
|
||||
resolver = StrategyResolver(default_conf)
|
||||
assert not resolver.strategy.use_sell_signal
|
||||
assert isinstance(resolver.strategy.use_sell_signal, bool)
|
||||
# must be inserted to configuration
|
||||
assert 'use_sell_signal' in config['experimental']
|
||||
assert not config['experimental']['use_sell_signal']
|
||||
assert 'use_sell_signal' in default_conf['experimental']
|
||||
assert not default_conf['experimental']['use_sell_signal']
|
||||
|
||||
config = {
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'experimental': {
|
||||
'use_sell_signal': True,
|
||||
},
|
||||
}
|
||||
resolver = StrategyResolver(config)
|
||||
})
|
||||
resolver = StrategyResolver(default_conf)
|
||||
|
||||
assert resolver.strategy.use_sell_signal
|
||||
assert isinstance(resolver.strategy.use_sell_signal, bool)
|
||||
@ -338,25 +340,25 @@ def test_strategy_override_use_sell_signal(caplog):
|
||||
) in caplog.record_tuples
|
||||
|
||||
|
||||
def test_strategy_override_use_sell_profit_only(caplog):
|
||||
def test_strategy_override_use_sell_profit_only(caplog, default_conf):
|
||||
caplog.set_level(logging.INFO)
|
||||
config = {
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
}
|
||||
resolver = StrategyResolver(config)
|
||||
})
|
||||
resolver = StrategyResolver(default_conf)
|
||||
assert not resolver.strategy.sell_profit_only
|
||||
assert isinstance(resolver.strategy.sell_profit_only, bool)
|
||||
# must be inserted to configuration
|
||||
assert 'sell_profit_only' in config['experimental']
|
||||
assert not config['experimental']['sell_profit_only']
|
||||
assert 'sell_profit_only' in default_conf['experimental']
|
||||
assert not default_conf['experimental']['sell_profit_only']
|
||||
|
||||
config = {
|
||||
default_conf.update({
|
||||
'strategy': 'DefaultStrategy',
|
||||
'experimental': {
|
||||
'sell_profit_only': True,
|
||||
},
|
||||
}
|
||||
resolver = StrategyResolver(config)
|
||||
})
|
||||
resolver = StrategyResolver(default_conf)
|
||||
|
||||
assert resolver.strategy.sell_profit_only
|
||||
assert isinstance(resolver.strategy.sell_profit_only, bool)
|
||||
@ -367,10 +369,11 @@ def test_strategy_override_use_sell_profit_only(caplog):
|
||||
|
||||
|
||||
@pytest.mark.filterwarnings("ignore:deprecated")
|
||||
def test_deprecate_populate_indicators(result):
|
||||
def test_deprecate_populate_indicators(result, default_conf):
|
||||
default_location = path.join(path.dirname(path.realpath(__file__)))
|
||||
resolver = StrategyResolver({'strategy': 'TestStrategyLegacy',
|
||||
'strategy_path': default_location})
|
||||
default_conf.update({'strategy': 'TestStrategyLegacy',
|
||||
'strategy_path': default_location})
|
||||
resolver = StrategyResolver(default_conf)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
# Cause all warnings to always be triggered.
|
||||
warnings.simplefilter("always")
|
||||
@ -400,10 +403,11 @@ def test_deprecate_populate_indicators(result):
|
||||
|
||||
|
||||
@pytest.mark.filterwarnings("ignore:deprecated")
|
||||
def test_call_deprecated_function(result, monkeypatch):
|
||||
def test_call_deprecated_function(result, monkeypatch, default_conf):
|
||||
default_location = path.join(path.dirname(path.realpath(__file__)))
|
||||
resolver = StrategyResolver({'strategy': 'TestStrategyLegacy',
|
||||
'strategy_path': default_location})
|
||||
default_conf.update({'strategy': 'TestStrategyLegacy',
|
||||
'strategy_path': default_location})
|
||||
resolver = StrategyResolver(default_conf)
|
||||
metadata = {'pair': 'ETH/BTC'}
|
||||
|
||||
# Make sure we are using a legacy function
|
||||
|
Loading…
Reference in New Issue
Block a user