add create_userdir function
This commit is contained in:
parent
c85cd13ca1
commit
6c3a0eb1d6
@ -10,7 +10,7 @@ from typing import Any, Callable, Dict, Optional
|
||||
|
||||
from freqtrade import OperationalException, constants
|
||||
from freqtrade.configuration.check_exchange import check_exchange
|
||||
from freqtrade.configuration.create_datadir import create_datadir
|
||||
from freqtrade.configuration.folder_operations import create_datadir
|
||||
from freqtrade.configuration.json_schema import validate_config_schema
|
||||
from freqtrade.loggers import setup_logging
|
||||
from freqtrade.misc import deep_merge_dicts
|
||||
|
@ -18,3 +18,17 @@ def create_datadir(config: Dict[str, Any], datadir: Optional[str] = None) -> str
|
||||
folder.mkdir(parents=True)
|
||||
logger.info(f'Created data directory: {datadir}')
|
||||
return str(folder)
|
||||
|
||||
|
||||
def create_userdata_dir(directory: str):
|
||||
sub_dirs = ["backtest_results", "data", "hyperopts", "plots", "strategies", ]
|
||||
folder = Path(directory)
|
||||
if not folder.is_dir():
|
||||
folder.mkdir(parents=True)
|
||||
logger.info(f'Created user-data directory: {folder}')
|
||||
|
||||
# Create required subdirectories
|
||||
for f in sub_dirs:
|
||||
subfolder = folder / f
|
||||
if not subfolder.is_dir():
|
||||
subfolder.mkdir(parents=False)
|
@ -13,7 +13,7 @@ from jsonschema import Draft4Validator, ValidationError, validate
|
||||
from freqtrade import OperationalException, constants
|
||||
from freqtrade.configuration import Arguments, Configuration
|
||||
from freqtrade.configuration.check_exchange import check_exchange
|
||||
from freqtrade.configuration.create_datadir import create_datadir
|
||||
from freqtrade.configuration.folder_operations import create_datadir, create_userdata_dir
|
||||
from freqtrade.configuration.json_schema import validate_config_schema
|
||||
from freqtrade.constants import DEFAULT_DB_DRYRUN_URL, DEFAULT_DB_PROD_URL
|
||||
from freqtrade.loggers import _set_loggers
|
||||
@ -609,6 +609,24 @@ def test_create_datadir(mocker, default_conf, caplog) -> None:
|
||||
assert log_has('Created data directory: /foo/bar', caplog.record_tuples)
|
||||
|
||||
|
||||
def test_create_userdata_dir(mocker, default_conf, caplog) -> None:
|
||||
mocker.patch.object(Path, "is_dir", MagicMock(return_value=False))
|
||||
md = mocker.patch.object(Path, 'mkdir', MagicMock())
|
||||
|
||||
create_userdata_dir('/tmp/bar')
|
||||
assert md.call_count == 6
|
||||
assert md.call_args[1]['parents'] is False
|
||||
assert log_has('Created user-data directory: /tmp/bar', caplog.record_tuples)
|
||||
|
||||
|
||||
def test_create_userdata_dir_exists(mocker, default_conf, caplog) -> None:
|
||||
mocker.patch.object(Path, "is_dir", MagicMock(return_value=True))
|
||||
md = mocker.patch.object(Path, 'mkdir', MagicMock())
|
||||
|
||||
create_userdata_dir('/tmp/bar')
|
||||
assert md.call_count == 0
|
||||
|
||||
|
||||
def test_validate_tsl(default_conf):
|
||||
default_conf['trailing_stop'] = True
|
||||
default_conf['trailing_stop_positive'] = 0
|
||||
|
Loading…
Reference in New Issue
Block a user