@@ -216,13 +216,10 @@ def setUp(self):
216216 self .mockServices .services = mockServicesDict
217217 self .mockClient .services = self .mockServices
218218
219- # Patch runCoroutine
220- self .runCoroutinePatcher = patch ("hwIo.ble._io.runCoroutine" )
221- self .mockRunCoroutine = self .runCoroutinePatcher .start ()
222- mockFuture = MagicMock ()
223- mockFuture .result .return_value = None
224- mockFuture .exception .return_value = None
225- self .mockRunCoroutine .return_value = mockFuture
219+ # Patch runCoroutineSync (just returns None, as it's a synchronous wrapper)
220+ self .runCoroutineSyncPatcher = patch ("hwIo.ble._io.runCoroutineSync" )
221+ self .mockRunCoroutineSync = self .runCoroutineSyncPatcher .start ()
222+ self .mockRunCoroutineSync .return_value = None
226223
227224 # Import Ble after patching
228225 from hwIo .ble ._io import Ble
@@ -231,7 +228,7 @@ def setUp(self):
231228
232229 def tearDown (self ):
233230 """Clean up patches."""
234- self .runCoroutinePatcher .stop ()
231+ self .runCoroutineSyncPatcher .stop ()
235232 self .bleakClientPatcher .stop ()
236233
237234 def test_connectionSuccess (self ):
@@ -265,8 +262,8 @@ def onReceive(data):
265262 callArgs = self .mockBleakClientClass .call_args
266263 self .assertEqual (callArgs [0 ][0 ], mockDevice )
267264
268- # Verify runCoroutine was called at least once (_initAndConnect contains connect + start_notify)
269- self .assertGreaterEqual ( self . mockRunCoroutine . call_count , 1 )
265+ # Verify runCoroutineSync was called for initialization
266+ self .mockRunCoroutineSync . assert_called ( )
270267
271268 # Verify the connection is established
272269 self .assertTrue (ble .isConnected ())
@@ -296,8 +293,8 @@ def test_writeData(self):
296293 self .mockServices .get_service .assert_called_with ("service-uuid" )
297294 self .mockService .get_characteristic .assert_called_with ("write-char-uuid" )
298295
299- # Verify write was called (through runCoroutine )
300- self .mockRunCoroutine . assert_called ()
296+ # Verify write was called (through runCoroutineSync )
297+ self .assertGreater ( self . mockRunCoroutineSync . call_count , 1 ) # At least init + write
301298
302299 def test_writeDataChunking (self ):
303300 """Test that large data is split into MTU-sized chunks."""
@@ -320,14 +317,14 @@ def test_writeDataChunking(self):
320317 )
321318
322319 # Reset call count after initialization
323- initialCallCount = self .mockRunCoroutine .call_count
320+ initialCallCount = self .mockRunCoroutineSync .call_count
324321
325322 # Write 25 bytes (should split into 3 chunks: 10, 10, 5)
326323 testData = b"A" * 25
327324 ble .write (testData )
328325
329- # Verify runCoroutine was called 3 times for writes (plus initial calls)
330- writeCalls = self .mockRunCoroutine .call_count - initialCallCount
326+ # Verify runCoroutineSync was called 3 times for writes
327+ writeCalls = self .mockRunCoroutineSync .call_count - initialCallCount
331328 self .assertEqual (writeCalls , 3 )
332329
333330 def test_receiveNotification (self ):
@@ -353,9 +350,8 @@ def onReceive(data):
353350 ioThread = mockIoThread ,
354351 )
355352
356- # Get the notification callback that was registered
357- # It should be in the call to start_notify via runCoroutine
358- self .assertTrue (self .mockRunCoroutine .called )
353+ # Verify initialization occurred
354+ self .mockRunCoroutineSync .assert_called ()
359355
360356 # Simulate notification by calling _notifyReceive directly
361357 testData = bytearray (b"notification data" )
@@ -385,8 +381,8 @@ def test_closeCleanup(self):
385381 # Close the connection
386382 ble .close ()
387383
388- # Verify disconnect was called via runCoroutine
389- self .assertTrue (self .mockRunCoroutine . called )
384+ # Verify disconnect was called via runCoroutineSync (init + close)
385+ self .assertGreater (self .mockRunCoroutineSync . call_count , 1 )
390386
391387 # Verify onReceive callback was cleared
392388 self .assertIsNone (ble ._onReceive )
0 commit comments