From f2a778d294a435c2b775dae1c644eef042dfe1dd Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 18 Jun 2020 07:03:30 +0200 Subject: [PATCH] Combine tests for empty dataframe --- freqtrade/strategy/interface.py | 2 +- tests/strategy/test_interface.py | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index fab438ae6..5b5cce268 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -415,7 +415,7 @@ class IStrategy(ABC): dataframe, _ = self.dp.get_analyzed_dataframe(pair, timeframe) if not isinstance(dataframe, DataFrame) or dataframe.empty: - logger.warning('Empty dataframe for pair %s', pair) + logger.warning(f'Empty candle (OHLCV) data for pair {pair}') return False, False latest_date = dataframe['date'].max() diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index 176fa43ca..835465f38 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -89,6 +89,11 @@ def test_get_signal_empty(default_conf, mocker, caplog): mocker.patch.object(_STRATEGY.dp, 'get_analyzed_dataframe', return_value=(None, 0)) assert (False, False) == _STRATEGY.get_signal('bar', default_conf['timeframe']) assert log_has('Empty candle (OHLCV) data for pair bar', caplog) + caplog.clear() + + mocker.patch.object(_STRATEGY.dp, 'get_analyzed_dataframe', return_value=(DataFrame([]), 0)) + assert (False, False) == _STRATEGY.get_signal('baz', default_conf['timeframe']) + assert log_has('Empty candle (OHLCV) data for pair baz', caplog) def test_get_signal_exception_valueerror(default_conf, mocker, caplog, ohlcv_history): @@ -110,15 +115,6 @@ def test_get_signal_exception_valueerror(default_conf, mocker, caplog, ohlcv_his assert log_has_re(r'Strategy caused the following exception: xyz.*', caplog) -def test_get_signal_empty_dataframe(default_conf, mocker, caplog, ohlcv_history): - caplog.set_level(logging.INFO) - mocker.patch.object(_STRATEGY.dp, 'get_analyzed_dataframe', return_value=(DataFrame([]), 0)) - mocker.patch.object(_STRATEGY, 'assert_df') - - assert (False, False) == _STRATEGY.get_signal('xyz', default_conf['timeframe']) - assert log_has('Empty dataframe for pair xyz', caplog) - - def test_get_signal_old_dataframe(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