Fix remaining tests using log_has
This commit is contained in:
@@ -62,7 +62,7 @@ async def async_ccxt_exception(mocker, default_conf, api_mock, fun, mock_ccxt_fu
|
||||
def test_init(default_conf, mocker, caplog):
|
||||
caplog.set_level(logging.INFO)
|
||||
get_patched_exchange(mocker, default_conf)
|
||||
assert log_has('Instance is running with dry_run enabled', caplog.record_tuples)
|
||||
assert log_has('Instance is running with dry_run enabled', caplog)
|
||||
|
||||
|
||||
def test_init_ccxt_kwargs(default_conf, mocker, caplog):
|
||||
@@ -71,8 +71,7 @@ def test_init_ccxt_kwargs(default_conf, mocker, caplog):
|
||||
conf = copy.deepcopy(default_conf)
|
||||
conf['exchange']['ccxt_async_config'] = {'aiohttp_trust_env': True}
|
||||
ex = Exchange(conf)
|
||||
assert log_has("Applying additional ccxt config: {'aiohttp_trust_env': True}",
|
||||
caplog.record_tuples)
|
||||
assert log_has("Applying additional ccxt config: {'aiohttp_trust_env': True}", caplog)
|
||||
assert ex._api_async.aiohttp_trust_env
|
||||
assert not ex._api.aiohttp_trust_env
|
||||
|
||||
@@ -81,20 +80,18 @@ def test_init_ccxt_kwargs(default_conf, mocker, caplog):
|
||||
conf = copy.deepcopy(default_conf)
|
||||
conf['exchange']['ccxt_config'] = {'TestKWARG': 11}
|
||||
ex = Exchange(conf)
|
||||
assert not log_has("Applying additional ccxt config: {'aiohttp_trust_env': True}",
|
||||
caplog.record_tuples)
|
||||
assert not log_has("Applying additional ccxt config: {'aiohttp_trust_env': True}", caplog)
|
||||
assert not ex._api_async.aiohttp_trust_env
|
||||
assert hasattr(ex._api, 'TestKWARG')
|
||||
assert ex._api.TestKWARG == 11
|
||||
assert not hasattr(ex._api_async, 'TestKWARG')
|
||||
assert log_has("Applying additional ccxt config: {'TestKWARG': 11}",
|
||||
caplog.record_tuples)
|
||||
assert log_has("Applying additional ccxt config: {'TestKWARG': 11}", caplog)
|
||||
|
||||
|
||||
def test_destroy(default_conf, mocker, caplog):
|
||||
caplog.set_level(logging.DEBUG)
|
||||
get_patched_exchange(mocker, default_conf)
|
||||
assert log_has('Exchange object destroyed, closing async loop', caplog.record_tuples)
|
||||
assert log_has('Exchange object destroyed, closing async loop', caplog)
|
||||
|
||||
|
||||
def test_init_exception(default_conf, mocker):
|
||||
@@ -120,8 +117,7 @@ def test_exchange_resolver(default_conf, mocker, caplog):
|
||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes', MagicMock())
|
||||
exchange = ExchangeResolver('Bittrex', default_conf).exchange
|
||||
assert isinstance(exchange, Exchange)
|
||||
assert log_has_re(r"No .* specific subclass found. Using the generic class instead.",
|
||||
caplog.record_tuples)
|
||||
assert log_has_re(r"No .* specific subclass found. Using the generic class instead.", caplog)
|
||||
caplog.clear()
|
||||
|
||||
exchange = ExchangeResolver('kraken', default_conf).exchange
|
||||
@@ -129,7 +125,7 @@ def test_exchange_resolver(default_conf, mocker, caplog):
|
||||
assert isinstance(exchange, Kraken)
|
||||
assert not isinstance(exchange, Binance)
|
||||
assert not log_has_re(r"No .* specific subclass found. Using the generic class instead.",
|
||||
caplog.record_tuples)
|
||||
caplog)
|
||||
|
||||
exchange = ExchangeResolver('binance', default_conf).exchange
|
||||
assert isinstance(exchange, Exchange)
|
||||
@@ -137,7 +133,7 @@ def test_exchange_resolver(default_conf, mocker, caplog):
|
||||
assert not isinstance(exchange, Kraken)
|
||||
|
||||
assert not log_has_re(r"No .* specific subclass found. Using the generic class instead.",
|
||||
caplog.record_tuples)
|
||||
caplog)
|
||||
|
||||
|
||||
def test_validate_order_time_in_force(default_conf, mocker, caplog):
|
||||
@@ -249,8 +245,7 @@ def test__load_async_markets(default_conf, mocker, caplog):
|
||||
exchange._api_async.load_markets = Mock(side_effect=ccxt.BaseError("deadbeef"))
|
||||
exchange._load_async_markets()
|
||||
|
||||
assert log_has('Could not load async markets. Reason: deadbeef',
|
||||
caplog.record_tuples)
|
||||
assert log_has('Could not load async markets. Reason: deadbeef', caplog)
|
||||
|
||||
|
||||
def test__load_markets(default_conf, mocker, caplog):
|
||||
@@ -262,7 +257,7 @@ def test__load_markets(default_conf, mocker, caplog):
|
||||
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes', MagicMock())
|
||||
mocker.patch('freqtrade.exchange.Exchange._load_async_markets', MagicMock())
|
||||
Exchange(default_conf)
|
||||
assert log_has('Unable to initialize markets. Reason: SomeError', caplog.record_tuples)
|
||||
assert log_has('Unable to initialize markets. Reason: SomeError', caplog)
|
||||
|
||||
expected_return = {'ETH/BTC': 'available'}
|
||||
api_mock = MagicMock()
|
||||
@@ -298,7 +293,7 @@ def test__reload_markets(default_conf, mocker, caplog):
|
||||
exchange._last_markets_refresh = arrow.utcnow().timestamp - 15 * 60
|
||||
exchange._reload_markets()
|
||||
assert exchange.markets == updated_markets
|
||||
assert log_has('Performing scheduled market reload..', caplog.record_tuples)
|
||||
assert log_has('Performing scheduled market reload..', caplog)
|
||||
|
||||
|
||||
def test__reload_markets_exception(default_conf, mocker, caplog):
|
||||
@@ -312,7 +307,7 @@ def test__reload_markets_exception(default_conf, mocker, caplog):
|
||||
# less than 10 minutes have passed, no reload
|
||||
exchange._reload_markets()
|
||||
assert exchange._last_markets_refresh == 0
|
||||
assert log_has_re(r"Could not reload markets.*", caplog.record_tuples)
|
||||
assert log_has_re(r"Could not reload markets.*", caplog)
|
||||
|
||||
|
||||
def test_validate_pairs(default_conf, mocker): # test exchange.validate_pairs directly
|
||||
@@ -357,8 +352,7 @@ def test_validate_pairs_exception(default_conf, mocker, caplog):
|
||||
|
||||
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value={}))
|
||||
Exchange(default_conf)
|
||||
assert log_has('Unable to validate pairs (assuming they are correct).',
|
||||
caplog.record_tuples)
|
||||
assert log_has('Unable to validate pairs (assuming they are correct).', caplog)
|
||||
|
||||
|
||||
def test_validate_pairs_restricted(default_conf, mocker, caplog):
|
||||
@@ -374,8 +368,7 @@ def test_validate_pairs_restricted(default_conf, mocker, caplog):
|
||||
Exchange(default_conf)
|
||||
assert log_has(f"Pair XRP/BTC is restricted for some users on this exchange."
|
||||
f"Please check if you are impacted by this restriction "
|
||||
f"on the exchange and eventually remove XRP/BTC from your whitelist.",
|
||||
caplog.record_tuples)
|
||||
f"on the exchange and eventually remove XRP/BTC from your whitelist.", caplog)
|
||||
|
||||
|
||||
def test_validate_timeframes(default_conf, mocker):
|
||||
@@ -1060,7 +1053,7 @@ def test_refresh_latest_ohlcv(mocker, default_conf, caplog) -> None:
|
||||
assert not exchange._klines
|
||||
exchange.refresh_latest_ohlcv(pairs)
|
||||
|
||||
assert log_has(f'Refreshing ohlcv data for {len(pairs)} pairs', caplog.record_tuples)
|
||||
assert log_has(f'Refreshing ohlcv data for {len(pairs)} pairs', caplog)
|
||||
assert exchange._klines
|
||||
assert exchange._api_async.fetch_ohlcv.call_count == 2
|
||||
for pair in pairs:
|
||||
@@ -1079,7 +1072,7 @@ def test_refresh_latest_ohlcv(mocker, default_conf, caplog) -> None:
|
||||
|
||||
assert exchange._api_async.fetch_ohlcv.call_count == 2
|
||||
assert log_has(f"Using cached ohlcv data for pair {pairs[0][0]}, interval {pairs[0][1]} ...",
|
||||
caplog.record_tuples)
|
||||
caplog)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -1109,7 +1102,7 @@ async def test__async_get_candle_history(default_conf, mocker, caplog, exchange_
|
||||
assert res[1] == "5m"
|
||||
assert res[2] == tick
|
||||
assert exchange._api_async.fetch_ohlcv.call_count == 1
|
||||
assert not log_has(f"Using cached ohlcv data for {pair} ...", caplog.record_tuples)
|
||||
assert not log_has(f"Using cached ohlcv data for {pair} ...", caplog)
|
||||
|
||||
# exchange = Exchange(default_conf)
|
||||
await async_ccxt_exception(mocker, default_conf, MagicMock(),
|
||||
@@ -1168,8 +1161,8 @@ def test_refresh_latest_ohlcv_inv_result(default_conf, mocker, caplog):
|
||||
# Test that each is in list at least once as order is not guaranteed
|
||||
assert type(res[0]) is tuple or type(res[1]) is tuple
|
||||
assert type(res[0]) is TypeError or type(res[1]) is TypeError
|
||||
assert log_has("Error loading ETH/BTC. Result was [[]].", caplog.record_tuples)
|
||||
assert log_has("Async code raised an exception: TypeError", caplog.record_tuples)
|
||||
assert log_has("Error loading ETH/BTC. Result was [[]].", caplog)
|
||||
assert log_has("Async code raised an exception: TypeError", caplog)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
||||
|
Reference in New Issue
Block a user