|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
import json
|
|
|
|
|
import re
|
|
|
|
|
import shutil
|
|
|
|
|
from datetime import timedelta
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from shutil import copyfile
|
|
|
|
|
@ -41,7 +42,7 @@ from freqtrade.optimize.optimize_reports.optimize_reports import (
|
|
|
|
|
from freqtrade.resolvers.strategy_resolver import StrategyResolver
|
|
|
|
|
from freqtrade.util import dt_ts
|
|
|
|
|
from freqtrade.util.datetime_helpers import dt_from_ts, dt_utc
|
|
|
|
|
from tests.conftest import CURRENT_TEST_STRATEGY
|
|
|
|
|
from tests.conftest import CURRENT_TEST_STRATEGY, log_has_re
|
|
|
|
|
from tests.data.test_history import _clean_test_file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -275,13 +276,16 @@ def test_store_backtest_results(testdatadir, mocker):
|
|
|
|
|
assert str(dump_mock.call_args_list[0][0][0]).startswith(str(testdatadir / "testresult"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_store_backtest_results_real(tmp_path):
|
|
|
|
|
def test_store_backtest_results_real(tmp_path, caplog):
|
|
|
|
|
data = {"metadata": {}, "strategy": {}, "strategy_comparison": []}
|
|
|
|
|
config = {
|
|
|
|
|
"exportfilename": tmp_path,
|
|
|
|
|
"original_config": {},
|
|
|
|
|
}
|
|
|
|
|
store_backtest_results(config, data, "2022_01_01_15_05_13")
|
|
|
|
|
store_backtest_results(
|
|
|
|
|
config, data, "2022_01_01_15_05_13", strategy_files={"DefStrat": "NoFile"}
|
|
|
|
|
)
|
|
|
|
|
assert log_has_re(r"Strategy file .* does not exist\. Skipping\.", caplog)
|
|
|
|
|
|
|
|
|
|
zip_file = tmp_path / "backtest-result-2022_01_01_15_05_13.zip"
|
|
|
|
|
assert zip_file.is_file()
|
|
|
|
|
@ -296,12 +300,17 @@ def test_store_backtest_results_real(tmp_path):
|
|
|
|
|
|
|
|
|
|
strategy_test_dir = Path(__file__).parent.parent / "strategy" / "strats"
|
|
|
|
|
|
|
|
|
|
shutil.copy(strategy_test_dir / "strategy_test_v3.py", tmp_path)
|
|
|
|
|
params_file = tmp_path / "strategy_test_v3.json"
|
|
|
|
|
with params_file.open("w") as f:
|
|
|
|
|
f.write("""{"strategy_name": "TurtleStrategyX5","params":{}}""")
|
|
|
|
|
|
|
|
|
|
store_backtest_results(
|
|
|
|
|
config,
|
|
|
|
|
data,
|
|
|
|
|
"2024_01_01_15_05_25",
|
|
|
|
|
market_change_data=pd.DataFrame(),
|
|
|
|
|
strategy_files={"DefStrat": str(strategy_test_dir / "strategy_test_v3.py")},
|
|
|
|
|
strategy_files={"DefStrat": str(tmp_path / "strategy_test_v3.py")},
|
|
|
|
|
)
|
|
|
|
|
zip_file = tmp_path / "backtest-result-2024_01_01_15_05_25.zip"
|
|
|
|
|
assert zip_file.is_file()
|
|
|
|
|
@ -320,6 +329,12 @@ def test_store_backtest_results_real(tmp_path):
|
|
|
|
|
with (strategy_test_dir / "strategy_test_v3.py").open("rb") as original_file:
|
|
|
|
|
original_content = original_file.read()
|
|
|
|
|
assert strategy_content == original_content
|
|
|
|
|
assert "backtest-result-2024_01_01_15_05_25_DefStrat.py" in zipf.namelist()
|
|
|
|
|
with zipf.open("backtest-result-2024_01_01_15_05_25_DefStrat.json") as pf:
|
|
|
|
|
params_content = pf.read()
|
|
|
|
|
with params_file.open("rb") as original_file:
|
|
|
|
|
original_content = original_file.read()
|
|
|
|
|
assert params_content == original_content
|
|
|
|
|
|
|
|
|
|
assert (tmp_path / LAST_BT_RESULT_FN).is_file()
|
|
|
|
|
|
|
|
|
|
|