mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Further improvements to test setup
This commit is contained in:
parent
be82248e01
commit
555f4b51e1
|
@ -1,6 +1,5 @@
|
||||||
# pragma pylint: disable=missing-docstring, C0103
|
# pragma pylint: disable=missing-docstring, C0103
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from pathlib import Path
|
|
||||||
from shutil import copytree
|
from shutil import copytree
|
||||||
from unittest.mock import PropertyMock
|
from unittest.mock import PropertyMock
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from pathlib import Path
|
|
||||||
from unittest.mock import AsyncMock, MagicMock, PropertyMock
|
from unittest.mock import AsyncMock, MagicMock, PropertyMock
|
||||||
|
|
||||||
import ccxt
|
import ccxt
|
||||||
|
@ -269,9 +268,9 @@ def test_additional_exchange_init_okx(default_conf, mocker):
|
||||||
"additional_exchange_init", "fetch_accounts")
|
"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')
|
# fd_mock = mocker.patch('freqtrade.exchange.exchange.file_dump_json')
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
type(api_mock).has = PropertyMock(return_value={
|
type(api_mock).has = PropertyMock(return_value={
|
||||||
|
|
|
@ -21,13 +21,13 @@ def is_mac() -> bool:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def freqai_conf(default_conf, tmpdir):
|
def freqai_conf(default_conf, tmp_path):
|
||||||
freqaiconf = deepcopy(default_conf)
|
freqaiconf = deepcopy(default_conf)
|
||||||
freqaiconf.update(
|
freqaiconf.update(
|
||||||
{
|
{
|
||||||
"datadir": Path(default_conf["datadir"]),
|
"datadir": Path(default_conf["datadir"]),
|
||||||
"strategy": "freqai_test_strat",
|
"strategy": "freqai_test_strat",
|
||||||
"user_data_dir": Path(tmpdir),
|
"user_data_dir": tmp_path,
|
||||||
"strategy-path": "freqtrade/tests/strategy/strats",
|
"strategy-path": "freqtrade/tests/strategy/strats",
|
||||||
"freqaimodel": "LightGBMRegressor",
|
"freqaimodel": "LightGBMRegressor",
|
||||||
"freqaimodel_path": "freqai/prediction_models",
|
"freqaimodel_path": "freqai/prediction_models",
|
||||||
|
|
|
@ -500,14 +500,14 @@ def test_get_required_data_timerange(mocker, freqai_conf):
|
||||||
assert (time_range.stopts - time_range.startts) == 177300
|
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)
|
caplog.set_level(logging.DEBUG)
|
||||||
strategy = get_patched_freqai_strategy(mocker, freqai_conf)
|
strategy = get_patched_freqai_strategy(mocker, freqai_conf)
|
||||||
exchange = get_patched_exchange(mocker, freqai_conf)
|
exchange = get_patched_exchange(mocker, freqai_conf)
|
||||||
pairlist = PairListManager(exchange, freqai_conf)
|
pairlist = PairListManager(exchange, freqai_conf)
|
||||||
strategy.dp = DataProvider(freqai_conf, exchange, pairlist)
|
strategy.dp = DataProvider(freqai_conf, exchange, pairlist)
|
||||||
freqai_conf['pairs'] = freqai_conf['exchange']['pair_whitelist']
|
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)
|
download_all_data_for_training(strategy.dp, freqai_conf)
|
||||||
|
|
||||||
assert log_has_re(
|
assert log_has_re(
|
||||||
|
|
|
@ -19,9 +19,9 @@ def create_results() -> List[Dict]:
|
||||||
return [{'loss': 1, 'result': 'foo', 'params': {}, 'is_best': True}]
|
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, {})
|
hyperopt_epochs = HyperoptTools.load_filtered_results(hyperopt.results_file, {})
|
||||||
assert log_has_re("Hyperopt file .* not found.", caplog)
|
assert log_has_re("Hyperopt file .* not found.", caplog)
|
||||||
|
@ -182,9 +182,9 @@ def test_get_strategy_filename(default_conf):
|
||||||
assert x is None
|
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()
|
assert not filename.is_file()
|
||||||
params = {
|
params = {
|
||||||
"params_details": {
|
"params_details": {
|
||||||
|
@ -231,11 +231,11 @@ def test_export_params(tmpdir):
|
||||||
assert "max_open_trades" in content["params"]
|
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
|
default_conf['disableparamexport'] = False
|
||||||
export_mock = mocker.patch("freqtrade.optimize.hyperopt_tools.HyperoptTools.export_params")
|
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()
|
assert not filename.is_file()
|
||||||
params = {
|
params = {
|
||||||
"params_details": {
|
"params_details": {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
|
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ def test_strategy_updater_start(user_dir, capsys) -> None:
|
||||||
# Backup file exists
|
# Backup file exists
|
||||||
assert Path(user_dir / "strategies_orig_updater" / 'strategy_test_v2.py').exists()
|
assert Path(user_dir / "strategies_orig_updater" / 'strategy_test_v2.py').exists()
|
||||||
# updated file exists
|
# updated file exists
|
||||||
new_file = Path(tmpdirp / 'strategy_test_v2.py')
|
new_file = tmpdirp / 'strategy_test_v2.py'
|
||||||
assert new_file.exists()
|
assert new_file.exists()
|
||||||
new_code = new_file.read_text()
|
new_code = new_file.read_text()
|
||||||
assert 'INTERFACE_VERSION = 3' in new_code
|
assert 'INTERFACE_VERSION = 3' in new_code
|
||||||
|
|
Loading…
Reference in New Issue
Block a user