Properly default to user_data/config.json if it exists

This commit is contained in:
Matthias
2020-02-14 20:04:05 +01:00
parent be4a9b5f4b
commit 5efbdd25a7
4 changed files with 66 additions and 25 deletions

View File

@@ -18,7 +18,8 @@ def test_parse_args_none() -> None:
assert isinstance(arguments.parser, argparse.ArgumentParser)
def test_parse_args_defaults() -> None:
def test_parse_args_defaults(mocker) -> None:
mocker.patch.object(Path, "is_file", MagicMock(side_effect=[False, True]))
args = Arguments(['trade']).get_parsed_arg()
assert args["config"] == ['config.json']
assert args["strategy_path"] is None
@@ -26,6 +27,25 @@ def test_parse_args_defaults() -> None:
assert args["verbosity"] == 0
def test_parse_args_default_userdatadir(mocker) -> None:
mocker.patch.object(Path, "is_file", MagicMock(return_value=True))
args = Arguments(['trade']).get_parsed_arg()
# configuration defaults to user_data if that is available.
assert args["config"] == ['user_data/config.json']
assert args["strategy_path"] is None
assert args["datadir"] is None
assert args["verbosity"] == 0
def test_parse_args_userdatadir(mocker) -> None:
mocker.patch.object(Path, "is_file", MagicMock(return_value=True))
args = Arguments(['trade', '--user-data-dir', 'user_data']).get_parsed_arg()
# configuration defaults to user_data if that is available.
assert args["config"] == ['user_data/config.json']
assert args["strategy_path"] is None
assert args["datadir"] is None
assert args["verbosity"] == 0
def test_parse_args_config() -> None:
args = Arguments(['trade', '-c', '/dev/null']).get_parsed_arg()
assert args["config"] == ['/dev/null']
@@ -208,7 +228,7 @@ def test_config_notrequired(mocker) -> None:
assert pargs["config"] is None
# When file exists:
mocker.patch.object(Path, "is_file", MagicMock(return_value=True))
mocker.patch.object(Path, "is_file", MagicMock(side_effect=[False, True]))
args = [
'download-data',
]

View File

@@ -5,8 +5,9 @@ from unittest.mock import MagicMock, PropertyMock
import pytest
from pathlib import Path
from freqtrade.commands import Arguments
from freqtrade.exceptions import OperationalException, FreqtradeException
from freqtrade.exceptions import FreqtradeException, OperationalException
from freqtrade.freqtradebot import FreqtradeBot
from freqtrade.main import main
from freqtrade.state import State
@@ -26,6 +27,7 @@ def test_parse_args_backtesting(mocker) -> None:
Test that main() can start backtesting and also ensure we can pass some specific arguments
further argument parsing is done in test_arguments.py
"""
mocker.patch.object(Path, "is_file", MagicMock(side_effect=[False, True]))
backtesting_mock = mocker.patch('freqtrade.commands.start_backtesting')
backtesting_mock.__name__ = PropertyMock("start_backtesting")
# it's sys.exit(0) at the end of backtesting
@@ -42,6 +44,7 @@ def test_parse_args_backtesting(mocker) -> None:
def test_main_start_hyperopt(mocker) -> None:
mocker.patch.object(Path, "is_file", MagicMock(side_effect=[False, True]))
hyperopt_mock = mocker.patch('freqtrade.commands.start_hyperopt', MagicMock())
hyperopt_mock.__name__ = PropertyMock("start_hyperopt")
# it's sys.exit(0) at the end of hyperopt