Update unit tests to be compatible with this refactoring
Updated: - test_acl_pair to be compatible with FreqtradeBot() class - test_default_strategy.py to be compatible with Analyze() class
This commit is contained in:
parent
383fb6d20e
commit
766ec5ad0f
@ -11,7 +11,7 @@ from telegram import Chat, Message, Update
|
|||||||
|
|
||||||
from freqtrade.analyze import Analyze
|
from freqtrade.analyze import Analyze
|
||||||
from freqtrade.constants import Constants
|
from freqtrade.constants import Constants
|
||||||
from freqtrade.strategy.strategy import Strategy
|
from freqtrade.freqtradebot import FreqtradeBot
|
||||||
|
|
||||||
logging.getLogger('').setLevel(logging.INFO)
|
logging.getLogger('').setLevel(logging.INFO)
|
||||||
|
|
||||||
@ -24,6 +24,26 @@ def log_has(line, logs):
|
|||||||
False)
|
False)
|
||||||
|
|
||||||
|
|
||||||
|
# Functions for recurrent object patching
|
||||||
|
def get_patched_freqtradebot(mocker, config) -> FreqtradeBot:
|
||||||
|
"""
|
||||||
|
This function patch _init_modules() to not call dependencies
|
||||||
|
:param mocker: a Mocker object to apply patches
|
||||||
|
:param config: Config to pass to the bot
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
mocker.patch('freqtrade.fiat_convert.Pymarketcap', {'price_usd': 12345.0})
|
||||||
|
mocker.patch('freqtrade.freqtradebot.Analyze', MagicMock())
|
||||||
|
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
|
||||||
|
mocker.patch('freqtrade.freqtradebot.persistence.init', MagicMock())
|
||||||
|
mocker.patch('freqtrade.freqtradebot.exchange.init', MagicMock())
|
||||||
|
mocker.patch('freqtrade.freqtradebot.RPCManager._init', MagicMock())
|
||||||
|
mocker.patch('freqtrade.freqtradebot.RPCManager.send_msg', MagicMock())
|
||||||
|
mocker.patch('freqtrade.freqtradebot.Analyze.get_signal', MagicMock())
|
||||||
|
|
||||||
|
return FreqtradeBot(config)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def default_conf():
|
def default_conf():
|
||||||
""" Returns validated configuration suitable for most tests """
|
""" Returns validated configuration suitable for most tests """
|
||||||
|
@ -2,13 +2,13 @@ import json
|
|||||||
import pytest
|
import pytest
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
from freqtrade.strategy.default_strategy import DefaultStrategy, class_name
|
from freqtrade.strategy.default_strategy import DefaultStrategy, class_name
|
||||||
from freqtrade.analyze import parse_ticker_dataframe
|
from freqtrade.analyze import Analyze
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def result():
|
def result():
|
||||||
with open('freqtrade/tests/testdata/BTC_ETH-1.json') as data_file:
|
with open('freqtrade/tests/testdata/BTC_ETH-1.json') as data_file:
|
||||||
return parse_ticker_dataframe(json.load(data_file))
|
return Analyze.parse_ticker_dataframe(json.load(data_file))
|
||||||
|
|
||||||
|
|
||||||
def test_default_strategy_class_name():
|
def test_default_strategy_class_name():
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# pragma pylint: disable=missing-docstring,C0103
|
# pragma pylint: disable=missing-docstring,C0103,protected-access
|
||||||
|
|
||||||
from freqtrade.main import refresh_whitelist, gen_pair_whitelist
|
import freqtrade.tests.conftest as tt # test tools
|
||||||
|
|
||||||
# whitelist, blacklist, filtering, all of that will
|
# whitelist, blacklist, filtering, all of that will
|
||||||
# eventually become some rules to run on a generic ACL engine
|
# eventually become some rules to run on a generic ACL engine
|
||||||
@ -8,21 +8,22 @@ from freqtrade.main import refresh_whitelist, gen_pair_whitelist
|
|||||||
|
|
||||||
|
|
||||||
def whitelist_conf():
|
def whitelist_conf():
|
||||||
return {
|
config = tt.default_conf()
|
||||||
'stake_currency': 'BTC',
|
|
||||||
'exchange': {
|
config['stake_currency'] = 'BTC'
|
||||||
'pair_whitelist': [
|
config['exchange']['pair_whitelist'] = [
|
||||||
'BTC_ETH',
|
'BTC_ETH',
|
||||||
'BTC_TKN',
|
'BTC_TKN',
|
||||||
'BTC_TRST',
|
'BTC_TRST',
|
||||||
'BTC_SWT',
|
'BTC_SWT',
|
||||||
'BTC_BCC'
|
'BTC_BCC'
|
||||||
],
|
]
|
||||||
'pair_blacklist': [
|
|
||||||
|
config['exchange']['pair_blacklist'] = [
|
||||||
'BTC_BLK'
|
'BTC_BLK'
|
||||||
],
|
]
|
||||||
},
|
|
||||||
}
|
return config
|
||||||
|
|
||||||
|
|
||||||
def get_market_summaries():
|
def get_market_summaries():
|
||||||
@ -86,11 +87,13 @@ def get_health_empty():
|
|||||||
|
|
||||||
def test_refresh_market_pair_not_in_whitelist(mocker):
|
def test_refresh_market_pair_not_in_whitelist(mocker):
|
||||||
conf = whitelist_conf()
|
conf = whitelist_conf()
|
||||||
mocker.patch.dict('freqtrade.main._CONF', conf)
|
|
||||||
mocker.patch.multiple('freqtrade.main.exchange',
|
freqtradebot = tt.get_patched_freqtradebot(mocker, conf)
|
||||||
get_wallet_health=get_health)
|
|
||||||
refreshedwhitelist = refresh_whitelist(
|
mocker.patch('freqtrade.freqtradebot.exchange.get_wallet_health', get_health)
|
||||||
conf['exchange']['pair_whitelist'] + ['BTC_XXX'])
|
refreshedwhitelist = freqtradebot._refresh_whitelist(
|
||||||
|
conf['exchange']['pair_whitelist'] + ['BTC_XXX']
|
||||||
|
)
|
||||||
# List ordered by BaseVolume
|
# List ordered by BaseVolume
|
||||||
whitelist = ['BTC_ETH', 'BTC_TKN']
|
whitelist = ['BTC_ETH', 'BTC_TKN']
|
||||||
# Ensure all except those in whitelist are removed
|
# Ensure all except those in whitelist are removed
|
||||||
@ -99,10 +102,11 @@ def test_refresh_market_pair_not_in_whitelist(mocker):
|
|||||||
|
|
||||||
def test_refresh_whitelist(mocker):
|
def test_refresh_whitelist(mocker):
|
||||||
conf = whitelist_conf()
|
conf = whitelist_conf()
|
||||||
mocker.patch.dict('freqtrade.main._CONF', conf)
|
freqtradebot = tt.get_patched_freqtradebot(mocker, conf)
|
||||||
mocker.patch.multiple('freqtrade.main.exchange',
|
|
||||||
get_wallet_health=get_health)
|
mocker.patch('freqtrade.freqtradebot.exchange.get_wallet_health', get_health)
|
||||||
refreshedwhitelist = refresh_whitelist(conf['exchange']['pair_whitelist'])
|
refreshedwhitelist = freqtradebot._refresh_whitelist(conf['exchange']['pair_whitelist'])
|
||||||
|
|
||||||
# List ordered by BaseVolume
|
# List ordered by BaseVolume
|
||||||
whitelist = ['BTC_ETH', 'BTC_TKN']
|
whitelist = ['BTC_ETH', 'BTC_TKN']
|
||||||
# Ensure all except those in whitelist are removed
|
# Ensure all except those in whitelist are removed
|
||||||
@ -111,26 +115,32 @@ def test_refresh_whitelist(mocker):
|
|||||||
|
|
||||||
def test_refresh_whitelist_dynamic(mocker):
|
def test_refresh_whitelist_dynamic(mocker):
|
||||||
conf = whitelist_conf()
|
conf = whitelist_conf()
|
||||||
mocker.patch.dict('freqtrade.main._CONF', conf)
|
freqtradebot = tt.get_patched_freqtradebot(mocker, conf)
|
||||||
mocker.patch.multiple('freqtrade.main.exchange',
|
mocker.patch.multiple(
|
||||||
get_wallet_health=get_health)
|
'freqtrade.freqtradebot.exchange',
|
||||||
mocker.patch.multiple('freqtrade.main.exchange',
|
get_wallet_health=get_health,
|
||||||
get_market_summaries=get_market_summaries)
|
get_market_summaries=get_market_summaries
|
||||||
|
)
|
||||||
|
|
||||||
# argument: use the whitelist dynamically by exchange-volume
|
# argument: use the whitelist dynamically by exchange-volume
|
||||||
whitelist = ['BTC_TKN', 'BTC_ETH']
|
whitelist = ['BTC_TKN', 'BTC_ETH']
|
||||||
refreshedwhitelist = refresh_whitelist(
|
|
||||||
gen_pair_whitelist(conf['stake_currency']))
|
refreshedwhitelist = freqtradebot._refresh_whitelist(
|
||||||
|
freqtradebot._gen_pair_whitelist(conf['stake_currency'])
|
||||||
|
)
|
||||||
|
|
||||||
assert whitelist == refreshedwhitelist
|
assert whitelist == refreshedwhitelist
|
||||||
|
|
||||||
|
|
||||||
def test_refresh_whitelist_dynamic_empty(mocker):
|
def test_refresh_whitelist_dynamic_empty(mocker):
|
||||||
conf = whitelist_conf()
|
conf = whitelist_conf()
|
||||||
mocker.patch.dict('freqtrade.main._CONF', conf)
|
freqtradebot = tt.get_patched_freqtradebot(mocker, conf)
|
||||||
mocker.patch.multiple('freqtrade.main.exchange',
|
mocker.patch('freqtrade.freqtradebot.exchange.get_wallet_health', get_health_empty)
|
||||||
get_wallet_health=get_health_empty)
|
|
||||||
# argument: use the whitelist dynamically by exchange-volume
|
# argument: use the whitelist dynamically by exchange-volume
|
||||||
whitelist = []
|
whitelist = []
|
||||||
conf['exchange']['pair_whitelist'] = []
|
conf['exchange']['pair_whitelist'] = []
|
||||||
refresh_whitelist(whitelist)
|
freqtradebot._refresh_whitelist(whitelist)
|
||||||
pairslist = conf['exchange']['pair_whitelist']
|
pairslist = conf['exchange']['pair_whitelist']
|
||||||
|
|
||||||
assert set(whitelist) == set(pairslist)
|
assert set(whitelist) == set(pairslist)
|
||||||
|
Loading…
Reference in New Issue
Block a user