Add test for Timeout - move tests to test_history
This commit is contained in:
parent
71447e55aa
commit
201e02e73f
@ -2,24 +2,25 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
|
||||||
import uuid
|
import uuid
|
||||||
|
from pathlib import Path
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
from pandas import DataFrame
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from pandas import DataFrame
|
||||||
|
|
||||||
from freqtrade import OperationalException
|
from freqtrade import OperationalException
|
||||||
from freqtrade.arguments import TimeRange
|
from freqtrade.arguments import TimeRange
|
||||||
from freqtrade.data import history
|
from freqtrade.data import history
|
||||||
from freqtrade.data.history import (download_pair_history,
|
from freqtrade.data.history import (download_pair_history,
|
||||||
load_cached_data_for_updating,
|
load_cached_data_for_updating,
|
||||||
load_tickerdata_file,
|
load_tickerdata_file, make_testdata_path,
|
||||||
make_testdata_path,
|
|
||||||
trim_tickerlist)
|
trim_tickerlist)
|
||||||
|
from freqtrade.exchange import timeframe_to_minutes
|
||||||
from freqtrade.misc import file_dump_json
|
from freqtrade.misc import file_dump_json
|
||||||
from freqtrade.tests.conftest import get_patched_exchange, log_has
|
from freqtrade.strategy.default_strategy import DefaultStrategy
|
||||||
|
from freqtrade.tests.conftest import get_patched_exchange, log_has, patch_exchange
|
||||||
|
|
||||||
# Change this if modifying UNITTEST/BTC testdatafile
|
# Change this if modifying UNITTEST/BTC testdatafile
|
||||||
_BTC_UNITTEST_LENGTH = 13681
|
_BTC_UNITTEST_LENGTH = 13681
|
||||||
@ -495,3 +496,62 @@ def test_file_dump_json_tofile() -> None:
|
|||||||
|
|
||||||
# Remove the file
|
# Remove the file
|
||||||
_clean_test_file(file)
|
_clean_test_file(file)
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_timeframe(default_conf, mocker) -> None:
|
||||||
|
patch_exchange(mocker)
|
||||||
|
strategy = DefaultStrategy(default_conf)
|
||||||
|
|
||||||
|
data = strategy.tickerdata_to_dataframe(
|
||||||
|
history.load_data(
|
||||||
|
datadir=None,
|
||||||
|
ticker_interval='1m',
|
||||||
|
pairs=['UNITTEST/BTC']
|
||||||
|
)
|
||||||
|
)
|
||||||
|
min_date, max_date = history.get_timeframe(data)
|
||||||
|
assert min_date.isoformat() == '2017-11-04T23:02:00+00:00'
|
||||||
|
assert max_date.isoformat() == '2017-11-14T22:58:00+00:00'
|
||||||
|
|
||||||
|
|
||||||
|
def test_validate_backtest_data_warn(default_conf, mocker, caplog) -> None:
|
||||||
|
patch_exchange(mocker)
|
||||||
|
strategy = DefaultStrategy(default_conf)
|
||||||
|
|
||||||
|
data = strategy.tickerdata_to_dataframe(
|
||||||
|
history.load_data(
|
||||||
|
datadir=None,
|
||||||
|
ticker_interval='1m',
|
||||||
|
pairs=['UNITTEST/BTC'],
|
||||||
|
fill_up_missing=False
|
||||||
|
)
|
||||||
|
)
|
||||||
|
min_date, max_date = history.get_timeframe(data)
|
||||||
|
caplog.clear()
|
||||||
|
assert history.validate_backtest_data(data, min_date, max_date,
|
||||||
|
timeframe_to_minutes('1m'))
|
||||||
|
assert len(caplog.record_tuples) == 1
|
||||||
|
assert log_has(
|
||||||
|
"UNITTEST/BTC has missing frames: expected 14396, got 13680, that's 716 missing values",
|
||||||
|
caplog.record_tuples)
|
||||||
|
|
||||||
|
|
||||||
|
def test_validate_backtest_data(default_conf, mocker, caplog) -> None:
|
||||||
|
patch_exchange(mocker)
|
||||||
|
strategy = DefaultStrategy(default_conf)
|
||||||
|
|
||||||
|
timerange = TimeRange('index', 'index', 200, 250)
|
||||||
|
data = strategy.tickerdata_to_dataframe(
|
||||||
|
history.load_data(
|
||||||
|
datadir=None,
|
||||||
|
ticker_interval='5m',
|
||||||
|
pairs=['UNITTEST/BTC'],
|
||||||
|
timerange=timerange
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
min_date, max_date = history.get_timeframe(data)
|
||||||
|
caplog.clear()
|
||||||
|
assert not history.validate_backtest_data(data, min_date, max_date,
|
||||||
|
timeframe_to_minutes('5m'))
|
||||||
|
assert len(caplog.record_tuples) == 0
|
||||||
|
@ -3,6 +3,7 @@ import json
|
|||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
from filelock import Timeout
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import pytest
|
import pytest
|
||||||
@ -11,7 +12,7 @@ from freqtrade import DependencyException
|
|||||||
from freqtrade.data.converter import parse_ticker_dataframe
|
from freqtrade.data.converter import parse_ticker_dataframe
|
||||||
from freqtrade.data.history import load_tickerdata_file
|
from freqtrade.data.history import load_tickerdata_file
|
||||||
from freqtrade.optimize.default_hyperopt import DefaultHyperOpts
|
from freqtrade.optimize.default_hyperopt import DefaultHyperOpts
|
||||||
from freqtrade.optimize.hyperopt import Hyperopt
|
from freqtrade.optimize.hyperopt import Hyperopt, HYPEROPT_LOCKFILE
|
||||||
from freqtrade.optimize import setup_configuration, start_hyperopt
|
from freqtrade.optimize import setup_configuration, start_hyperopt
|
||||||
from freqtrade.resolvers.hyperopt_resolver import HyperOptResolver
|
from freqtrade.resolvers.hyperopt_resolver import HyperOptResolver
|
||||||
from freqtrade.state import RunMode
|
from freqtrade.state import RunMode
|
||||||
@ -247,6 +248,28 @@ def test_start_failure(mocker, default_conf, caplog) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_start_filelock(mocker, default_conf, caplog) -> None:
|
||||||
|
start_mock = MagicMock(side_effect=Timeout(HYPEROPT_LOCKFILE))
|
||||||
|
mocker.patch(
|
||||||
|
'freqtrade.configuration.Configuration._load_config_file',
|
||||||
|
lambda *args, **kwargs: default_conf
|
||||||
|
)
|
||||||
|
mocker.patch('freqtrade.optimize.hyperopt.Hyperopt.start', start_mock)
|
||||||
|
patch_exchange(mocker)
|
||||||
|
|
||||||
|
args = [
|
||||||
|
'--config', 'config.json',
|
||||||
|
'hyperopt',
|
||||||
|
'--epochs', '5'
|
||||||
|
]
|
||||||
|
args = get_args(args)
|
||||||
|
start_hyperopt(args)
|
||||||
|
assert log_has(
|
||||||
|
"Another running instance of freqtrade Hyperopt detected.",
|
||||||
|
caplog.record_tuples
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_loss_calculation_prefer_correct_trade_count(hyperopt) -> None:
|
def test_loss_calculation_prefer_correct_trade_count(hyperopt) -> None:
|
||||||
|
|
||||||
correct = hyperopt.calculate_loss(1, hyperopt.target_trades, 20)
|
correct = hyperopt.calculate_loss(1, hyperopt.target_trades, 20)
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
# pragma pylint: disable=missing-docstring, protected-access, C0103
|
|
||||||
from freqtrade.arguments import TimeRange
|
|
||||||
from freqtrade.data import history
|
|
||||||
from freqtrade.exchange import timeframe_to_minutes
|
|
||||||
from freqtrade.strategy.default_strategy import DefaultStrategy
|
|
||||||
from freqtrade.tests.conftest import log_has, patch_exchange
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_timeframe(default_conf, mocker) -> None:
|
|
||||||
patch_exchange(mocker)
|
|
||||||
strategy = DefaultStrategy(default_conf)
|
|
||||||
|
|
||||||
data = strategy.tickerdata_to_dataframe(
|
|
||||||
history.load_data(
|
|
||||||
datadir=None,
|
|
||||||
ticker_interval='1m',
|
|
||||||
pairs=['UNITTEST/BTC']
|
|
||||||
)
|
|
||||||
)
|
|
||||||
min_date, max_date = history.get_timeframe(data)
|
|
||||||
assert min_date.isoformat() == '2017-11-04T23:02:00+00:00'
|
|
||||||
assert max_date.isoformat() == '2017-11-14T22:58:00+00:00'
|
|
||||||
|
|
||||||
|
|
||||||
def test_validate_backtest_data_warn(default_conf, mocker, caplog) -> None:
|
|
||||||
patch_exchange(mocker)
|
|
||||||
strategy = DefaultStrategy(default_conf)
|
|
||||||
|
|
||||||
data = strategy.tickerdata_to_dataframe(
|
|
||||||
history.load_data(
|
|
||||||
datadir=None,
|
|
||||||
ticker_interval='1m',
|
|
||||||
pairs=['UNITTEST/BTC'],
|
|
||||||
fill_up_missing=False
|
|
||||||
)
|
|
||||||
)
|
|
||||||
min_date, max_date = history.get_timeframe(data)
|
|
||||||
caplog.clear()
|
|
||||||
assert history.validate_backtest_data(data, min_date, max_date,
|
|
||||||
timeframe_to_minutes('1m'))
|
|
||||||
assert len(caplog.record_tuples) == 1
|
|
||||||
assert log_has(
|
|
||||||
"UNITTEST/BTC has missing frames: expected 14396, got 13680, that's 716 missing values",
|
|
||||||
caplog.record_tuples)
|
|
||||||
|
|
||||||
|
|
||||||
def test_validate_backtest_data(default_conf, mocker, caplog) -> None:
|
|
||||||
patch_exchange(mocker)
|
|
||||||
strategy = DefaultStrategy(default_conf)
|
|
||||||
|
|
||||||
timerange = TimeRange('index', 'index', 200, 250)
|
|
||||||
data = strategy.tickerdata_to_dataframe(
|
|
||||||
history.load_data(
|
|
||||||
datadir=None,
|
|
||||||
ticker_interval='5m',
|
|
||||||
pairs=['UNITTEST/BTC'],
|
|
||||||
timerange=timerange
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
min_date, max_date = history.get_timeframe(data)
|
|
||||||
caplog.clear()
|
|
||||||
assert not history.validate_backtest_data(data, min_date, max_date,
|
|
||||||
timeframe_to_minutes('5m'))
|
|
||||||
assert len(caplog.record_tuples) == 0
|
|
Loading…
Reference in New Issue
Block a user