Add test for get_last_backtest_Result
This commit is contained in:
@@ -33,17 +33,17 @@ def get_latest_backtest_filename(directory: Union[Path, str]) -> str:
|
|||||||
if isinstance(directory, str):
|
if isinstance(directory, str):
|
||||||
directory = Path(directory)
|
directory = Path(directory)
|
||||||
if not directory.is_dir():
|
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'
|
filename = directory / '.last_result.json'
|
||||||
|
|
||||||
if not filename.is_file():
|
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:
|
with filename.open() as file:
|
||||||
data = json_load(file)
|
data = json_load(file)
|
||||||
|
|
||||||
if 'latest_backtest' not in data:
|
if 'latest_backtest' not in data:
|
||||||
raise ValueError("Invalid .last_result.json format")
|
raise ValueError("Invalid '.last_result.json' format.")
|
||||||
|
|
||||||
return data['latest_backtest']
|
return data['latest_backtest']
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,31 @@ from freqtrade.data.btanalysis import (BT_DATA_COLUMNS,
|
|||||||
combine_dataframes_with_mean,
|
combine_dataframes_with_mean,
|
||||||
create_cum_profit,
|
create_cum_profit,
|
||||||
extract_trades_of_period,
|
extract_trades_of_period,
|
||||||
|
get_latest_backtest_filename,
|
||||||
load_backtest_data, load_trades,
|
load_backtest_data, load_trades,
|
||||||
load_trades_from_db)
|
load_trades_from_db)
|
||||||
from freqtrade.data.history import load_data, load_pair_history
|
from freqtrade.data.history import load_data, load_pair_history
|
||||||
from tests.conftest import create_mock_trades
|
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):
|
def test_load_backtest_data(testdatadir):
|
||||||
|
|
||||||
filename = testdatadir / "backtest-result_test.json"
|
filename = testdatadir / "backtest-result_test.json"
|
||||||
|
|||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
{"latest_backtest":"backtest-result_new.json"}
|
||||||
+1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user