Remove further usages of Path(tmpdir)

This commit is contained in:
Matthias
2023-11-05 16:25:23 +01:00
parent 555f4b51e1
commit 5a3839320d
5 changed files with 33 additions and 33 deletions

View File

@@ -193,8 +193,8 @@ def test_start_no_hyperopt_allowed(mocker, hyperopt_conf, caplog) -> None:
start_hyperopt(pargs)
def test_start_no_data(mocker, hyperopt_conf, tmpdir) -> None:
hyperopt_conf['user_data_dir'] = Path(tmpdir)
def test_start_no_data(mocker, hyperopt_conf, tmp_path) -> None:
hyperopt_conf['user_data_dir'] = tmp_path
patched_configuration_load_config_file(mocker, hyperopt_conf)
mocker.patch('freqtrade.data.history.load_pair_history', MagicMock(return_value=pd.DataFrame))
mocker.patch(
@@ -857,14 +857,14 @@ def test_simplified_interface_failed(mocker, hyperopt_conf, space) -> None:
hyperopt.start()
def test_in_strategy_auto_hyperopt(mocker, hyperopt_conf, tmpdir, fee) -> None:
def test_in_strategy_auto_hyperopt(mocker, hyperopt_conf, tmp_path, fee) -> None:
patch_exchange(mocker)
mocker.patch(f'{EXMS}.get_fee', fee)
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
(tmp_path / 'hyperopt_results').mkdir(parents=True)
# No hyperopt needed
hyperopt_conf.update({
'strategy': 'HyperoptableStrategy',
'user_data_dir': Path(tmpdir),
'user_data_dir': tmp_path,
'hyperopt_random_state': 42,
'spaces': ['all'],
})
@@ -897,17 +897,17 @@ def test_in_strategy_auto_hyperopt(mocker, hyperopt_conf, tmpdir, fee) -> None:
hyperopt.get_optimizer([], 2)
def test_in_strategy_auto_hyperopt_with_parallel(mocker, hyperopt_conf, tmpdir, fee) -> None:
def test_in_strategy_auto_hyperopt_with_parallel(mocker, hyperopt_conf, tmp_path, fee) -> None:
mocker.patch(f'{EXMS}.validate_config', MagicMock())
mocker.patch(f'{EXMS}.get_fee', fee)
mocker.patch(f'{EXMS}._load_markets')
mocker.patch(f'{EXMS}.markets',
PropertyMock(return_value=get_markets()))
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
(tmp_path / 'hyperopt_results').mkdir(parents=True)
# No hyperopt needed
hyperopt_conf.update({
'strategy': 'HyperoptableStrategy',
'user_data_dir': Path(tmpdir),
'user_data_dir': tmp_path,
'hyperopt_random_state': 42,
'spaces': ['all'],
# Enforce parallelity
@@ -938,14 +938,14 @@ def test_in_strategy_auto_hyperopt_with_parallel(mocker, hyperopt_conf, tmpdir,
hyperopt.start()
def test_in_strategy_auto_hyperopt_per_epoch(mocker, hyperopt_conf, tmpdir, fee) -> None:
def test_in_strategy_auto_hyperopt_per_epoch(mocker, hyperopt_conf, tmp_path, fee) -> None:
patch_exchange(mocker)
mocker.patch(f'{EXMS}.get_fee', fee)
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
(tmp_path / 'hyperopt_results').mkdir(parents=True)
hyperopt_conf.update({
'strategy': 'HyperoptableStrategy',
'user_data_dir': Path(tmpdir),
'user_data_dir': tmp_path,
'hyperopt_random_state': 42,
'spaces': ['all'],
'epochs': 3,
@@ -995,15 +995,15 @@ def test_SKDecimal():
assert space.transform([1.5, 1.6]) == [150, 160]
def test_stake_amount_unlimited_max_open_trades(mocker, hyperopt_conf, tmpdir, fee) -> None:
def test_stake_amount_unlimited_max_open_trades(mocker, hyperopt_conf, tmp_path, fee) -> None:
# This test is to ensure that unlimited max_open_trades are ignored for the backtesting
# if we have an unlimited stake amount
patch_exchange(mocker)
mocker.patch(f'{EXMS}.get_fee', fee)
(Path(tmpdir) / 'hyperopt_results').mkdir(parents=True)
(tmp_path / 'hyperopt_results').mkdir(parents=True)
hyperopt_conf.update({
'strategy': 'HyperoptableStrategy',
'user_data_dir': Path(tmpdir),
'user_data_dir': tmp_path,
'hyperopt_random_state': 42,
'spaces': ['trades'],
'stake_amount': 'unlimited'

View File

@@ -74,7 +74,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, tmpdir):
def test_generate_backtest_stats(default_conf, testdatadir, tmp_path):
default_conf.update({'strategy': CURRENT_TEST_STRATEGY})
StrategyResolver.load_strategy(default_conf)
@@ -185,8 +185,8 @@ def test_generate_backtest_stats(default_conf, testdatadir, tmpdir):
assert strat_stats['pairlist'] == ['UNITTEST/BTC']
# Test storing stats
filename = Path(tmpdir / 'btresult.json')
filename_last = Path(tmpdir / LAST_BT_RESULT_FN)
filename = tmp_path / 'btresult.json'
filename_last = tmp_path / LAST_BT_RESULT_FN
_backup_file(filename_last, copy_file=True)
assert not filename.is_file()
@@ -196,7 +196,7 @@ def test_generate_backtest_stats(default_conf, testdatadir, tmpdir):
last_fn = get_latest_backtest_filename(filename_last.parent)
assert re.match(r"btresult-.*\.json", last_fn)
filename1 = Path(tmpdir / last_fn)
filename1 = tmp_path / last_fn
assert filename1.is_file()
content = filename1.read_text()
assert 'max_drawdown_account' in content
@@ -254,14 +254,14 @@ def test_store_backtest_candles(testdatadir, mocker):
dump_mock.reset_mock()
def test_write_read_backtest_candles(tmpdir):
def test_write_read_backtest_candles(tmp_path):
candle_dict = {'DefStrat': {'UNITTEST/BTC': pd.DataFrame()}}
# test directory exporting
sample_date = '2022_01_01_15_05_13'
store_backtest_analysis_results(Path(tmpdir), candle_dict, {}, sample_date)
stored_file = Path(tmpdir / f'backtest-result-{sample_date}_signals.pkl')
store_backtest_analysis_results(tmp_path, candle_dict, {}, sample_date)
stored_file = tmp_path / f'backtest-result-{sample_date}_signals.pkl'
with stored_file.open("rb") as scp:
pickled_signal_candles = joblib.load(scp)
@@ -273,9 +273,9 @@ def test_write_read_backtest_candles(tmpdir):
_clean_test_file(stored_file)
# test file exporting
filename = Path(tmpdir / 'testresult')
filename = tmp_path / 'testresult'
store_backtest_analysis_results(filename, candle_dict, {}, sample_date)
stored_file = Path(tmpdir / f'testresult-{sample_date}_signals.pkl')
stored_file = tmp_path / f'testresult-{sample_date}_signals.pkl'
with stored_file.open("rb") as scp:
pickled_signal_candles = joblib.load(scp)