parent
730d2e3574
commit
bb1d8fb54f
@ -100,6 +100,9 @@ def get_latest_hyperopt_file(directory: Union[Path, str], predef_filename: str =
|
|||||||
if isinstance(directory, str):
|
if isinstance(directory, str):
|
||||||
directory = Path(directory)
|
directory = Path(directory)
|
||||||
if predef_filename:
|
if predef_filename:
|
||||||
|
if Path(predef_filename).is_absolute():
|
||||||
|
raise OperationalException(
|
||||||
|
"--hyperopt-filename expects only the filename, not an absolute path.")
|
||||||
return directory / predef_filename
|
return directory / predef_filename
|
||||||
return directory / get_latest_hyperopt_filename(directory)
|
return directory / get_latest_hyperopt_filename(directory)
|
||||||
|
|
||||||
|
@ -137,6 +137,7 @@ class HyperoptTools():
|
|||||||
}
|
}
|
||||||
if not HyperoptTools._test_hyperopt_results_exist(results_file):
|
if not HyperoptTools._test_hyperopt_results_exist(results_file):
|
||||||
# No file found.
|
# No file found.
|
||||||
|
logger.warning(f"Hyperopt file {results_file} not found.")
|
||||||
return [], 0
|
return [], 0
|
||||||
|
|
||||||
epochs = []
|
epochs = []
|
||||||
|
@ -51,6 +51,12 @@ def test_get_latest_hyperopt_file(testdatadir):
|
|||||||
res = get_latest_hyperopt_file(str(testdatadir.parent))
|
res = get_latest_hyperopt_file(str(testdatadir.parent))
|
||||||
assert res == testdatadir.parent / "hyperopt_results.pickle"
|
assert res == testdatadir.parent / "hyperopt_results.pickle"
|
||||||
|
|
||||||
|
# Test with absolute path
|
||||||
|
with pytest.raises(
|
||||||
|
OperationalException,
|
||||||
|
match="--hyperopt-filename expects only the filename, not an absolute path."):
|
||||||
|
get_latest_hyperopt_file(str(testdatadir.parent), str(testdatadir.parent))
|
||||||
|
|
||||||
|
|
||||||
def test_load_backtest_metadata(mocker, testdatadir):
|
def test_load_backtest_metadata(mocker, testdatadir):
|
||||||
res = load_backtest_metadata(testdatadir / 'nonexistant.file.json')
|
res = load_backtest_metadata(testdatadir / 'nonexistant.file.json')
|
||||||
|
@ -10,7 +10,7 @@ import rapidjson
|
|||||||
from freqtrade.constants import FTHYPT_FILEVERSION
|
from freqtrade.constants import FTHYPT_FILEVERSION
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.optimize.hyperopt_tools import HyperoptTools, hyperopt_serializer
|
from freqtrade.optimize.hyperopt_tools import HyperoptTools, hyperopt_serializer
|
||||||
from tests.conftest import log_has
|
from tests.conftest import log_has, log_has_re
|
||||||
|
|
||||||
|
|
||||||
# Functions for recurrent object patching
|
# Functions for recurrent object patching
|
||||||
@ -24,6 +24,7 @@ def test_save_results_saves_epochs(hyperopt, tmpdir, caplog) -> None:
|
|||||||
hyperopt.results_file = Path(tmpdir / 'ut_results.fthypt')
|
hyperopt.results_file = Path(tmpdir / 'ut_results.fthypt')
|
||||||
|
|
||||||
hyperopt_epochs = HyperoptTools.load_filtered_results(hyperopt.results_file, {})
|
hyperopt_epochs = HyperoptTools.load_filtered_results(hyperopt.results_file, {})
|
||||||
|
assert log_has_re("Hyperopt file .* not found.", caplog)
|
||||||
assert hyperopt_epochs == ([], 0)
|
assert hyperopt_epochs == ([], 0)
|
||||||
|
|
||||||
# Test writing to temp dir and reading again
|
# Test writing to temp dir and reading again
|
||||||
|
Loading…
Reference in New Issue
Block a user