Improve test resiliance

This commit is contained in:
Matthias 2022-10-09 10:55:38 +02:00
parent 4f967fed97
commit 4623c3ec1d
3 changed files with 8 additions and 6 deletions

View File

@ -2018,8 +2018,8 @@ class Exchange:
candle_limit = self.ohlcv_candle_limit( candle_limit = self.ohlcv_candle_limit(
timeframe, candle_type=candle_type, since_ms=since_ms) timeframe, candle_type=candle_type, since_ms=since_ms)
if candle_type != CandleType.SPOT: if candle_type and candle_type != CandleType.SPOT:
params.update({'price': candle_type}) params.update({'price': candle_type.value})
if candle_type != CandleType.FUNDING_RATE: if candle_type != CandleType.FUNDING_RATE:
data = await self._api_async.fetch_ohlcv( data = await self._api_async.fetch_ohlcv(
pair, timeframe=timeframe, since=since_ms, pair, timeframe=timeframe, since=since_ms,

View File

@ -5,7 +5,7 @@ from unittest.mock import MagicMock, PropertyMock
import ccxt import ccxt
import pytest import pytest
from freqtrade.enums import MarginMode, TradingMode from freqtrade.enums import CandleType, MarginMode, TradingMode
from freqtrade.exceptions import DependencyException, InvalidOrderException, OperationalException from freqtrade.exceptions import DependencyException, InvalidOrderException, OperationalException
from tests.conftest import get_mock_coro, get_patched_exchange, log_has_re from tests.conftest import get_mock_coro, get_patched_exchange, log_has_re
from tests.exchange.test_exchange import ccxt_exceptionhandlers from tests.exchange.test_exchange import ccxt_exceptionhandlers
@ -542,7 +542,7 @@ def test__set_leverage_binance(mocker, default_conf):
@pytest.mark.asyncio @pytest.mark.asyncio
@pytest.mark.parametrize('candle_type', ['mark', '']) @pytest.mark.parametrize('candle_type', [CandleType.MARK, ''])
async def test__async_get_historic_ohlcv_binance(default_conf, mocker, caplog, candle_type): async def test__async_get_historic_ohlcv_binance(default_conf, mocker, caplog, candle_type):
ohlcv = [ ohlcv = [
[ [

View File

@ -2339,7 +2339,8 @@ async def test__async_kucoin_get_candle_history(default_conf, mocker, caplog):
for _ in range(3): for _ in range(3):
with pytest.raises(DDosProtection, match=r'429 Too Many Requests'): with pytest.raises(DDosProtection, match=r'429 Too Many Requests'):
await exchange._async_get_candle_history( await exchange._async_get_candle_history(
"ETH/BTC", "5m", (arrow.utcnow().int_timestamp - 2000) * 1000, count=3) "ETH/BTC", "5m", CandleType.SPOT,
since_ms=(arrow.utcnow().int_timestamp - 2000) * 1000, count=3)
assert num_log_has_re(msg, caplog) == 3 assert num_log_has_re(msg, caplog) == 3
caplog.clear() caplog.clear()
@ -2355,7 +2356,8 @@ async def test__async_kucoin_get_candle_history(default_conf, mocker, caplog):
for _ in range(3): for _ in range(3):
with pytest.raises(DDosProtection, match=r'429 Too Many Requests'): with pytest.raises(DDosProtection, match=r'429 Too Many Requests'):
await exchange._async_get_candle_history( await exchange._async_get_candle_history(
"ETH/BTC", "5m", (arrow.utcnow().int_timestamp - 2000) * 1000, count=3) "ETH/BTC", "5m", CandleType.SPOT,
(arrow.utcnow().int_timestamp - 2000) * 1000, count=3)
# Expect the "returned exception" message 12 times (4 retries * 3 (loop)) # Expect the "returned exception" message 12 times (4 retries * 3 (loop))
assert num_log_has_re(msg, caplog) == 12 assert num_log_has_re(msg, caplog) == 12
assert num_log_has_re(msg2, caplog) == 9 assert num_log_has_re(msg2, caplog) == 9