diff --git a/freqtrade/resolvers/iresolver.py b/freqtrade/resolvers/iresolver.py index 922a2700a..52d944f2c 100644 --- a/freqtrade/resolvers/iresolver.py +++ b/freqtrade/resolvers/iresolver.py @@ -22,13 +22,15 @@ class IResolver: object_type: Type[Any] object_type_str: str user_subdir: Optional[str] = None - initial_search_path: Path + initial_search_path: Optional[Path] @classmethod def build_search_paths(cls, config: Dict[str, Any], user_subdir: Optional[str] = None, extra_dir: Optional[str] = None) -> List[Path]: - abs_paths: List[Path] = [cls.initial_search_path] + abs_paths: List[Path] = [] + if cls.initial_search_path: + abs_paths.append(cls.initial_search_path) if user_subdir: abs_paths.insert(0, config['user_data_dir'].joinpath(user_subdir)) diff --git a/freqtrade/resolvers/strategy_resolver.py b/freqtrade/resolvers/strategy_resolver.py index bb8ff870e..cddc7c9cd 100644 --- a/freqtrade/resolvers/strategy_resolver.py +++ b/freqtrade/resolvers/strategy_resolver.py @@ -27,7 +27,7 @@ class StrategyResolver(IResolver): object_type = IStrategy object_type_str = "Strategy" user_subdir = USERPATH_STRATEGIES - initial_search_path = Path(__file__).parent.parent.joinpath('strategy').resolve() + initial_search_path = None @staticmethod def load_strategy(config: Dict[str, Any] = None) -> IStrategy: diff --git a/tests/commands/test_commands.py b/tests/commands/test_commands.py index e5ee65ec1..a9fe0f637 100644 --- a/tests/commands/test_commands.py +++ b/tests/commands/test_commands.py @@ -640,7 +640,7 @@ def test_start_list_strategies(mocker, caplog, capsys): args = [ "list-strategies", "--strategy-path", - str(Path(__file__).parent.parent / "strategy"), + str(Path(__file__).parent.parent / "strategy" / "strats"), "-1" ] pargs = get_args(args) @@ -655,7 +655,7 @@ def test_start_list_strategies(mocker, caplog, capsys): args = [ "list-strategies", "--strategy-path", - str(Path(__file__).parent.parent / "strategy"), + str(Path(__file__).parent.parent / "strategy" / "strats"), ] pargs = get_args(args) # pargs['config'] = None diff --git a/tests/conftest.py b/tests/conftest.py index e897dbccd..acb730330 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -257,6 +257,7 @@ def default_conf(testdatadir): "db_url": "sqlite://", "user_data_dir": Path("user_data"), "verbosity": 3, + "strategy_path": str(Path(__file__).parent / "strategy" / "strats"), "strategy": "DefaultStrategy" } return configuration diff --git a/tests/optimize/test_backtesting.py b/tests/optimize/test_backtesting.py index ac9bcca5b..96855dc9d 100644 --- a/tests/optimize/test_backtesting.py +++ b/tests/optimize/test_backtesting.py @@ -715,14 +715,14 @@ def test_backtest_start_multi_strat(default_conf, mocker, caplog, testdatadir): 'backtesting', '--config', 'config.json', '--datadir', str(testdatadir), - '--strategy-path', str(Path(__file__).parents[2] / 'freqtrade/templates'), + '--strategy-path', str(Path(__file__).parents[1] / 'strategy/strats'), '--ticker-interval', '1m', '--timerange', '1510694220-1510700340', '--enable-position-stacking', '--disable-max-market-positions', '--strategy-list', 'DefaultStrategy', - 'SampleStrategy', + 'TestStrategyLegacy', ] args = get_args(args) start_backtesting(args) @@ -745,7 +745,7 @@ def test_backtest_start_multi_strat(default_conf, mocker, caplog, testdatadir): 'up to 2017-11-14T22:58:00+00:00 (0 days)..', 'Parameter --enable-position-stacking detected ...', 'Running backtesting for Strategy DefaultStrategy', - 'Running backtesting for Strategy SampleStrategy', + 'Running backtesting for Strategy TestStrategyLegacy', ] for line in exists: diff --git a/freqtrade/strategy/default_strategy.py b/tests/strategy/strats/default_strategy.py similarity index 100% rename from freqtrade/strategy/default_strategy.py rename to tests/strategy/strats/default_strategy.py diff --git a/tests/strategy/failing_strategy.py b/tests/strategy/strats/failing_strategy.py similarity index 100% rename from tests/strategy/failing_strategy.py rename to tests/strategy/strats/failing_strategy.py diff --git a/tests/strategy/legacy_strategy.py b/tests/strategy/strats/legacy_strategy.py similarity index 100% rename from tests/strategy/legacy_strategy.py rename to tests/strategy/strats/legacy_strategy.py diff --git a/tests/strategy/test_default_strategy.py b/tests/strategy/test_default_strategy.py index 17d6b8ee0..0b8ea9f85 100644 --- a/tests/strategy/test_default_strategy.py +++ b/tests/strategy/test_default_strategy.py @@ -1,6 +1,6 @@ from pandas import DataFrame -from freqtrade.strategy.default_strategy import DefaultStrategy +from .strats.default_strategy import DefaultStrategy def test_default_strategy_structure(): diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index 862f73ad1..86d0738c6 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -10,7 +10,7 @@ from freqtrade.configuration import TimeRange from freqtrade.data.history import load_data from freqtrade.persistence import Trade from freqtrade.resolvers import StrategyResolver -from freqtrade.strategy.default_strategy import DefaultStrategy +from .strats.default_strategy import DefaultStrategy from tests.conftest import get_patched_exchange, log_has # Avoid to reinit the same object again and again diff --git a/tests/strategy/test_strategy.py b/tests/strategy/test_strategy.py index 379260599..13ca68bf0 100644 --- a/tests/strategy/test_strategy.py +++ b/tests/strategy/test_strategy.py @@ -2,7 +2,6 @@ import logging import warnings from base64 import urlsafe_b64encode -from os import path from pathlib import Path import pytest @@ -15,7 +14,7 @@ from tests.conftest import log_has, log_has_re def test_search_strategy(): - default_location = Path(__file__).parent.parent.joinpath('strategy').resolve() + default_location = Path(__file__).parent / 'strats' s, _ = StrategyResolver._search_object( directory=default_location, @@ -31,21 +30,21 @@ def test_search_strategy(): def test_search_all_strategies_no_failed(): - directory = Path(__file__).parent + directory = Path(__file__).parent / "strats" strategies = StrategyResolver.search_all_objects(directory, enum_failed=False) assert isinstance(strategies, list) - assert len(strategies) == 3 + assert len(strategies) == 2 assert isinstance(strategies[0], dict) def test_search_all_strategies_with_failed(): - directory = Path(__file__).parent + directory = Path(__file__).parent / "strats" strategies = StrategyResolver.search_all_objects(directory, enum_failed=True) assert isinstance(strategies, list) - assert len(strategies) == 4 - # with enum_failed=True search_all_objects() shall find 3 good strategies + assert len(strategies) == 3 + # with enum_failed=True search_all_objects() shall find 2 good strategies # and 1 which fails to load - assert len([x for x in strategies if x['class'] is not None]) == 3 + assert len([x for x in strategies if x['class'] is not None]) == 2 assert len([x for x in strategies if x['class'] is None]) == 1 @@ -72,13 +71,12 @@ def test_load_strategy_base64(result, caplog, default_conf): def test_load_strategy_invalid_directory(result, caplog, default_conf): default_conf['strategy'] = 'DefaultStrategy' extra_dir = Path.cwd() / 'some/path' - strategy = StrategyResolver._load_strategy('DefaultStrategy', config=default_conf, - extra_dir=extra_dir) + with pytest.raises(OperationalException): + StrategyResolver._load_strategy('DefaultStrategy', config=default_conf, + extra_dir=extra_dir) assert log_has_re(r'Path .*' + r'some.*path.*' + r'.* does not exist', caplog) - assert 'rsi' in strategy.advise_indicators(result, {'pair': 'ETH/BTC'}) - def test_load_not_found_strategy(default_conf): default_conf['strategy'] = 'NotFoundStrategy' @@ -326,7 +324,7 @@ def test_strategy_override_use_sell_profit_only(caplog, default_conf): @pytest.mark.filterwarnings("ignore:deprecated") def test_deprecate_populate_indicators(result, default_conf): - default_location = path.join(path.dirname(path.realpath(__file__))) + default_location = Path(__file__).parent / "strats" default_conf.update({'strategy': 'TestStrategyLegacy', 'strategy_path': default_location}) strategy = StrategyResolver.load_strategy(default_conf) @@ -360,7 +358,7 @@ def test_deprecate_populate_indicators(result, default_conf): @pytest.mark.filterwarnings("ignore:deprecated") def test_call_deprecated_function(result, monkeypatch, default_conf): - default_location = path.join(path.dirname(path.realpath(__file__))) + default_location = Path(__file__).parent / "strats" default_conf.update({'strategy': 'TestStrategyLegacy', 'strategy_path': default_location}) strategy = StrategyResolver.load_strategy(default_conf) diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 74de166c1..d810305db 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -212,6 +212,7 @@ def test_load_config_file_exception(mocker) -> None: def test_load_config(default_conf, mocker) -> None: + del default_conf['strategy_path'] patched_configuration_load_config_file(mocker, default_conf) args = Arguments(['trade']).get_parsed_arg()