Don't write to testdir, but to tempdir
This commit is contained in:
parent
a81a672ffe
commit
08f96df3ac
@ -919,7 +919,8 @@ def test_start_test_pairlist(mocker, caplog, tickers, default_conf, capsys):
|
||||
|
||||
|
||||
def test_hyperopt_list(mocker, capsys, caplog, saved_hyperopt_results,
|
||||
saved_hyperopt_results_legacy):
|
||||
saved_hyperopt_results_legacy, tmpdir):
|
||||
csv_file = Path(tmpdir) / "test.csv"
|
||||
for _ in (saved_hyperopt_results, saved_hyperopt_results_legacy):
|
||||
mocker.patch(
|
||||
'freqtrade.optimize.hyperopt_tools.HyperoptTools.load_previous_results',
|
||||
@ -1139,17 +1140,18 @@ def test_hyperopt_list(mocker, capsys, caplog, saved_hyperopt_results,
|
||||
"hyperopt-list",
|
||||
"--no-details",
|
||||
"--no-color",
|
||||
"--export-csv", "test_file.csv",
|
||||
"--export-csv",
|
||||
str(csv_file),
|
||||
]
|
||||
pargs = get_args(args)
|
||||
pargs['config'] = None
|
||||
start_hyperopt_list(pargs)
|
||||
captured = capsys.readouterr()
|
||||
log_has("CSV file created: test_file.csv", caplog)
|
||||
f = Path("test_file.csv")
|
||||
assert 'Best,1,2,-1.25%,-1.2222,-0.00125625,,-2.51,"3,930.0 m",0.43662' in f.read_text()
|
||||
assert f.is_file()
|
||||
f.unlink()
|
||||
assert ('Best,1,2,-1.25%,-1.2222,-0.00125625,,-2.51,"3,930.0 m",0.43662'
|
||||
in csv_file.read_text())
|
||||
assert csv_file.is_file()
|
||||
csv_file.unlink()
|
||||
|
||||
|
||||
def test_hyperopt_show(mocker, capsys, saved_hyperopt_results):
|
||||
|
@ -1,5 +1,7 @@
|
||||
# pragma pylint: disable=missing-docstring, C0103
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from shutil import copyfile
|
||||
|
||||
import pytest
|
||||
|
||||
@ -11,7 +13,7 @@ from freqtrade.data.converter import (convert_ohlcv_format, convert_trades_forma
|
||||
from freqtrade.data.history import (get_timerange, load_data, load_pair_history,
|
||||
validate_backtest_data)
|
||||
from tests.conftest import log_has, log_has_re
|
||||
from tests.data.test_history import _backup_file, _clean_test_file
|
||||
from tests.data.test_history import _clean_test_file
|
||||
|
||||
|
||||
def test_dataframe_correct_columns(result):
|
||||
@ -251,17 +253,19 @@ def test_trades_dict_to_list(fetch_trades_result):
|
||||
assert t[6] == fetch_trades_result[i]['cost']
|
||||
|
||||
|
||||
def test_convert_trades_format(mocker, default_conf, testdatadir):
|
||||
files = [{'old': testdatadir / "XRP_ETH-trades.json.gz",
|
||||
'new': testdatadir / "XRP_ETH-trades.json"},
|
||||
{'old': testdatadir / "XRP_OLD-trades.json.gz",
|
||||
'new': testdatadir / "XRP_OLD-trades.json"},
|
||||
def test_convert_trades_format(default_conf, testdatadir, tmpdir):
|
||||
tmpdir1 = Path(tmpdir)
|
||||
files = [{'old': tmpdir1 / "XRP_ETH-trades.json.gz",
|
||||
'new': tmpdir1 / "XRP_ETH-trades.json"},
|
||||
{'old': tmpdir1 / "XRP_OLD-trades.json.gz",
|
||||
'new': tmpdir1 / "XRP_OLD-trades.json"},
|
||||
]
|
||||
for file in files:
|
||||
_backup_file(file['old'], copy_file=True)
|
||||
copyfile(testdatadir / file['old'].name, file['old'])
|
||||
# _backup_file(file['old'], copy_file=True)
|
||||
assert not file['new'].exists()
|
||||
|
||||
default_conf['datadir'] = testdatadir
|
||||
default_conf['datadir'] = tmpdir1
|
||||
|
||||
convert_trades_format(default_conf, convert_from='jsongz',
|
||||
convert_to='json', erase=False)
|
||||
@ -284,14 +288,20 @@ def test_convert_trades_format(mocker, default_conf, testdatadir):
|
||||
file['new'].unlink()
|
||||
|
||||
|
||||
def test_convert_ohlcv_format(mocker, default_conf, testdatadir):
|
||||
file1 = testdatadir / "XRP_ETH-5m.json"
|
||||
file1_new = testdatadir / "XRP_ETH-5m.json.gz"
|
||||
file2 = testdatadir / "XRP_ETH-1m.json"
|
||||
file2_new = testdatadir / "XRP_ETH-1m.json.gz"
|
||||
_backup_file(file1, copy_file=True)
|
||||
_backup_file(file2, copy_file=True)
|
||||
default_conf['datadir'] = testdatadir
|
||||
def test_convert_ohlcv_format(default_conf, testdatadir, tmpdir):
|
||||
tmpdir1 = Path(tmpdir)
|
||||
|
||||
file1_orig = testdatadir / "XRP_ETH-5m.json"
|
||||
file1 = tmpdir1 / "XRP_ETH-5m.json"
|
||||
file1_new = tmpdir1 / "XRP_ETH-5m.json.gz"
|
||||
file2_orig = testdatadir / "XRP_ETH-1m.json"
|
||||
file2 = tmpdir1 / "XRP_ETH-1m.json"
|
||||
file2_new = tmpdir1 / "XRP_ETH-1m.json.gz"
|
||||
|
||||
copyfile(file1_orig, file1)
|
||||
copyfile(file2_orig, file2)
|
||||
|
||||
default_conf['datadir'] = tmpdir1
|
||||
default_conf['pairs'] = ['XRP_ETH']
|
||||
default_conf['timeframes'] = ['1m', '5m']
|
||||
|
||||
@ -317,10 +327,3 @@ def test_convert_ohlcv_format(mocker, default_conf, testdatadir):
|
||||
assert file2.exists()
|
||||
assert not file1_new.exists()
|
||||
assert not file2_new.exists()
|
||||
|
||||
_clean_test_file(file1)
|
||||
_clean_test_file(file2)
|
||||
if file1_new.exists():
|
||||
file1_new.unlink()
|
||||
if file2_new.exists():
|
||||
file2_new.unlink()
|
||||
|
@ -51,7 +51,7 @@ def test_text_table_bt_results():
|
||||
assert text_table_bt_results(pair_results, stake_currency='BTC') == result_str
|
||||
|
||||
|
||||
def test_generate_backtest_stats(default_conf, testdatadir):
|
||||
def test_generate_backtest_stats(default_conf, testdatadir, tmpdir):
|
||||
default_conf.update({'strategy': 'DefaultStrategy'})
|
||||
StrategyResolver.load_strategy(default_conf)
|
||||
|
||||
@ -148,8 +148,8 @@ def test_generate_backtest_stats(default_conf, testdatadir):
|
||||
assert strat_stats['pairlist'] == ['UNITTEST/BTC']
|
||||
|
||||
# Test storing stats
|
||||
filename = Path(testdatadir / 'btresult.json')
|
||||
filename_last = Path(testdatadir / LAST_BT_RESULT_FN)
|
||||
filename = Path(tmpdir / 'btresult.json')
|
||||
filename_last = Path(tmpdir / LAST_BT_RESULT_FN)
|
||||
_backup_file(filename_last, copy_file=True)
|
||||
assert not filename.is_file()
|
||||
|
||||
@ -159,7 +159,7 @@ def test_generate_backtest_stats(default_conf, testdatadir):
|
||||
last_fn = get_latest_backtest_filename(filename_last.parent)
|
||||
assert re.match(r"btresult-.*\.json", last_fn)
|
||||
|
||||
filename1 = (testdatadir / last_fn)
|
||||
filename1 = Path(tmpdir / last_fn)
|
||||
assert filename1.is_file()
|
||||
content = filename1.read_text()
|
||||
assert 'max_drawdown' in content
|
||||
|
Loading…
Reference in New Issue
Block a user