11import asyncio
2+ import logging
23import threading
34from datetime import timedelta
45from time import sleep
56from unittest .mock import AsyncMock , MagicMock
67
8+ from ccxt import NotSupported
9+
710from freqtrade .enums import CandleType
811from freqtrade .exchange .exchange_ws import ExchangeWS
912from ft_client .test_client .test_rest_client import log_has_re
@@ -61,15 +64,18 @@ def thread_fuck():
6164 pass
6265
6366
64- async def test_exchangews_ohlcv (mocker , time_machine ):
67+ async def test_exchangews_ohlcv (mocker , time_machine , caplog ):
6568 config = MagicMock ()
6669 ccxt_object = MagicMock ()
70+ caplog .set_level (logging .DEBUG )
6771
6872 async def sleeper (* args , ** kwargs ):
6973 # pass
7074 await asyncio .sleep (0.12 )
7175 return MagicMock ()
7276
77+ ccxt_object .un_watch_ohlcv_for_symbols = AsyncMock (side_effect = NotSupported )
78+
7379 ccxt_object .watch_ohlcv = AsyncMock (side_effect = sleeper )
7480 ccxt_object .close = AsyncMock ()
7581 time_machine .move_to ("2024-11-01 01:00:02 +00:00" )
@@ -101,11 +107,14 @@ async def sleeper(*args, **kwargs):
101107 time_machine .shift (timedelta (minutes = 5 ))
102108 exchange_ws .schedule_ohlcv ("ETH/BTC" , "1m" , CandleType .SPOT )
103109 await asyncio .sleep (1 )
110+ assert log_has_re ("un_watch_ohlcv_for_symbols not supported: " , caplog )
104111 # XRP/BTC should be cleaned up.
105112 assert exchange_ws ._klines_watching == {
106113 ("ETH/BTC" , "1m" , CandleType .SPOT ),
107114 }
115+
108116 # Cleanup happened.
117+ ccxt_object .un_watch_ohlcv_for_symbols = AsyncMock (side_effect = ValueError )
109118 exchange_ws .schedule_ohlcv ("ETH/BTC" , "1m" , CandleType .SPOT )
110119 assert exchange_ws ._klines_watching == {
111120 ("ETH/BTC" , "1m" , CandleType .SPOT ),
@@ -117,6 +126,7 @@ async def sleeper(*args, **kwargs):
117126 finally :
118127 # Cleanup
119128 exchange_ws .cleanup ()
129+ assert log_has_re ("Exception in _unwatch_ohlcv" , caplog )
120130
121131
122132async def test_exchangews_get_ohlcv (mocker , caplog ):
0 commit comments