Fix test
This commit is contained in:
parent
bf69b055eb
commit
85beb3b6a9
@ -7,6 +7,7 @@ import pytest
|
|||||||
from freqtrade import OperationalException
|
from freqtrade import OperationalException
|
||||||
from freqtrade.constants import AVAILABLE_PAIRLISTS
|
from freqtrade.constants import AVAILABLE_PAIRLISTS
|
||||||
from freqtrade.resolvers import PairListResolver
|
from freqtrade.resolvers import PairListResolver
|
||||||
|
from freqtrade.pairlist.pairlistmanager import PairListManager
|
||||||
from tests.conftest import get_patched_freqtradebot, log_has_re
|
from tests.conftest import get_patched_freqtradebot, log_has_re
|
||||||
|
|
||||||
# whitelist, blacklist
|
# whitelist, blacklist
|
||||||
@ -25,26 +26,41 @@ def whitelist_conf(default_conf):
|
|||||||
default_conf['exchange']['pair_blacklist'] = [
|
default_conf['exchange']['pair_blacklist'] = [
|
||||||
'BLK/BTC'
|
'BLK/BTC'
|
||||||
]
|
]
|
||||||
default_conf['pairlist'] = {'method': 'StaticPairList',
|
default_conf['pairlists'] = [
|
||||||
'config': {'number_assets': 5},
|
{
|
||||||
'filters': {},
|
"method": "VolumePairList",
|
||||||
|
"config": {
|
||||||
|
"number_assets": 5,
|
||||||
|
"sort_key": "quoteVolume",
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
return default_conf
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="function")
|
||||||
|
def static_pl_conf(default_conf):
|
||||||
|
default_conf['pairlists'] = [
|
||||||
|
{
|
||||||
|
"method": "StaticPairList",
|
||||||
|
},
|
||||||
|
]
|
||||||
return default_conf
|
return default_conf
|
||||||
|
|
||||||
|
|
||||||
def test_load_pairlist_noexist(mocker, markets, default_conf):
|
def test_load_pairlist_noexist(mocker, markets, default_conf):
|
||||||
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
bot = get_patched_freqtradebot(mocker, default_conf)
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets))
|
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets))
|
||||||
|
plm = PairListManager(bot.exchange, default_conf)
|
||||||
with pytest.raises(OperationalException,
|
with pytest.raises(OperationalException,
|
||||||
match=r"Impossible to load Pairlist 'NonexistingPairList'. "
|
match=r"Impossible to load Pairlist 'NonexistingPairList'. "
|
||||||
r"This class does not exist or contains Python code errors."):
|
r"This class does not exist or contains Python code errors."):
|
||||||
PairListResolver('NonexistingPairList', freqtradebot, default_conf).pairlist
|
PairListResolver('NonexistingPairList', bot.exchange, plm, default_conf, {})
|
||||||
|
|
||||||
|
|
||||||
def test_refresh_market_pair_not_in_whitelist(mocker, markets, whitelist_conf):
|
def test_refresh_market_pair_not_in_whitelist(mocker, markets, static_pl_conf):
|
||||||
|
|
||||||
freqtradebot = get_patched_freqtradebot(mocker, whitelist_conf)
|
freqtradebot = get_patched_freqtradebot(mocker, static_pl_conf)
|
||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets))
|
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets))
|
||||||
freqtradebot.pairlists.refresh_pairlist()
|
freqtradebot.pairlists.refresh_pairlist()
|
||||||
@ -53,34 +69,33 @@ def test_refresh_market_pair_not_in_whitelist(mocker, markets, whitelist_conf):
|
|||||||
# Ensure all except those in whitelist are removed
|
# Ensure all except those in whitelist are removed
|
||||||
assert set(whitelist) == set(freqtradebot.pairlists.whitelist)
|
assert set(whitelist) == set(freqtradebot.pairlists.whitelist)
|
||||||
# Ensure config dict hasn't been changed
|
# Ensure config dict hasn't been changed
|
||||||
assert (whitelist_conf['exchange']['pair_whitelist'] ==
|
assert (static_pl_conf['exchange']['pair_whitelist'] ==
|
||||||
freqtradebot.config['exchange']['pair_whitelist'])
|
freqtradebot.config['exchange']['pair_whitelist'])
|
||||||
|
|
||||||
|
|
||||||
def test_refresh_pairlists(mocker, markets, whitelist_conf):
|
def test_refresh_pairlists(mocker, markets, static_pl_conf):
|
||||||
freqtradebot = get_patched_freqtradebot(mocker, whitelist_conf)
|
freqtradebot = get_patched_freqtradebot(mocker, static_pl_conf)
|
||||||
|
mocker.patch.multiple(
|
||||||
mocker.patch('freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets))
|
'freqtrade.exchange.Exchange',
|
||||||
|
exchange_has=MagicMock(return_value=True),
|
||||||
|
markets=PropertyMock(return_value=markets),
|
||||||
|
)
|
||||||
freqtradebot.pairlists.refresh_pairlist()
|
freqtradebot.pairlists.refresh_pairlist()
|
||||||
# List ordered by BaseVolume
|
# List ordered by BaseVolume
|
||||||
whitelist = ['ETH/BTC', 'TKN/BTC']
|
whitelist = ['ETH/BTC', 'TKN/BTC']
|
||||||
# Ensure all except those in whitelist are removed
|
# Ensure all except those in whitelist are removed
|
||||||
assert set(whitelist) == set(freqtradebot.pairlists.whitelist)
|
assert set(whitelist) == set(freqtradebot.pairlists.whitelist)
|
||||||
assert whitelist_conf['exchange']['pair_blacklist'] == freqtradebot.pairlists.blacklist
|
assert static_pl_conf['exchange']['pair_blacklist'] == freqtradebot.pairlists.blacklist
|
||||||
|
|
||||||
|
|
||||||
def test_refresh_pairlist_dynamic(mocker, shitcoinmarkets, tickers, whitelist_conf):
|
def test_refresh_pairlist_dynamic(mocker, shitcoinmarkets, tickers, whitelist_conf):
|
||||||
whitelist_conf['pairlist'] = {'method': 'VolumePairList',
|
|
||||||
'config': {'number_assets': 5,
|
|
||||||
'precision_filter': False}
|
|
||||||
}
|
|
||||||
|
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
get_tickers=tickers,
|
get_tickers=tickers,
|
||||||
exchange_has=MagicMock(return_value=True)
|
exchange_has=MagicMock(return_value=True),
|
||||||
)
|
)
|
||||||
freqtradebot = get_patched_freqtradebot(mocker, whitelist_conf)
|
bot = get_patched_freqtradebot(mocker, whitelist_conf)
|
||||||
# Remock markets with shitcoinmarkets since get_patched_freqtradebot uses the markets fixture
|
# Remock markets with shitcoinmarkets since get_patched_freqtradebot uses the markets fixture
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
@ -88,17 +103,19 @@ def test_refresh_pairlist_dynamic(mocker, shitcoinmarkets, tickers, whitelist_co
|
|||||||
)
|
)
|
||||||
# argument: use the whitelist dynamically by exchange-volume
|
# argument: use the whitelist dynamically by exchange-volume
|
||||||
whitelist = ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'HOT/BTC', 'FUEL/BTC']
|
whitelist = ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'HOT/BTC', 'FUEL/BTC']
|
||||||
freqtradebot.pairlists.refresh_pairlist()
|
bot.pairlists.refresh_pairlist()
|
||||||
|
|
||||||
assert whitelist == freqtradebot.pairlists.whitelist
|
assert whitelist == bot.pairlists.whitelist
|
||||||
|
|
||||||
whitelist_conf['pairlist'] = {'method': 'VolumePairList',
|
whitelist_conf['pairlists'] = [{'method': 'VolumePairList',
|
||||||
'config': {}
|
'config': {}
|
||||||
}
|
}
|
||||||
|
]
|
||||||
|
|
||||||
with pytest.raises(OperationalException,
|
with pytest.raises(OperationalException,
|
||||||
match=r'`number_assets` not specified. Please check your configuration '
|
match=r'`number_assets` not specified. Please check your configuration '
|
||||||
r'for "pairlist.config.number_assets"'):
|
r'for "pairlist.config.number_assets"'):
|
||||||
PairListResolver('VolumePairList', freqtradebot, whitelist_conf).pairlist
|
PairListManager(bot.exchange, whitelist_conf)
|
||||||
|
|
||||||
|
|
||||||
def test_VolumePairList_refresh_empty(mocker, markets_empty, whitelist_conf):
|
def test_VolumePairList_refresh_empty(mocker, markets_empty, whitelist_conf):
|
||||||
|
Loading…
Reference in New Issue
Block a user