Introduce new test functions to check logs
New functions log_contains, num_log_contains, num_log_has and num_log_has_re are introduced in the conftest module to help and simplify checking: - if logs contain a string; - count how many messages contain a string; - count how many messages are the given string; - count how many messages matchs a regex. A couple of existing tests are changed using the new functions.
This commit is contained in:
@@ -15,7 +15,7 @@ from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist
|
||||
from freqtrade.plugins.pairlistmanager import PairListManager
|
||||
from freqtrade.resolvers import PairListResolver
|
||||
from tests.conftest import (create_mock_trades, get_patched_exchange, get_patched_freqtradebot,
|
||||
log_has, log_has_re)
|
||||
log_has, log_has_re, num_log_has)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
@@ -240,16 +240,14 @@ def test_remove_logs_for_pairs_already_in_blacklist(mocker, markets, static_pl_c
|
||||
new_whitelist = freqtrade.pairlists.verify_blacklist(whitelist + ['BLK/BTC'], logger.warning)
|
||||
# Ensure that the pair is removed from the white list, and properly logged.
|
||||
assert set(whitelist) == set(new_whitelist)
|
||||
matches = sum(1 for message in caplog.messages
|
||||
if message == 'Pair BLK/BTC in your blacklist. Removing it from whitelist...')
|
||||
assert matches == 1
|
||||
assert num_log_has('Pair BLK/BTC in your blacklist. Removing it from whitelist...',
|
||||
caplog) == 1
|
||||
|
||||
new_whitelist = freqtrade.pairlists.verify_blacklist(whitelist + ['BLK/BTC'], logger.warning)
|
||||
# Ensure that the pair is not logged anymore when being removed from the pair list.
|
||||
assert set(whitelist) == set(new_whitelist)
|
||||
matches = sum(1 for message in caplog.messages
|
||||
if message == 'Pair BLK/BTC in your blacklist. Removing it from whitelist...')
|
||||
assert matches == 1
|
||||
assert num_log_has('Pair BLK/BTC in your blacklist. Removing it from whitelist...',
|
||||
caplog) == 1
|
||||
|
||||
|
||||
def test_refresh_pairlist_dynamic(mocker, shitcoinmarkets, tickers, whitelist_conf):
|
||||
|
Reference in New Issue
Block a user