Improve data-provider tests
This commit is contained in:
parent
0aa0b1d4fe
commit
a9abc25785
@ -9,27 +9,31 @@ from freqtrade.tests.conftest import get_patched_exchange
|
||||
|
||||
def test_ohlcv(mocker, default_conf, ticker_history):
|
||||
default_conf['runmode'] = RunMode.DRY_RUN
|
||||
tick_interval = default_conf['ticker_interval']
|
||||
exchange = get_patched_exchange(mocker, default_conf)
|
||||
exchange._klines['XRP/BTC'] = ticker_history
|
||||
exchange._klines['UNITTEST/BTC'] = ticker_history
|
||||
exchange._klines[('XRP/BTC', tick_interval)] = ticker_history
|
||||
exchange._klines[('UNITTEST/BTC', tick_interval)] = ticker_history
|
||||
dp = DataProvider(default_conf, exchange)
|
||||
assert dp.runmode == RunMode.DRY_RUN
|
||||
assert ticker_history.equals(dp.ohlcv('UNITTEST/BTC'))
|
||||
assert isinstance(dp.ohlcv('UNITTEST/BTC'), DataFrame)
|
||||
assert dp.ohlcv('UNITTEST/BTC') is not ticker_history
|
||||
assert dp.ohlcv('UNITTEST/BTC', copy=False) is ticker_history
|
||||
assert not dp.ohlcv('UNITTEST/BTC').empty
|
||||
assert dp.ohlcv('NONESENSE/AAA').empty
|
||||
assert ticker_history.equals(dp.ohlcv('UNITTEST/BTC', tick_interval))
|
||||
assert isinstance(dp.ohlcv('UNITTEST/BTC', tick_interval), DataFrame)
|
||||
assert dp.ohlcv('UNITTEST/BTC', tick_interval) is not ticker_history
|
||||
assert dp.ohlcv('UNITTEST/BTC', tick_interval, copy=False) is ticker_history
|
||||
assert not dp.ohlcv('UNITTEST/BTC', tick_interval).empty
|
||||
assert dp.ohlcv('NONESENSE/AAA', tick_interval).empty
|
||||
|
||||
# Test with and without parameter
|
||||
assert dp.ohlcv('UNITTEST/BTC', tick_interval).equals(dp.ohlcv('UNITTEST/BTC'))
|
||||
|
||||
default_conf['runmode'] = RunMode.LIVE
|
||||
dp = DataProvider(default_conf, exchange)
|
||||
assert dp.runmode == RunMode.LIVE
|
||||
assert isinstance(dp.ohlcv('UNITTEST/BTC'), DataFrame)
|
||||
assert isinstance(dp.ohlcv('UNITTEST/BTC', tick_interval), DataFrame)
|
||||
|
||||
default_conf['runmode'] = RunMode.BACKTEST
|
||||
dp = DataProvider(default_conf, exchange)
|
||||
assert dp.runmode == RunMode.BACKTEST
|
||||
assert dp.ohlcv('UNITTEST/BTC').empty
|
||||
assert dp.ohlcv('UNITTEST/BTC', tick_interval).empty
|
||||
|
||||
|
||||
def test_historic_ohlcv(mocker, default_conf, ticker_history):
|
||||
@ -49,8 +53,10 @@ def test_historic_ohlcv(mocker, default_conf, ticker_history):
|
||||
|
||||
def test_available_pairs(mocker, default_conf, ticker_history):
|
||||
exchange = get_patched_exchange(mocker, default_conf)
|
||||
exchange._klines['XRP/BTC'] = ticker_history
|
||||
exchange._klines['UNITTEST/BTC'] = ticker_history
|
||||
|
||||
tick_interval = default_conf['ticker_interval']
|
||||
exchange._klines[('XRP/BTC', tick_interval)] = ticker_history
|
||||
exchange._klines[('UNITTEST/BTC', tick_interval)] = ticker_history
|
||||
dp = DataProvider(default_conf, exchange)
|
||||
|
||||
assert len(dp.available_pairs) == 2
|
||||
|
@ -802,10 +802,10 @@ def test_refresh_latest_ohlcv(mocker, default_conf, caplog) -> None:
|
||||
exchange = get_patched_exchange(mocker, default_conf)
|
||||
exchange._api_async.fetch_ohlcv = get_mock_coro(tick)
|
||||
|
||||
pairs = ['IOTA/ETH', 'XRP/ETH']
|
||||
pairs = [('IOTA/ETH', '5m'), ('XRP/ETH', '5m')]
|
||||
# empty dicts
|
||||
assert not exchange._klines
|
||||
exchange.refresh_latest_ohlcv(['IOTA/ETH', 'XRP/ETH'], '5m')
|
||||
exchange.refresh_latest_ohlcv([('IOTA/ETH', '5m'), ('XRP/ETH', '5m')])
|
||||
|
||||
assert log_has(f'Refreshing ohlcv data for {len(pairs)} pairs', caplog.record_tuples)
|
||||
assert exchange._klines
|
||||
@ -822,10 +822,11 @@ def test_refresh_latest_ohlcv(mocker, default_conf, caplog) -> None:
|
||||
assert exchange.klines(pair, copy=False) is exchange.klines(pair, copy=False)
|
||||
|
||||
# test caching
|
||||
exchange.refresh_latest_ohlcv(['IOTA/ETH', 'XRP/ETH'], '5m')
|
||||
exchange.refresh_latest_ohlcv([('IOTA/ETH', '5m'), ('XRP/ETH', '5m')])
|
||||
|
||||
assert exchange._api_async.fetch_ohlcv.call_count == 2
|
||||
assert log_has(f"Using cached ohlcv data for {pairs[0]} ...", caplog.record_tuples)
|
||||
assert log_has(f"Using cached ohlcv data for {pairs[0][0]}, {pairs[0][1]} ...",
|
||||
caplog.record_tuples)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
Loading…
Reference in New Issue
Block a user