Add test for assert error
This commit is contained in:
parent
0887a0212c
commit
cd2e738e35
@ -279,11 +279,12 @@ class IStrategy(ABC):
|
|||||||
dataframe = self._analyze_ticker_internal(dataframe, {'pair': pair})
|
dataframe = self._analyze_ticker_internal(dataframe, {'pair': pair})
|
||||||
self.assert_df(dataframe, df_len, df_close, df_date)
|
self.assert_df(dataframe, df_len, df_close, df_date)
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
logger.warning(
|
logger.warning('Unable to analyze candle (OHLCV) data for pair %s: %s',
|
||||||
'Unable to analyze candle (OHLCV) data for pair %s: %s',
|
pair, str(error))
|
||||||
pair,
|
return False, False
|
||||||
str(error)
|
except DependencyException as error:
|
||||||
)
|
logger.warning("Unable to analyze candle (OHLCV) data for pair %s: %s",
|
||||||
|
pair, str(error))
|
||||||
return False, False
|
return False, False
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
|
@ -6,6 +6,7 @@ from unittest.mock import MagicMock
|
|||||||
import arrow
|
import arrow
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
|
|
||||||
|
from freqtrade.exceptions import DependencyException
|
||||||
from freqtrade.configuration import TimeRange
|
from freqtrade.configuration import TimeRange
|
||||||
from freqtrade.data.history import load_data
|
from freqtrade.data.history import load_data
|
||||||
from freqtrade.persistence import Trade
|
from freqtrade.persistence import Trade
|
||||||
@ -105,6 +106,26 @@ def test_get_signal_old_dataframe(default_conf, mocker, caplog, ohlcv_history):
|
|||||||
assert log_has('Outdated history for pair xyz. Last tick is 16 minutes old', caplog)
|
assert log_has('Outdated history for pair xyz. Last tick is 16 minutes old', caplog)
|
||||||
|
|
||||||
|
|
||||||
|
def test_assert_df_raise(default_conf, mocker, caplog, ohlcv_history):
|
||||||
|
# default_conf defines a 5m interval. we check interval * 2 + 5m
|
||||||
|
# this is necessary as the last candle is removed (partial candles) by default
|
||||||
|
ohlcv_history.loc[1, 'date'] = arrow.utcnow().shift(minutes=-16)
|
||||||
|
# Take a copy to correctly modify the call
|
||||||
|
mocked_history = ohlcv_history.copy()
|
||||||
|
mocked_history['sell'] = 0
|
||||||
|
mocked_history['buy'] = 0
|
||||||
|
mocked_history.loc[1, 'buy'] = 1
|
||||||
|
|
||||||
|
caplog.set_level(logging.INFO)
|
||||||
|
mocker.patch.object(
|
||||||
|
_STRATEGY, 'assert_df',
|
||||||
|
side_effect=DependencyException('Dataframe returned...')
|
||||||
|
)
|
||||||
|
assert (False, False) == _STRATEGY.get_signal('xyz', default_conf['ticker_interval'],
|
||||||
|
ohlcv_history)
|
||||||
|
assert log_has('Unable to analyze candle (OHLCV) data for pair xyz: Dataframe returned...', caplog)
|
||||||
|
|
||||||
|
|
||||||
def test_get_signal_handles_exceptions(mocker, default_conf):
|
def test_get_signal_handles_exceptions(mocker, default_conf):
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
mocker.patch.object(
|
mocker.patch.object(
|
||||||
|
Loading…
Reference in New Issue
Block a user