Fix some direct usages of "/tmp"
This commit is contained in:
@@ -401,11 +401,11 @@ def test_load_dry_run(default_conf, mocker, config_value, expected, arglist) ->
|
|||||||
assert validated_conf["runmode"] == (RunMode.DRY_RUN if expected else RunMode.LIVE)
|
assert validated_conf["runmode"] == (RunMode.DRY_RUN if expected else RunMode.LIVE)
|
||||||
|
|
||||||
|
|
||||||
def test_load_custom_strategy(default_conf, mocker) -> None:
|
def test_load_custom_strategy(default_conf, mocker, tmp_path) -> None:
|
||||||
default_conf.update(
|
default_conf.update(
|
||||||
{
|
{
|
||||||
"strategy": "CustomStrategy",
|
"strategy": "CustomStrategy",
|
||||||
"strategy_path": "/tmp/strategies",
|
"strategy_path": f"{tmp_path}/strategies",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
patched_configuration_load_config_file(mocker, default_conf)
|
patched_configuration_load_config_file(mocker, default_conf)
|
||||||
@@ -415,7 +415,7 @@ def test_load_custom_strategy(default_conf, mocker) -> None:
|
|||||||
validated_conf = configuration.load_config()
|
validated_conf = configuration.load_config()
|
||||||
|
|
||||||
assert validated_conf.get("strategy") == "CustomStrategy"
|
assert validated_conf.get("strategy") == "CustomStrategy"
|
||||||
assert validated_conf.get("strategy_path") == "/tmp/strategies"
|
assert validated_conf.get("strategy_path") == f"{tmp_path}/strategies"
|
||||||
|
|
||||||
|
|
||||||
def test_show_info(default_conf, mocker, caplog) -> None:
|
def test_show_info(default_conf, mocker, caplog) -> None:
|
||||||
@@ -469,7 +469,7 @@ def test_setup_configuration_without_arguments(mocker, default_conf, caplog) ->
|
|||||||
assert "timerange" not in config
|
assert "timerange" not in config
|
||||||
|
|
||||||
|
|
||||||
def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> None:
|
def test_setup_configuration_with_arguments(mocker, default_conf, caplog, tmp_path) -> None:
|
||||||
patched_configuration_load_config_file(mocker, default_conf)
|
patched_configuration_load_config_file(mocker, default_conf)
|
||||||
mocker.patch("freqtrade.configuration.configuration.create_datadir", lambda c, x: x)
|
mocker.patch("freqtrade.configuration.configuration.create_datadir", lambda c, x: x)
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
@@ -485,7 +485,7 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non
|
|||||||
"--datadir",
|
"--datadir",
|
||||||
"/foo/bar",
|
"/foo/bar",
|
||||||
"--userdir",
|
"--userdir",
|
||||||
"/tmp/freqtrade",
|
f"{tmp_path}/freqtrade",
|
||||||
"--timeframe",
|
"--timeframe",
|
||||||
"1m",
|
"1m",
|
||||||
"--enable-position-stacking",
|
"--enable-position-stacking",
|
||||||
@@ -509,7 +509,7 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non
|
|||||||
assert "pair_whitelist" in config["exchange"]
|
assert "pair_whitelist" in config["exchange"]
|
||||||
assert "datadir" in config
|
assert "datadir" in config
|
||||||
assert log_has("Using data directory: {} ...".format("/foo/bar"), caplog)
|
assert log_has("Using data directory: {} ...".format("/foo/bar"), caplog)
|
||||||
assert log_has("Using user-data directory: {} ...".format(Path("/tmp/freqtrade")), caplog)
|
assert log_has(f"Using user-data directory: {tmp_path}/freqtrade ...", caplog)
|
||||||
assert "user_data_dir" in config
|
assert "user_data_dir" in config
|
||||||
|
|
||||||
assert "timeframe" in config
|
assert "timeframe" in config
|
||||||
|
|||||||
@@ -24,16 +24,16 @@ def test_create_datadir(mocker, default_conf, caplog) -> None:
|
|||||||
assert log_has("Created data directory: /foo/bar", caplog)
|
assert log_has("Created data directory: /foo/bar", caplog)
|
||||||
|
|
||||||
|
|
||||||
def test_create_userdata_dir(mocker, default_conf, caplog) -> None:
|
def test_create_userdata_dir(mocker, tmp_path, caplog) -> None:
|
||||||
mocker.patch.object(Path, "is_dir", MagicMock(return_value=False))
|
mocker.patch.object(Path, "is_dir", MagicMock(return_value=False))
|
||||||
md = mocker.patch.object(Path, "mkdir", MagicMock())
|
md = mocker.patch.object(Path, "mkdir", MagicMock())
|
||||||
|
|
||||||
x = create_userdata_dir("/tmp/bar", create_dir=True)
|
x = create_userdata_dir(f"{tmp_path}/bar", create_dir=True)
|
||||||
assert md.call_count == 10
|
assert md.call_count == 10
|
||||||
assert md.call_args[1]["parents"] is False
|
assert md.call_args[1]["parents"] is False
|
||||||
assert log_has(f'Created user-data directory: {Path("/tmp/bar")}', caplog)
|
assert log_has(f'Created user-data directory: {f"{tmp_path}/bar"}', caplog)
|
||||||
assert isinstance(x, Path)
|
assert isinstance(x, Path)
|
||||||
assert str(x) == str(Path("/tmp/bar"))
|
assert str(x) == f"{tmp_path}/bar"
|
||||||
|
|
||||||
|
|
||||||
def test_create_userdata_dir_and_chown(mocker, tmp_path, caplog) -> None:
|
def test_create_userdata_dir_and_chown(mocker, tmp_path, caplog) -> None:
|
||||||
@@ -54,11 +54,11 @@ def test_create_userdata_dir_and_chown(mocker, tmp_path, caplog) -> None:
|
|||||||
del os.environ["FT_APP_ENV"]
|
del os.environ["FT_APP_ENV"]
|
||||||
|
|
||||||
|
|
||||||
def test_create_userdata_dir_exists(mocker, default_conf, caplog) -> None:
|
def test_create_userdata_dir_exists(mocker, tmp_path) -> None:
|
||||||
mocker.patch.object(Path, "is_dir", MagicMock(return_value=True))
|
mocker.patch.object(Path, "is_dir", MagicMock(return_value=True))
|
||||||
md = mocker.patch.object(Path, "mkdir", MagicMock())
|
md = mocker.patch.object(Path, "mkdir", MagicMock())
|
||||||
|
|
||||||
create_userdata_dir("/tmp/bar")
|
create_userdata_dir(f"{tmp_path}/bar")
|
||||||
assert md.call_count == 0
|
assert md.call_count == 0
|
||||||
|
|
||||||
|
|
||||||
@@ -73,21 +73,19 @@ def test_create_userdata_dir_exists_exception(mocker, default_conf, caplog) -> N
|
|||||||
assert md.call_count == 0
|
assert md.call_count == 0
|
||||||
|
|
||||||
|
|
||||||
def test_copy_sample_files(mocker, default_conf, caplog) -> None:
|
def test_copy_sample_files(mocker, tmp_path) -> None:
|
||||||
mocker.patch.object(Path, "is_dir", MagicMock(return_value=True))
|
mocker.patch.object(Path, "is_dir", MagicMock(return_value=True))
|
||||||
mocker.patch.object(Path, "exists", MagicMock(return_value=False))
|
mocker.patch.object(Path, "exists", MagicMock(return_value=False))
|
||||||
copymock = mocker.patch("shutil.copy", MagicMock())
|
copymock = mocker.patch("shutil.copy", MagicMock())
|
||||||
|
|
||||||
copy_sample_files(Path("/tmp/bar"))
|
copy_sample_files(Path(f"{tmp_path}/bar"))
|
||||||
assert copymock.call_count == 3
|
assert copymock.call_count == 3
|
||||||
assert copymock.call_args_list[0][0][1] == str(
|
assert copymock.call_args_list[0][0][1] == str(f"{tmp_path}/bar/strategies/sample_strategy.py")
|
||||||
Path("/tmp/bar") / "strategies/sample_strategy.py"
|
|
||||||
)
|
|
||||||
assert copymock.call_args_list[1][0][1] == str(
|
assert copymock.call_args_list[1][0][1] == str(
|
||||||
Path("/tmp/bar") / "hyperopts/sample_hyperopt_loss.py"
|
f"{tmp_path}/bar/hyperopts/sample_hyperopt_loss.py"
|
||||||
)
|
)
|
||||||
assert copymock.call_args_list[2][0][1] == str(
|
assert copymock.call_args_list[2][0][1] == str(
|
||||||
Path("/tmp/bar") / "notebooks/strategy_analysis_example.ipynb"
|
f"{tmp_path}/bar/notebooks/strategy_analysis_example.ipynb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user