Simplify mocking

This commit is contained in:
Matthias
2023-04-16 17:45:56 +02:00
parent 7171fd1132
commit 5608aaca26
2 changed files with 8 additions and 3 deletions

View File

@@ -107,8 +107,7 @@ class Exchange:
# Lock event loop. This is necessary to avoid race-conditions when using force* commands
# Due to funding fee fetching.
self._loop_lock = Lock()
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
self.loop = self._init_async_loop()
self._config: Config = {}
self._config.update(config)
@@ -212,6 +211,11 @@ class Exchange:
if self.loop and not self.loop.is_closed():
self.loop.close()
def _init_async_loop(self):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
return loop
def validate_config(self, config):
# Check if timeframe is available
self.validate_timeframes(config.get('timeframe'))

View File

@@ -89,6 +89,7 @@ def get_telegram_testobject(mocker, default_conf, mock=True, ftbot=None):
_start_thread=MagicMock(),
)
if not ftbot:
mocker.patch('freqtrade.exchange.exchange.Exchange._init_async_loop')
ftbot = get_patched_freqtradebot(mocker, default_conf)
rpc = RPC(ftbot)
telegram = Telegram(rpc, default_conf)
@@ -140,7 +141,7 @@ async def test_telegram_startup(default_conf, mocker) -> None:
app_mock.start = AsyncMock()
app_mock.updater.start_polling = AsyncMock()
app_mock.updater.running = False
sleep_mock = mocker.patch('freqtrade.rpc.telegram.asyncio.sleep',AsyncMock())
sleep_mock = mocker.patch('freqtrade.rpc.telegram.asyncio.sleep', AsyncMock())
telegram, _, _ = get_telegram_testobject(mocker, default_conf)
telegram._app = app_mock