Remove Strategy fallback to default strategy (#490)

* Remove Strategy fallback to default strategy
This commit is contained in:
Gérald LONLAS
2018-02-02 01:01:09 -08:00
committed by Janne Sinivirta
parent 0f041b424d
commit d24cd89304
5 changed files with 28 additions and 8 deletions

View File

@@ -163,7 +163,7 @@ def common_args_parser(description: str):
'-s', '--strategy',
help='specify strategy file (default: freqtrade/strategy/default_strategy.py)',
dest='strategy',
default='.default_strategy',
default='default_strategy',
type=str,
metavar='PATH',
)

View File

@@ -95,8 +95,16 @@ class Strategy(object):
self.custom_strategy = self._load_class(path + strategy_name)
# Fallback to the default strategy
except (ImportError, TypeError):
self.custom_strategy = self._load_class('.' + self.DEFAULT_STRATEGY)
except (ImportError, TypeError) as error:
self.logger.error(
"Impossible to load Strategy 'user_data/strategies/%s.py'. This file does not exist"
" or contains Python code errors",
strategy_name
)
self.logger.error(
"The error is:\n%s.",
error
)
def _load_class(self, filename: str) -> IStrategy:
"""

View File

@@ -32,7 +32,7 @@ def test_load_strategy(result):
strategy.logger = logging.getLogger(__name__)
assert not hasattr(Strategy, 'custom_strategy')
strategy._load_strategy('default_strategy')
strategy._load_strategy('test_strategy')
assert not hasattr(Strategy, 'custom_strategy')
@@ -40,6 +40,18 @@ def test_load_strategy(result):
assert 'adx' in strategy.populate_indicators(result)
def test_load_not_found_strategy(caplog):
strategy = Strategy()
strategy.logger = logging.getLogger(__name__)
assert not hasattr(Strategy, 'custom_strategy')
strategy._load_strategy('NotFoundStrategy')
error_msg = "Impossible to load Strategy 'user_data/strategies/{}.py'. This file does not " \
"exist or contains Python code errors".format('NotFoundStrategy')
assert ('test_strategy', logging.ERROR, error_msg) in caplog.record_tuples
def test_strategy(result):
strategy = Strategy()
strategy.init({'strategy': 'default_strategy'})