Add test for get_last_backtest_Result
This commit is contained in:
parent
7727292861
commit
04eaf2c39c
@ -33,17 +33,17 @@ def get_latest_backtest_filename(directory: Union[Path, str]) -> str:
|
||||
if isinstance(directory, str):
|
||||
directory = Path(directory)
|
||||
if not directory.is_dir():
|
||||
raise ValueError(f"Directory {directory} does not exist.")
|
||||
raise ValueError(f"Directory '{directory}' does not exist.")
|
||||
filename = directory / '.last_result.json'
|
||||
|
||||
if not filename.is_file():
|
||||
raise ValueError(f"Directory {directory} does not seem to contain backtest statistics yet.")
|
||||
raise ValueError(f"Directory '{directory}' does not seem to contain backtest statistics yet.")
|
||||
|
||||
with filename.open() as file:
|
||||
data = json_load(file)
|
||||
|
||||
if 'latest_backtest' not in data:
|
||||
raise ValueError("Invalid .last_result.json format")
|
||||
raise ValueError("Invalid '.last_result.json' format.")
|
||||
|
||||
return data['latest_backtest']
|
||||
|
||||
|
@ -13,12 +13,31 @@ from freqtrade.data.btanalysis import (BT_DATA_COLUMNS,
|
||||
combine_dataframes_with_mean,
|
||||
create_cum_profit,
|
||||
extract_trades_of_period,
|
||||
get_latest_backtest_filename,
|
||||
load_backtest_data, load_trades,
|
||||
load_trades_from_db)
|
||||
from freqtrade.data.history import load_data, load_pair_history
|
||||
from tests.conftest import create_mock_trades
|
||||
|
||||
|
||||
def test_get_latest_backtest_filename(testdatadir, mocker):
|
||||
with pytest.raises(ValueError, match=r"Directory .* does not exist\."):
|
||||
get_latest_backtest_filename(testdatadir / 'does_not_exist')
|
||||
|
||||
with pytest.raises(ValueError,
|
||||
match=r"Directory .* does not seem to contain .*"):
|
||||
get_latest_backtest_filename(testdatadir.parent)
|
||||
|
||||
res = get_latest_backtest_filename(testdatadir)
|
||||
assert res == 'backtest-result_new.json'
|
||||
|
||||
mocker.patch("freqtrade.data.btanalysis.json_load", return_value={})
|
||||
|
||||
|
||||
with pytest.raises(ValueError, match=r"Invalid '.last_result.json' format."):
|
||||
get_latest_backtest_filename(testdatadir)
|
||||
|
||||
|
||||
def test_load_backtest_data(testdatadir):
|
||||
|
||||
filename = testdatadir / "backtest-result_test.json"
|
||||
|
1
tests/testdata/.last_result.json
vendored
Normal file
1
tests/testdata/.last_result.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"latest_backtest":"backtest-result_new.json"}
|
1
tests/testdata/backtest-result_new.json
vendored
Normal file
1
tests/testdata/backtest-result_new.json
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user