Introduce markets_static fixture serving an immutable list of markets. Adapt pairlist/markets tests to use this new fixture.
This allows freely modifying markets in get_markets() without a need of updating pairlist/markets tests.
This commit is contained in:
parent
5726886b06
commit
e025576d8c
@ -208,11 +208,10 @@ def test_list_timeframes(mocker, capsys):
|
||||
assert re.search(r"^1d$", captured.out, re.MULTILINE)
|
||||
|
||||
|
||||
def test_list_markets(mocker, markets, capsys):
|
||||
def test_list_markets(mocker, markets_static, capsys):
|
||||
|
||||
api_mock = MagicMock()
|
||||
api_mock.markets = markets
|
||||
patch_exchange(mocker, api_mock=api_mock, id='bittrex')
|
||||
patch_exchange(mocker, api_mock=api_mock, id='bittrex', mock_markets=markets_static)
|
||||
|
||||
# Test with no --config
|
||||
args = [
|
||||
@ -237,7 +236,7 @@ def test_list_markets(mocker, markets, capsys):
|
||||
"TKN/BTC, XLTCUSDT, XRP/BTC.\n"
|
||||
in captured.out)
|
||||
|
||||
patch_exchange(mocker, api_mock=api_mock, id="binance")
|
||||
patch_exchange(mocker, api_mock=api_mock, id="binance", mock_markets=markets_static)
|
||||
# Test with --exchange
|
||||
args = [
|
||||
"list-markets",
|
||||
@ -250,7 +249,7 @@ def test_list_markets(mocker, markets, capsys):
|
||||
assert re.match("\nExchange Binance has 10 active markets:\n",
|
||||
captured.out)
|
||||
|
||||
patch_exchange(mocker, api_mock=api_mock, id="bittrex")
|
||||
patch_exchange(mocker, api_mock=api_mock, id="bittrex", mock_markets=markets_static)
|
||||
# Test with --all: all markets
|
||||
args = [
|
||||
"list-markets", "--all",
|
||||
|
@ -90,8 +90,10 @@ def patch_exchange(mocker, api_mock=None, id='binance', mock_markets=True) -> No
|
||||
mocker.patch('freqtrade.exchange.Exchange.name', PropertyMock(return_value=id.title()))
|
||||
mocker.patch('freqtrade.exchange.Exchange.precisionMode', PropertyMock(return_value=2))
|
||||
if mock_markets:
|
||||
if isinstance(mock_markets, bool):
|
||||
mock_markets = get_markets()
|
||||
mocker.patch('freqtrade.exchange.Exchange.markets',
|
||||
PropertyMock(return_value=get_markets()))
|
||||
PropertyMock(return_value=mock_markets))
|
||||
|
||||
if api_mock:
|
||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
||||
@ -376,6 +378,8 @@ def markets():
|
||||
|
||||
|
||||
def get_markets():
|
||||
# See get_markets_static() for immutable markets and do not modify them unless absolutely
|
||||
# necessary!
|
||||
return {
|
||||
'ETH/BTC': {
|
||||
'id': 'ethbtc',
|
||||
@ -675,11 +679,22 @@ def get_markets():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def shitcoinmarkets(markets):
|
||||
def markets_static():
|
||||
# These markets are used in some tests that would need adaptation should anything change in
|
||||
# market list. Do not modify this list without a good reason! Do not modify market parameters
|
||||
# of listed pairs in get_markets() without a good reason either!
|
||||
static_markets = ['BLK/BTC', 'BTT/BTC', 'ETH/BTC', 'ETH/USDT', 'LTC/BTC', 'LTC/ETH', 'LTC/USD',
|
||||
'LTC/USDT', 'NEO/BTC', 'TKN/BTC', 'XLTCUSDT', 'XRP/BTC']
|
||||
all_markets = get_markets()
|
||||
return {m: all_markets[m] for m in static_markets}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def shitcoinmarkets(markets_static):
|
||||
"""
|
||||
Fixture with shitcoin markets - used to test filters in pairlists
|
||||
"""
|
||||
shitmarkets = deepcopy(markets)
|
||||
shitmarkets = deepcopy(markets_static)
|
||||
shitmarkets.update({
|
||||
'HOT/BTC': {
|
||||
'id': 'HOTBTC',
|
||||
|
@ -2735,7 +2735,7 @@ def test_get_valid_pair_combination(default_conf, mocker, markets):
|
||||
(['LTC'], ['NONEXISTENT'], False, False,
|
||||
[]),
|
||||
])
|
||||
def test_get_markets(default_conf, mocker, markets,
|
||||
def test_get_markets(default_conf, mocker, markets_static,
|
||||
base_currencies, quote_currencies, pairs_only, active_only,
|
||||
expected_keys):
|
||||
mocker.patch.multiple('freqtrade.exchange.Exchange',
|
||||
@ -2743,7 +2743,7 @@ def test_get_markets(default_conf, mocker, markets,
|
||||
_load_async_markets=MagicMock(),
|
||||
validate_pairs=MagicMock(),
|
||||
validate_timeframes=MagicMock(),
|
||||
markets=PropertyMock(return_value=markets))
|
||||
markets=PropertyMock(return_value=markets_static))
|
||||
ex = Exchange(default_conf)
|
||||
pairs = ex.get_markets(base_currencies, quote_currencies, pairs_only, active_only)
|
||||
assert sorted(pairs.keys()) == sorted(expected_keys)
|
||||
|
@ -131,9 +131,9 @@ def test_load_pairlist_noexist(mocker, markets, default_conf):
|
||||
default_conf, {}, 1)
|
||||
|
||||
|
||||
def test_load_pairlist_verify_multi(mocker, markets, default_conf):
|
||||
def test_load_pairlist_verify_multi(mocker, markets_static, default_conf):
|
||||
freqtrade = 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_static))
|
||||
plm = PairListManager(freqtrade.exchange, default_conf)
|
||||
# Call different versions one after the other, should always consider what was passed in
|
||||
# and have no side-effects (therefore the same check multiple times)
|
||||
|
Loading…
Reference in New Issue
Block a user