Rename function and add test

This commit is contained in:
Matthias 2019-03-16 10:38:25 +01:00
parent edf2cd0b92
commit d42ebab575
2 changed files with 14 additions and 9 deletions

View File

@ -59,7 +59,7 @@ class Configuration(object):
logger.info('Validating configuration ...') logger.info('Validating configuration ...')
self._validate_config_schema(config) self._validate_config_schema(config)
self._validate_config(config) self._validate_config_consistency(config)
# Set strategy if not specified in config and or if it's non default # Set strategy if not specified in config and or if it's non default
if self.args.strategy != constants.DEFAULT_STRATEGY or not config.get('strategy'): if self.args.strategy != constants.DEFAULT_STRATEGY or not config.get('strategy'):
@ -310,11 +310,11 @@ class Configuration(object):
best_match(Draft4Validator(constants.CONF_SCHEMA).iter_errors(conf)).message best_match(Draft4Validator(constants.CONF_SCHEMA).iter_errors(conf)).message
) )
def _validate_config(self, conf: Dict[str, Any]) -> None: def _validate_config_consistency(self, conf: Dict[str, Any]) -> None:
""" """
Validate the configuration consistency Validate the configuration consistency
:param conf: Config in JSON format :param conf: Config in JSON format
:return: Returns None if everything is ok, otherwise throw an exception :return: Returns None if everything is ok, otherwise throw an OperationalException
""" """
# validating trailing stoploss # validating trailing stoploss
@ -332,11 +332,11 @@ class Configuration(object):
if tsl_only_offset: if tsl_only_offset:
if tsl_positive == 0.0: if tsl_positive == 0.0:
raise OperationalException( raise OperationalException(
f'The config trailing_only_offset_is_reached need ' f'The config trailing_only_offset_is_reached needs '
'trailing_stop_positive_offset to be more than 0 in your config.') 'trailing_stop_positive_offset to be more than 0 in your config.')
if tsl_positive > 0 and 0 < tsl_offset <= tsl_positive: if tsl_positive > 0 and 0 < tsl_offset <= tsl_positive:
raise OperationalException( raise OperationalException(
f'The config trailing_stop_positive_offset need ' f'The config trailing_stop_positive_offset needs '
'to be greater than trailing_stop_positive_offset in your config.') 'to be greater than trailing_stop_positive_offset in your config.')
def get_config(self) -> Dict[str, Any]: def get_config(self) -> Dict[str, Any]:

View File

@ -582,15 +582,20 @@ def test_validate_tsl(default_conf):
default_conf['trailing_only_offset_is_reached'] = True default_conf['trailing_only_offset_is_reached'] = True
with pytest.raises(OperationalException, with pytest.raises(OperationalException,
match=r'The config trailing_only_offset_is_reached need ' match=r'The config trailing_only_offset_is_reached needs '
'trailing_stop_positive_offset to be more than 0 in your config.'): 'trailing_stop_positive_offset to be more than 0 in your config.'):
configuration = Configuration(Namespace()) configuration = Configuration(Namespace())
configuration._validate_config(default_conf) configuration._validate_config_consistency(default_conf)
default_conf['trailing_stop_positive_offset'] = 0.01 default_conf['trailing_stop_positive_offset'] = 0.01
default_conf['trailing_stop_positive'] = 0.015 default_conf['trailing_stop_positive'] = 0.015
with pytest.raises(OperationalException, with pytest.raises(OperationalException,
match=r'The config trailing_stop_positive_offset need ' match=r'The config trailing_stop_positive_offset needs '
'to be greater than trailing_stop_positive_offset in your config.'): 'to be greater than trailing_stop_positive_offset in your config.'):
configuration = Configuration(Namespace()) configuration = Configuration(Namespace())
configuration._validate_config(default_conf) configuration._validate_config_consistency(default_conf)
default_conf['trailing_stop_positive'] = 0.01
default_conf['trailing_stop_positive_offset'] = 0.015
Configuration(Namespace())
configuration._validate_config_consistency(default_conf)