Remove futher usages of Path(tmpdir)

This commit is contained in:
Matthias
2023-11-05 16:18:28 +01:00
parent 7bed7801cc
commit be82248e01
4 changed files with 47 additions and 55 deletions
+11 -14
View File
@@ -328,17 +328,16 @@ def test_hdf5datahandler_trades_load(testdatadir):
]) ])
def test_hdf5datahandler_ohlcv_load_and_resave( def test_hdf5datahandler_ohlcv_load_and_resave(
testdatadir, testdatadir,
tmpdir, tmp_path,
pair, pair,
timeframe, timeframe,
candle_type, candle_type,
candle_append, candle_append,
startdt, enddt startdt, enddt
): ):
tmpdir1 = Path(tmpdir) tmpdir2 = tmp_path
tmpdir2 = tmpdir1
if candle_type not in ('', 'spot'): if candle_type not in ('', 'spot'):
tmpdir2 = tmpdir1 / 'futures' tmpdir2 = tmp_path / 'futures'
tmpdir2.mkdir() tmpdir2.mkdir()
dh = get_datahandler(testdatadir, 'hdf5') dh = get_datahandler(testdatadir, 'hdf5')
ohlcv = dh._ohlcv_load(pair, timeframe, None, candle_type=candle_type) ohlcv = dh._ohlcv_load(pair, timeframe, None, candle_type=candle_type)
@@ -348,7 +347,7 @@ def test_hdf5datahandler_ohlcv_load_and_resave(
file = tmpdir2 / f"UNITTEST_NEW-{timeframe}{candle_append}.h5" file = tmpdir2 / f"UNITTEST_NEW-{timeframe}{candle_append}.h5"
assert not file.is_file() assert not file.is_file()
dh1 = get_datahandler(tmpdir1, 'hdf5') dh1 = get_datahandler(tmp_path, 'hdf5')
dh1.ohlcv_store('UNITTEST/NEW', timeframe, ohlcv, candle_type=candle_type) dh1.ohlcv_store('UNITTEST/NEW', timeframe, ohlcv, candle_type=candle_type)
assert file.is_file() assert file.is_file()
@@ -379,17 +378,16 @@ def test_hdf5datahandler_ohlcv_load_and_resave(
def test_generic_datahandler_ohlcv_load_and_resave( def test_generic_datahandler_ohlcv_load_and_resave(
datahandler, datahandler,
testdatadir, testdatadir,
tmpdir, tmp_path,
pair, pair,
timeframe, timeframe,
candle_type, candle_type,
candle_append, candle_append,
startdt, enddt startdt, enddt
): ):
tmpdir1 = Path(tmpdir) tmpdir2 = tmp_path
tmpdir2 = tmpdir1
if candle_type not in ('', 'spot'): if candle_type not in ('', 'spot'):
tmpdir2 = tmpdir1 / 'futures' tmpdir2 = tmp_path / 'futures'
tmpdir2.mkdir() tmpdir2.mkdir()
# Load data from one common file # Load data from one common file
dhbase = get_datahandler(testdatadir, 'feather') dhbase = get_datahandler(testdatadir, 'feather')
@@ -403,7 +401,7 @@ def test_generic_datahandler_ohlcv_load_and_resave(
file = tmpdir2 / f"UNITTEST_NEW-{timeframe}{candle_append}.{dh._get_file_extension()}" file = tmpdir2 / f"UNITTEST_NEW-{timeframe}{candle_append}.{dh._get_file_extension()}"
assert not file.is_file() assert not file.is_file()
dh1 = get_datahandler(tmpdir1, datahandler) dh1 = get_datahandler(tmp_path, datahandler)
dh1.ohlcv_store('UNITTEST/NEW', timeframe, ohlcv, candle_type=candle_type) dh1.ohlcv_store('UNITTEST/NEW', timeframe, ohlcv, candle_type=candle_type)
assert file.is_file() assert file.is_file()
@@ -459,15 +457,14 @@ def test_datahandler_trades_load(testdatadir, datahandler):
@pytest.mark.parametrize('datahandler', ['jsongz', 'hdf5', 'feather', 'parquet']) @pytest.mark.parametrize('datahandler', ['jsongz', 'hdf5', 'feather', 'parquet'])
def test_datahandler_trades_store(testdatadir, tmpdir, datahandler): def test_datahandler_trades_store(testdatadir, tmp_path, datahandler):
tmpdir1 = Path(tmpdir)
dh = get_datahandler(testdatadir, datahandler) dh = get_datahandler(testdatadir, datahandler)
trades = dh.trades_load('XRP/ETH') trades = dh.trades_load('XRP/ETH')
dh1 = get_datahandler(tmpdir1, datahandler) dh1 = get_datahandler(tmp_path, datahandler)
dh1.trades_store('XRP/NEW', trades) dh1.trades_store('XRP/NEW', trades)
file = tmpdir1 / f'XRP_NEW-trades.{dh1._get_file_extension()}' file = tmp_path / f'XRP_NEW-trades.{dh1._get_file_extension()}'
assert file.is_file() assert file.is_file()
# Load trades back # Load trades back
trades_new = dh1.trades_load('XRP/NEW') trades_new = dh1.trades_load('XRP/NEW')
+20 -24
View File
@@ -106,17 +106,16 @@ def test_load_data_startup_candles(mocker, testdatadir) -> None:
@pytest.mark.parametrize('candle_type', ['mark', '']) @pytest.mark.parametrize('candle_type', ['mark', ''])
def test_load_data_with_new_pair_1min(ohlcv_history_list, mocker, caplog, def test_load_data_with_new_pair_1min(ohlcv_history_list, mocker, caplog,
default_conf, tmpdir, candle_type) -> None: default_conf, tmp_path, candle_type) -> None:
""" """
Test load_pair_history() with 1 min timeframe Test load_pair_history() with 1 min timeframe
""" """
tmpdir1 = Path(tmpdir)
mocker.patch(f'{EXMS}.get_historic_ohlcv', return_value=ohlcv_history_list) mocker.patch(f'{EXMS}.get_historic_ohlcv', return_value=ohlcv_history_list)
exchange = get_patched_exchange(mocker, default_conf) exchange = get_patched_exchange(mocker, default_conf)
file = tmpdir1 / 'MEME_BTC-1m.feather' file = tmp_path / 'MEME_BTC-1m.feather'
# do not download a new pair if refresh_pairs isn't set # do not download a new pair if refresh_pairs isn't set
load_pair_history(datadir=tmpdir1, timeframe='1m', pair='MEME/BTC', candle_type=candle_type) load_pair_history(datadir=tmp_path, timeframe='1m', pair='MEME/BTC', candle_type=candle_type)
assert not file.is_file() assert not file.is_file()
assert log_has( assert log_has(
f"No history for MEME/BTC, {candle_type}, 1m found. " f"No history for MEME/BTC, {candle_type}, 1m found. "
@@ -124,10 +123,10 @@ def test_load_data_with_new_pair_1min(ohlcv_history_list, mocker, caplog,
) )
# download a new pair if refresh_pairs is set # download a new pair if refresh_pairs is set
refresh_data(datadir=tmpdir1, timeframe='1m', pairs=['MEME/BTC'], refresh_data(datadir=tmp_path, timeframe='1m', pairs=['MEME/BTC'],
exchange=exchange, candle_type=CandleType.SPOT exchange=exchange, candle_type=CandleType.SPOT
) )
load_pair_history(datadir=tmpdir1, timeframe='1m', pair='MEME/BTC', candle_type=candle_type) load_pair_history(datadir=tmp_path, timeframe='1m', pair='MEME/BTC', candle_type=candle_type)
assert file.is_file() assert file.is_file()
assert log_has_re( assert log_has_re(
r'\(0/1\) - Download history data for "MEME/BTC", 1m, ' r'\(0/1\) - Download history data for "MEME/BTC", 1m, '
@@ -273,27 +272,26 @@ def test_download_pair_history(
ohlcv_history_list, ohlcv_history_list,
mocker, mocker,
default_conf, default_conf,
tmpdir, tmp_path,
candle_type, candle_type,
subdir, subdir,
file_tail file_tail
) -> None: ) -> None:
mocker.patch(f'{EXMS}.get_historic_ohlcv', return_value=ohlcv_history_list) mocker.patch(f'{EXMS}.get_historic_ohlcv', return_value=ohlcv_history_list)
exchange = get_patched_exchange(mocker, default_conf) exchange = get_patched_exchange(mocker, default_conf)
tmpdir1 = Path(tmpdir) file1_1 = tmp_path / f'{subdir}MEME_BTC-1m{file_tail}.feather'
file1_1 = tmpdir1 / f'{subdir}MEME_BTC-1m{file_tail}.feather' file1_5 = tmp_path / f'{subdir}MEME_BTC-5m{file_tail}.feather'
file1_5 = tmpdir1 / f'{subdir}MEME_BTC-5m{file_tail}.feather' file2_1 = tmp_path / f'{subdir}CFI_BTC-1m{file_tail}.feather'
file2_1 = tmpdir1 / f'{subdir}CFI_BTC-1m{file_tail}.feather' file2_5 = tmp_path / f'{subdir}CFI_BTC-5m{file_tail}.feather'
file2_5 = tmpdir1 / f'{subdir}CFI_BTC-5m{file_tail}.feather'
assert not file1_1.is_file() assert not file1_1.is_file()
assert not file2_1.is_file() assert not file2_1.is_file()
assert _download_pair_history(datadir=tmpdir1, exchange=exchange, assert _download_pair_history(datadir=tmp_path, exchange=exchange,
pair='MEME/BTC', pair='MEME/BTC',
timeframe='1m', timeframe='1m',
candle_type=candle_type) candle_type=candle_type)
assert _download_pair_history(datadir=tmpdir1, exchange=exchange, assert _download_pair_history(datadir=tmp_path, exchange=exchange,
pair='CFI/BTC', pair='CFI/BTC',
timeframe='1m', timeframe='1m',
candle_type=candle_type) candle_type=candle_type)
@@ -308,11 +306,11 @@ def test_download_pair_history(
assert not file1_5.is_file() assert not file1_5.is_file()
assert not file2_5.is_file() assert not file2_5.is_file()
assert _download_pair_history(datadir=tmpdir1, exchange=exchange, assert _download_pair_history(datadir=tmp_path, exchange=exchange,
pair='MEME/BTC', pair='MEME/BTC',
timeframe='5m', timeframe='5m',
candle_type=candle_type) candle_type=candle_type)
assert _download_pair_history(datadir=tmpdir1, exchange=exchange, assert _download_pair_history(datadir=tmp_path, exchange=exchange,
pair='CFI/BTC', pair='CFI/BTC',
timeframe='5m', timeframe='5m',
candle_type=candle_type) candle_type=candle_type)
@@ -340,13 +338,12 @@ def test_download_pair_history2(mocker, default_conf, testdatadir) -> None:
assert json_dump_mock.call_count == 3 assert json_dump_mock.call_count == 3
def test_download_backtesting_data_exception(mocker, caplog, default_conf, tmpdir) -> None: def test_download_backtesting_data_exception(mocker, caplog, default_conf, tmp_path) -> None:
mocker.patch(f'{EXMS}.get_historic_ohlcv', mocker.patch(f'{EXMS}.get_historic_ohlcv',
side_effect=Exception('File Error')) side_effect=Exception('File Error'))
tmpdir1 = Path(tmpdir)
exchange = get_patched_exchange(mocker, default_conf) exchange = get_patched_exchange(mocker, default_conf)
assert not _download_pair_history(datadir=tmpdir1, exchange=exchange, assert not _download_pair_history(datadir=tmp_path, exchange=exchange,
pair='MEME/BTC', pair='MEME/BTC',
timeframe='1m', candle_type='spot') timeframe='1m', candle_type='spot')
assert log_has('Failed to download history data for pair: "MEME/BTC", timeframe: 1m.', caplog) assert log_has('Failed to download history data for pair: "MEME/BTC", timeframe: 1m.', caplog)
@@ -570,16 +567,15 @@ def test_refresh_backtest_trades_data(mocker, default_conf, markets, caplog, tes
def test_download_trades_history(trades_history, mocker, default_conf, testdatadir, caplog, def test_download_trades_history(trades_history, mocker, default_conf, testdatadir, caplog,
tmpdir, time_machine) -> None: tmp_path, time_machine) -> None:
start_dt = dt_utc(2023, 1, 1) start_dt = dt_utc(2023, 1, 1)
time_machine.move_to(start_dt, tick=False) time_machine.move_to(start_dt, tick=False)
tmpdir1 = Path(tmpdir)
ght_mock = MagicMock(side_effect=lambda pair, *args, **kwargs: (pair, trades_history)) ght_mock = MagicMock(side_effect=lambda pair, *args, **kwargs: (pair, trades_history))
mocker.patch(f'{EXMS}.get_historic_trades', ght_mock) mocker.patch(f'{EXMS}.get_historic_trades', ght_mock)
exchange = get_patched_exchange(mocker, default_conf) exchange = get_patched_exchange(mocker, default_conf)
file1 = tmpdir1 / 'ETH_BTC-trades.json.gz' file1 = tmp_path / 'ETH_BTC-trades.json.gz'
data_handler = get_datahandler(tmpdir1, data_format='jsongz') data_handler = get_datahandler(tmp_path, data_format='jsongz')
assert not file1.is_file() assert not file1.is_file()
@@ -614,7 +610,7 @@ def test_download_trades_history(trades_history, mocker, default_conf, testdatad
pair='ETH/BTC') pair='ETH/BTC')
assert log_has_re('Failed to download historic trades for pair: "ETH/BTC".*', caplog) assert log_has_re('Failed to download historic trades for pair: "ETH/BTC".*', caplog)
file2 = tmpdir1 / 'XRP_ETH-trades.json.gz' file2 = tmp_path / 'XRP_ETH-trades.json.gz'
copyfile(testdatadir / file2.name, file2) copyfile(testdatadir / file2.name, file2)
ght_mock.reset_mock() ght_mock.reset_mock()
+5 -6
View File
@@ -11,7 +11,7 @@ from freqtrade.exceptions import OperationalException
from tests.conftest import EXMS, log_has, log_has_re, patch_exchange from tests.conftest import EXMS, log_has, log_has_re, patch_exchange
def test_import_kraken_trades_from_csv(testdatadir, tmpdir, caplog, default_conf_usdt, mocker): def test_import_kraken_trades_from_csv(testdatadir, tmp_path, caplog, default_conf_usdt, mocker):
with pytest.raises(OperationalException, match="This function is only for the kraken exchange"): with pytest.raises(OperationalException, match="This function is only for the kraken exchange"):
import_kraken_trades_from_csv(default_conf_usdt, 'feather') import_kraken_trades_from_csv(default_conf_usdt, 'feather')
@@ -21,10 +21,9 @@ def test_import_kraken_trades_from_csv(testdatadir, tmpdir, caplog, default_conf
mocker.patch(f'{EXMS}.markets', PropertyMock(return_value={ mocker.patch(f'{EXMS}.markets', PropertyMock(return_value={
'BCH/EUR': {'symbol': 'BCH/EUR', 'id': 'BCHEUR', 'altname': 'BCHEUR'}, 'BCH/EUR': {'symbol': 'BCH/EUR', 'id': 'BCHEUR', 'altname': 'BCHEUR'},
})) }))
tmpdir1 = Path(tmpdir) dstfile = tmp_path / 'BCH_EUR-trades.feather'
dstfile = tmpdir1 / 'BCH_EUR-trades.feather'
assert not dstfile.is_file() assert not dstfile.is_file()
default_conf_usdt['datadir'] = tmpdir1 default_conf_usdt['datadir'] = tmp_path
# There's 2 files in this tree, containing a total of 2 days. # There's 2 files in this tree, containing a total of 2 days.
# tests/testdata/kraken/ # tests/testdata/kraken/
# └── trades_csv # └── trades_csv
@@ -32,7 +31,7 @@ def test_import_kraken_trades_from_csv(testdatadir, tmpdir, caplog, default_conf
# └── incremental_q2 # └── incremental_q2
# └── BCHEUR.csv <-- 2023-01-02 # └── BCHEUR.csv <-- 2023-01-02
copytree(testdatadir / 'kraken/trades_csv', tmpdir1 / 'trades_csv') copytree(testdatadir / 'kraken/trades_csv', tmp_path / 'trades_csv')
import_kraken_trades_from_csv(default_conf_usdt, 'feather') import_kraken_trades_from_csv(default_conf_usdt, 'feather')
assert log_has("Found csv files for BCHEUR.", caplog) assert log_has("Found csv files for BCHEUR.", caplog)
@@ -40,7 +39,7 @@ def test_import_kraken_trades_from_csv(testdatadir, tmpdir, caplog, default_conf
assert dstfile.is_file() assert dstfile.is_file()
dh = get_datahandler(tmpdir1, 'feather') dh = get_datahandler(tmp_path, 'feather')
trades = dh.trades_load('BCH_EUR') trades = dh.trades_load('BCH_EUR')
assert len(trades) == 340 assert len(trades) == 340
+11 -11
View File
@@ -1616,9 +1616,9 @@ def test_api_plot_config(botclient, mocker):
assert_response(rc) assert_response(rc)
def test_api_strategies(botclient, tmpdir): def test_api_strategies(botclient, tmp_path):
ftbot, client = botclient ftbot, client = botclient
ftbot.config['user_data_dir'] = Path(tmpdir) ftbot.config['user_data_dir'] = tmp_path
rc = client_get(client, f"{BASE_URI}/strategies") rc = client_get(client, f"{BASE_URI}/strategies")
@@ -1701,9 +1701,9 @@ def test_api_exchanges(botclient):
} }
def test_api_freqaimodels(botclient, tmpdir, mocker): def test_api_freqaimodels(botclient, tmp_path, mocker):
ftbot, client = botclient ftbot, client = botclient
ftbot.config['user_data_dir'] = Path(tmpdir) ftbot.config['user_data_dir'] = tmp_path
mocker.patch( mocker.patch(
"freqtrade.resolvers.freqaimodel_resolver.FreqaiModelResolver.search_all_objects", "freqtrade.resolvers.freqaimodel_resolver.FreqaiModelResolver.search_all_objects",
return_value=[ return_value=[
@@ -1739,9 +1739,9 @@ def test_api_freqaimodels(botclient, tmpdir, mocker):
]} ]}
def test_api_pairlists_available(botclient, tmpdir): def test_api_pairlists_available(botclient, tmp_path):
ftbot, client = botclient ftbot, client = botclient
ftbot.config['user_data_dir'] = Path(tmpdir) ftbot.config['user_data_dir'] = tmp_path
rc = client_get(client, f"{BASE_URI}/pairlists/available") rc = client_get(client, f"{BASE_URI}/pairlists/available")
@@ -1768,9 +1768,9 @@ def test_api_pairlists_available(botclient, tmpdir):
assert len(volumepl['params']) > 2 assert len(volumepl['params']) > 2
def test_api_pairlists_evaluate(botclient, tmpdir, mocker): def test_api_pairlists_evaluate(botclient, tmp_path, mocker):
ftbot, client = botclient ftbot, client = botclient
ftbot.config['user_data_dir'] = Path(tmpdir) ftbot.config['user_data_dir'] = tmp_path
rc = client_get(client, f"{BASE_URI}/pairlists/evaluate/randomJob") rc = client_get(client, f"{BASE_URI}/pairlists/evaluate/randomJob")
@@ -1905,7 +1905,7 @@ def test_sysinfo(botclient):
assert 'ram_pct' in result assert 'ram_pct' in result
def test_api_backtesting(botclient, mocker, fee, caplog, tmpdir): def test_api_backtesting(botclient, mocker, fee, caplog, tmp_path):
try: try:
ftbot, client = botclient ftbot, client = botclient
mocker.patch(f'{EXMS}.get_fee', fee) mocker.patch(f'{EXMS}.get_fee', fee)
@@ -1935,8 +1935,8 @@ def test_api_backtesting(botclient, mocker, fee, caplog, tmpdir):
assert result['status_msg'] == 'Backtest reset' assert result['status_msg'] == 'Backtest reset'
ftbot.config['export'] = 'trades' ftbot.config['export'] = 'trades'
ftbot.config['backtest_cache'] = 'day' ftbot.config['backtest_cache'] = 'day'
ftbot.config['user_data_dir'] = Path(tmpdir) ftbot.config['user_data_dir'] = tmp_path
ftbot.config['exportfilename'] = Path(tmpdir) / "backtest_results" ftbot.config['exportfilename'] = tmp_path / "backtest_results"
ftbot.config['exportfilename'].mkdir() ftbot.config['exportfilename'].mkdir()
# start backtesting # start backtesting