mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Properly handle and test ohlcv min_max with empty files
This commit is contained in:
parent
a9ea84e2c4
commit
6e09d552ac
|
@ -102,6 +102,11 @@ class IDataHandler(ABC):
|
||||||
:return: (min, max)
|
:return: (min, max)
|
||||||
"""
|
"""
|
||||||
data = self._ohlcv_load(pair, timeframe, None, candle_type)
|
data = self._ohlcv_load(pair, timeframe, None, candle_type)
|
||||||
|
if data.empty:
|
||||||
|
return (
|
||||||
|
datetime.fromtimestamp(0, tz=timezone.utc),
|
||||||
|
datetime.fromtimestamp(0, tz=timezone.utc)
|
||||||
|
)
|
||||||
return data.iloc[0]['date'].to_pydatetime(), data.iloc[-1]['date'].to_pydatetime()
|
return data.iloc[0]['date'].to_pydatetime(), data.iloc[-1]['date'].to_pydatetime()
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# pragma pylint: disable=missing-docstring, protected-access, C0103
|
# pragma pylint: disable=missing-docstring, protected-access, C0103
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
from datetime import datetime, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
@ -154,6 +155,23 @@ def test_jsondatahandler_ohlcv_load(testdatadir, caplog):
|
||||||
assert df.columns.equals(df1.columns)
|
assert df.columns.equals(df1.columns)
|
||||||
|
|
||||||
|
|
||||||
|
def test_datahandler_ohlcv_data_min_max(testdatadir):
|
||||||
|
dh = JsonDataHandler(testdatadir)
|
||||||
|
min_max = dh.ohlcv_data_min_max('UNITTEST/BTC', '5m', 'spot')
|
||||||
|
assert len(min_max) == 2
|
||||||
|
|
||||||
|
# Empty pair
|
||||||
|
min_max = dh.ohlcv_data_min_max('UNITTEST/BTC', '8m', 'spot')
|
||||||
|
assert len(min_max) == 2
|
||||||
|
assert min_max[0] == datetime.fromtimestamp(0, tz=timezone.utc)
|
||||||
|
assert min_max[0] == min_max[1]
|
||||||
|
# Empty pair2
|
||||||
|
min_max = dh.ohlcv_data_min_max('NOPAIR/XXX', '4m', 'spot')
|
||||||
|
assert len(min_max) == 2
|
||||||
|
assert min_max[0] == datetime.fromtimestamp(0, tz=timezone.utc)
|
||||||
|
assert min_max[0] == min_max[1]
|
||||||
|
|
||||||
|
|
||||||
def test_datahandler__check_empty_df(testdatadir, caplog):
|
def test_datahandler__check_empty_df(testdatadir, caplog):
|
||||||
dh = JsonDataHandler(testdatadir)
|
dh = JsonDataHandler(testdatadir)
|
||||||
expected_text = r"Price jump in UNITTEST/USDT, 1h, spot between"
|
expected_text = r"Price jump in UNITTEST/USDT, 1h, spot between"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user