mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
don't import python-telegram-bot at runtime if disabled in config
This commit is contained in:
parent
4048859912
commit
3787dad212
|
@ -5,7 +5,6 @@ import logging
|
|||
from typing import List
|
||||
|
||||
from freqtrade.rpc.rpc import RPC
|
||||
from freqtrade.rpc.telegram import Telegram
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -21,6 +20,7 @@ class RPCManager(object):
|
|||
# Enable telegram
|
||||
if freqtrade.config['telegram'].get('enabled', False):
|
||||
logger.info('Enabling rpc.telegram ...')
|
||||
from freqtrade.rpc.telegram import Telegram
|
||||
self.registered_modules.append(Telegram(freqtrade))
|
||||
|
||||
def cleanup(self) -> None:
|
||||
|
|
|
@ -16,6 +16,8 @@ from freqtrade.rpc.rpc import RPC, RPCException
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
logger.debug('Included module rpc.telegram ...')
|
||||
|
||||
|
||||
def authorized_only(command_handler: Callable[[Any, Bot, Update], None]) -> Callable[..., Any]:
|
||||
"""
|
||||
|
|
|
@ -31,7 +31,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
|
|||
"""
|
||||
patch_get_signal(mocker, (True, False))
|
||||
patch_coinmarketcap(mocker)
|
||||
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
|
||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.freqtradebot.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
|
@ -77,7 +77,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None:
|
|||
"""
|
||||
patch_get_signal(mocker, (True, False))
|
||||
patch_coinmarketcap(mocker)
|
||||
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
|
||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.freqtradebot.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
|
@ -110,7 +110,7 @@ def test_rpc_daily_profit(default_conf, update, ticker, fee,
|
|||
"""
|
||||
patch_get_signal(mocker, (True, False))
|
||||
patch_coinmarketcap(mocker, value={'price_usd': 15000.0})
|
||||
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
|
||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.freqtradebot.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
|
@ -165,7 +165,7 @@ def test_rpc_trade_statistics(default_conf, ticker, ticker_sell_up, fee,
|
|||
ticker=MagicMock(return_value={'price_usd': 15000.0}),
|
||||
)
|
||||
mocker.patch('freqtrade.fiat_convert.CryptoToFiatConverter._find_price', return_value=15000.0)
|
||||
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
|
||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.freqtradebot.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
|
@ -241,7 +241,7 @@ def test_rpc_trade_statistics_closed(mocker, default_conf, ticker, fee,
|
|||
ticker=MagicMock(return_value={'price_usd': 15000.0}),
|
||||
)
|
||||
mocker.patch('freqtrade.fiat_convert.CryptoToFiatConverter._find_price', return_value=15000.0)
|
||||
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
|
||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.freqtradebot.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
|
@ -312,7 +312,7 @@ def test_rpc_balance_handle(default_conf, mocker):
|
|||
ticker=MagicMock(return_value={'price_usd': 15000.0}),
|
||||
)
|
||||
mocker.patch('freqtrade.fiat_convert.CryptoToFiatConverter._find_price', return_value=15000.0)
|
||||
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
|
||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.freqtradebot.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
|
@ -340,7 +340,7 @@ def test_rpc_start(mocker, default_conf) -> None:
|
|||
"""
|
||||
patch_get_signal(mocker, (True, False))
|
||||
patch_coinmarketcap(mocker)
|
||||
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
|
||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.freqtradebot.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
|
@ -366,7 +366,7 @@ def test_rpc_stop(mocker, default_conf) -> None:
|
|||
"""
|
||||
patch_get_signal(mocker, (True, False))
|
||||
patch_coinmarketcap(mocker)
|
||||
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
|
||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.freqtradebot.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
|
@ -392,7 +392,7 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker) -> None:
|
|||
"""
|
||||
patch_get_signal(mocker, (True, False))
|
||||
patch_coinmarketcap(mocker)
|
||||
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
|
||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||
|
||||
cancel_order_mock = MagicMock()
|
||||
mocker.patch.multiple(
|
||||
|
@ -495,7 +495,7 @@ def test_performance_handle(default_conf, ticker, limit_buy_order, fee,
|
|||
"""
|
||||
patch_get_signal(mocker, (True, False))
|
||||
patch_coinmarketcap(mocker)
|
||||
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
|
||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.freqtradebot.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
|
@ -533,7 +533,7 @@ def test_rpc_count(mocker, default_conf, ticker, fee) -> None:
|
|||
"""
|
||||
patch_get_signal(mocker, (True, False))
|
||||
patch_coinmarketcap(mocker)
|
||||
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
|
||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.freqtradebot.exchange',
|
||||
validate_pairs=MagicMock(),
|
||||
|
|
|
@ -57,7 +57,7 @@ def patch_RPCManager(mocker) -> MagicMock:
|
|||
:param mocker: mocker to patch RPCManager class
|
||||
:return: RPCManager.send_msg MagicMock to track if this method is called
|
||||
"""
|
||||
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
|
||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||
rpc_mock = mocker.patch('freqtrade.freqtradebot.RPCManager.send_msg', MagicMock())
|
||||
return rpc_mock
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user