From 555f4b51e14941fa4a77ddb82dfeda5c1139a296 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 5 Nov 2023 16:23:22 +0100 Subject: [PATCH] Further improvements to test setup --- tests/data/test_converter.py | 1 - tests/data/test_trade_converter_kraken.py | 1 - tests/exchange/test_okx.py | 5 ++--- tests/freqai/conftest.py | 4 ++-- tests/freqai/test_freqai_interface.py | 4 ++-- tests/optimize/test_hyperopt_tools.py | 12 ++++++------ tests/test_binance_mig.py | 1 - tests/test_log_setup.py | 1 - tests/test_strategy_updater.py | 2 +- 9 files changed, 13 insertions(+), 18 deletions(-) diff --git a/tests/data/test_converter.py b/tests/data/test_converter.py index 49a16f7c9..99c56e1d0 100644 --- a/tests/data/test_converter.py +++ b/tests/data/test_converter.py @@ -1,6 +1,5 @@ # pragma pylint: disable=missing-docstring, C0103 import logging -from pathlib import Path from shutil import copyfile import numpy as np diff --git a/tests/data/test_trade_converter_kraken.py b/tests/data/test_trade_converter_kraken.py index 6fb752714..bb44062bf 100644 --- a/tests/data/test_trade_converter_kraken.py +++ b/tests/data/test_trade_converter_kraken.py @@ -1,5 +1,4 @@ from datetime import datetime, timezone -from pathlib import Path from shutil import copytree from unittest.mock import PropertyMock diff --git a/tests/exchange/test_okx.py b/tests/exchange/test_okx.py index 736c630e0..fe9ab3c18 100644 --- a/tests/exchange/test_okx.py +++ b/tests/exchange/test_okx.py @@ -1,5 +1,4 @@ from datetime import datetime, timedelta, timezone -from pathlib import Path from unittest.mock import AsyncMock, MagicMock, PropertyMock import ccxt @@ -269,9 +268,9 @@ def test_additional_exchange_init_okx(default_conf, mocker): "additional_exchange_init", "fetch_accounts") -def test_load_leverage_tiers_okx(default_conf, mocker, markets, tmpdir, caplog, time_machine): +def test_load_leverage_tiers_okx(default_conf, mocker, markets, tmp_path, caplog, time_machine): - default_conf['datadir'] = Path(tmpdir) + default_conf['datadir'] = tmp_path # fd_mock = mocker.patch('freqtrade.exchange.exchange.file_dump_json') api_mock = MagicMock() type(api_mock).has = PropertyMock(return_value={ diff --git a/tests/freqai/conftest.py b/tests/freqai/conftest.py index 9c7a950e7..be208408f 100644 --- a/tests/freqai/conftest.py +++ b/tests/freqai/conftest.py @@ -21,13 +21,13 @@ def is_mac() -> bool: @pytest.fixture(scope="function") -def freqai_conf(default_conf, tmpdir): +def freqai_conf(default_conf, tmp_path): freqaiconf = deepcopy(default_conf) freqaiconf.update( { "datadir": Path(default_conf["datadir"]), "strategy": "freqai_test_strat", - "user_data_dir": Path(tmpdir), + "user_data_dir": tmp_path, "strategy-path": "freqtrade/tests/strategy/strats", "freqaimodel": "LightGBMRegressor", "freqaimodel_path": "freqai/prediction_models", diff --git a/tests/freqai/test_freqai_interface.py b/tests/freqai/test_freqai_interface.py index 55338f611..7638c03ed 100644 --- a/tests/freqai/test_freqai_interface.py +++ b/tests/freqai/test_freqai_interface.py @@ -500,14 +500,14 @@ def test_get_required_data_timerange(mocker, freqai_conf): assert (time_range.stopts - time_range.startts) == 177300 -def test_download_all_data_for_training(mocker, freqai_conf, caplog, tmpdir): +def test_download_all_data_for_training(mocker, freqai_conf, caplog, tmp_path): caplog.set_level(logging.DEBUG) strategy = get_patched_freqai_strategy(mocker, freqai_conf) exchange = get_patched_exchange(mocker, freqai_conf) pairlist = PairListManager(exchange, freqai_conf) strategy.dp = DataProvider(freqai_conf, exchange, pairlist) freqai_conf['pairs'] = freqai_conf['exchange']['pair_whitelist'] - freqai_conf['datadir'] = Path(tmpdir) + freqai_conf['datadir'] = tmp_path download_all_data_for_training(strategy.dp, freqai_conf) assert log_has_re( diff --git a/tests/optimize/test_hyperopt_tools.py b/tests/optimize/test_hyperopt_tools.py index eace78eee..c46897374 100644 --- a/tests/optimize/test_hyperopt_tools.py +++ b/tests/optimize/test_hyperopt_tools.py @@ -19,9 +19,9 @@ def create_results() -> List[Dict]: return [{'loss': 1, 'result': 'foo', 'params': {}, 'is_best': True}] -def test_save_results_saves_epochs(hyperopt, tmpdir, caplog) -> None: +def test_save_results_saves_epochs(hyperopt, tmp_path, caplog) -> None: - hyperopt.results_file = Path(tmpdir / 'ut_results.fthypt') + hyperopt.results_file = tmp_path / 'ut_results.fthypt' hyperopt_epochs = HyperoptTools.load_filtered_results(hyperopt.results_file, {}) assert log_has_re("Hyperopt file .* not found.", caplog) @@ -182,9 +182,9 @@ def test_get_strategy_filename(default_conf): assert x is None -def test_export_params(tmpdir): +def test_export_params(tmp_path): - filename = Path(tmpdir) / f"{CURRENT_TEST_STRATEGY}.json" + filename = tmp_path / f"{CURRENT_TEST_STRATEGY}.json" assert not filename.is_file() params = { "params_details": { @@ -231,11 +231,11 @@ def test_export_params(tmpdir): assert "max_open_trades" in content["params"] -def test_try_export_params(default_conf, tmpdir, caplog, mocker): +def test_try_export_params(default_conf, tmp_path, caplog, mocker): default_conf['disableparamexport'] = False export_mock = mocker.patch("freqtrade.optimize.hyperopt_tools.HyperoptTools.export_params") - filename = Path(tmpdir) / f"{CURRENT_TEST_STRATEGY}.json" + filename = tmp_path / f"{CURRENT_TEST_STRATEGY}.json" assert not filename.is_file() params = { "params_details": { diff --git a/tests/test_binance_mig.py b/tests/test_binance_mig.py index f1694bfc8..b7c821a5a 100644 --- a/tests/test_binance_mig.py +++ b/tests/test_binance_mig.py @@ -1,7 +1,6 @@ import shutil -from pathlib import Path import pytest diff --git a/tests/test_log_setup.py b/tests/test_log_setup.py index 47b93c947..182e78730 100644 --- a/tests/test_log_setup.py +++ b/tests/test_log_setup.py @@ -1,6 +1,5 @@ import logging import sys -from pathlib import Path import pytest diff --git a/tests/test_strategy_updater.py b/tests/test_strategy_updater.py index 3b48c952c..7f4ae4349 100644 --- a/tests/test_strategy_updater.py +++ b/tests/test_strategy_updater.py @@ -40,7 +40,7 @@ def test_strategy_updater_start(user_dir, capsys) -> None: # Backup file exists assert Path(user_dir / "strategies_orig_updater" / 'strategy_test_v2.py').exists() # updated file exists - new_file = Path(tmpdirp / 'strategy_test_v2.py') + new_file = tmpdirp / 'strategy_test_v2.py' assert new_file.exists() new_code = new_file.read_text() assert 'INTERFACE_VERSION = 3' in new_code