resolver: don't fail if user_data can't be found

This commit is contained in:
gcarq 2018-06-23 14:42:22 +02:00
parent 9c66c25890
commit 4ea5fcc661
2 changed files with 15 additions and 9 deletions

View File

@ -81,10 +81,13 @@ class StrategyResolver(object):
abs_paths.insert(0, extra_dir) abs_paths.insert(0, extra_dir)
for path in abs_paths: for path in abs_paths:
strategy = self._search_strategy(path, strategy_name) try:
if strategy: strategy = self._search_strategy(path, strategy_name)
logger.info('Using resolved strategy %s from \'%s\'', strategy_name, path) if strategy:
return import_strategy(strategy) logger.info('Using resolved strategy %s from \'%s\'', strategy_name, path)
return import_strategy(strategy)
except FileNotFoundError:
logger.warning('Path "%s" does not exist', path)
raise ImportError( raise ImportError(
"Impossible to load Strategy '{}'. This class does not exist" "Impossible to load Strategy '{}'. This class does not exist"

View File

@ -50,13 +50,16 @@ def test_load_strategy(result):
assert 'adx' in resolver.strategy.populate_indicators(result) assert 'adx' in resolver.strategy.populate_indicators(result)
def test_load_strategy_custom_directory(result): def test_load_strategy_invalid_directory(result, caplog):
resolver = StrategyResolver() resolver = StrategyResolver()
extra_dir = os.path.join('some', 'path') extra_dir = os.path.join('some', 'path')
with pytest.raises( resolver._load_strategy('TestStrategy', extra_dir)
FileNotFoundError,
match=r".*No such file or directory: '{}'".format(extra_dir)): assert (
resolver._load_strategy('TestStrategy', extra_dir) 'freqtrade.strategy.resolver',
logging.WARNING,
'Path "{}" does not exist'.format(extra_dir),
) in caplog.record_tuples
assert hasattr(resolver.strategy, 'populate_indicators') assert hasattr(resolver.strategy, 'populate_indicators')
assert 'adx' in resolver.strategy.populate_indicators(result) assert 'adx' in resolver.strategy.populate_indicators(result)