diff --git a/tests/commands/test_commands.py b/tests/commands/test_commands.py index e066eac01..a0e7b8376 100644 --- a/tests/commands/test_commands.py +++ b/tests/commands/test_commands.py @@ -550,7 +550,7 @@ def test_start_install_ui(mocker): assert download_mock.call_count == 0 -def test_clean_ui_subdir(mocker, tmpdir, caplog): +def test_clean_ui_subdir(mocker, tmp_path, caplog): mocker.patch("freqtrade.commands.deploy_commands.Path.is_dir", side_effect=[True, True]) mocker.patch("freqtrade.commands.deploy_commands.Path.is_file", @@ -560,14 +560,14 @@ def test_clean_ui_subdir(mocker, tmpdir, caplog): mocker.patch("freqtrade.commands.deploy_commands.Path.glob", return_value=[Path('test1'), Path('test2'), Path('.gitkeep')]) - folder = Path(tmpdir) / "uitests" + folder = tmp_path / "uitests" clean_ui_subdir(folder) assert log_has("Removing UI directory content.", caplog) assert rd_mock.call_count == 1 assert ul_mock.call_count == 1 -def test_download_and_install_ui(mocker, tmpdir): +def test_download_and_install_ui(mocker, tmp_path): # Create zipfile requests_mock = MagicMock() file_like_object = BytesIO() @@ -583,7 +583,7 @@ def test_download_and_install_ui(mocker, tmpdir): side_effect=[True, False]) wb_mock = mocker.patch("freqtrade.commands.deploy_commands.Path.write_bytes") - folder = Path(tmpdir) / "uitests_dl" + folder = tmp_path / "uitests_dl" folder.mkdir(exist_ok=True) assert read_ui_version(folder) is None @@ -1010,8 +1010,8 @@ def test_start_test_pairlist(mocker, caplog, tickers, default_conf, capsys): pytest.fail(f'Expected well formed JSON, but failed to parse: {captured.out}') -def test_hyperopt_list(mocker, capsys, caplog, saved_hyperopt_results, tmpdir): - csv_file = Path(tmpdir) / "test.csv" +def test_hyperopt_list(mocker, capsys, caplog, saved_hyperopt_results, tmp_path): + csv_file = tmp_path / "test.csv" mocker.patch( 'freqtrade.optimize.hyperopt_tools.HyperoptTools._test_hyperopt_results_exist', return_value=True diff --git a/tests/optimize/test_hyperopt.py b/tests/optimize/test_hyperopt.py index 81c0d9ece..b858aa33c 100644 --- a/tests/optimize/test_hyperopt.py +++ b/tests/optimize/test_hyperopt.py @@ -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' diff --git a/tests/optimize/test_optimize_reports.py b/tests/optimize/test_optimize_reports.py index 7624757e2..a65c3f277 100644 --- a/tests/optimize/test_optimize_reports.py +++ b/tests/optimize/test_optimize_reports.py @@ -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) diff --git a/tests/test_configuration.py b/tests/test_configuration.py index bbd299e6a..6472faf37 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -601,9 +601,9 @@ def test_cli_verbose_with_params(default_conf, mocker, caplog) -> None: assert log_has('Verbosity set to 3', caplog) -def test_set_logfile(default_conf, mocker, tmpdir): +def test_set_logfile(default_conf, mocker, tmp_path): patched_configuration_load_config_file(mocker, default_conf) - f = Path(tmpdir / "test_file.log") + f = tmp_path / "test_file.log" assert not f.is_file() arglist = [ 'trade', '--logfile', str(f), diff --git a/tests/test_directory_operations.py b/tests/test_directory_operations.py index 8e49aab10..8bd07f18a 100644 --- a/tests/test_directory_operations.py +++ b/tests/test_directory_operations.py @@ -32,9 +32,9 @@ def test_create_userdata_dir(mocker, default_conf, caplog) -> None: assert str(x) == str(Path("/tmp/bar")) -def test_create_userdata_dir_and_chown(mocker, tmpdir, caplog) -> None: +def test_create_userdata_dir_and_chown(mocker, tmp_path, caplog) -> None: sp_mock = mocker.patch('subprocess.check_output') - path = Path(tmpdir / 'bar') + path = tmp_path / 'bar' assert not path.is_dir() x = create_userdata_dir(str(path), create_dir=True)