@@ -76,46 +76,46 @@ def test_restart(self):
7676 with can .Bus ("test" , interface = "virtual" , receive_own_messages = True ) as bus :
7777 reader = can .BufferedReader ()
7878 notifier = can .Notifier (bus , [reader ], 0.1 )
79-
79+
8080 bus .send (can .Message (arbitration_id = 0x123 ))
8181 self .assertIsNotNone (reader .get_message (1 ))
82-
82+
8383 notifier .stop ()
8484 self .assertTrue (notifier .stopped )
85-
85+
8686 new_reader = can .BufferedReader ()
8787 notifier .listeners = [new_reader ]
88-
88+
8989 notifier .restart ()
9090 self .assertFalse (notifier .stopped )
91-
91+
9292 # Small settling time for the thread to actually start
9393 time .sleep (0.2 )
94-
94+
9595 # Send and Verify
9696 msg = can .Message (arbitration_id = 0xABC )
9797 bus .send (msg )
98-
98+
9999 recv = new_reader .get_message (1 )
100100 self .assertIsNotNone (recv , "Failed to receive message after restart" )
101101 self .assertEqual (recv .arbitration_id , 0xABC )
102-
102+
103103 notifier .stop ()
104104
105105 def test_restart_registry_lifecycle (self ):
106106 with can .Bus ("test" , interface = "virtual" , receive_own_messages = True ) as bus :
107107 notifier = can .Notifier (bus , [], 0.1 )
108108 notifier .stop ()
109-
109+
110110 # Verify it is removed from registry
111111 self .assertEqual (can .Notifier .find_instances (bus ), ())
112-
112+
113113 notifier .restart ()
114-
114+
115115 # Verify it is back in the registry and blocking others
116116 self .assertEqual (can .Notifier .find_instances (bus ), (notifier ,))
117117 self .assertRaises (ValueError , can .Notifier , bus , [], 0.1 )
118-
118+
119119 notifier .stop ()
120120
121121 def test_double_restart_warning (self ):
@@ -125,6 +125,7 @@ def test_double_restart_warning(self):
125125 with self .assertRaises (RuntimeWarning ):
126126 notifier .restart ()
127127
128+
128129class AsyncNotifierTest (unittest .TestCase ):
129130 def test_asyncio_notifier (self ):
130131 async def run_it ():
@@ -147,25 +148,25 @@ async def run_it():
147148 notifier = can .Notifier (
148149 bus , [reader ], 0.1 , loop = asyncio .get_running_loop ()
149150 )
150-
151+
151152 notifier .stop ()
152-
153+
153154 # In some cases, creating a new listener is the safest path for a restart
154155 new_reader = can .AsyncBufferedReader ()
155- notifier .listeners = [new_reader ]
156-
156+ notifier .listeners = [new_reader ]
157+
157158 notifier .restart ()
158-
159+
159160 # Small yield to let the selector register the FD
160161 await asyncio .sleep (0.1 )
161-
162+
162163 bus .send (can .Message (arbitration_id = 0x123 ))
163-
164+
164165 recv_msg = await asyncio .wait_for (new_reader .get_message (), 1.5 )
165-
166+
166167 self .assertIsNotNone (recv_msg )
167168 self .assertEqual (recv_msg .arbitration_id , 0x123 )
168-
169+
169170 notifier .stop ()
170171
171172 asyncio .run (run_it ())
0 commit comments