@@ -23,9 +23,11 @@ def tearDown(self):
2323 # -------------------------------------------------------------------------
2424 def _timeout_handler (self , signum , frame ):
2525 raise TimeoutError (
26- f"Test { self ._testMethodName } took longer than 30s! Infinite Loop suspected." )
27- def run_module_safely (self , module_name , mock_modules ): """Imports and runs a module with a strict 30-second timeout."""
28- with patch .dict ('sys.modules' , mock_modules ):
26+ f"Test { self ._testMethodName } took longer than 30s! Infinite Loop suspected." )
27+
28+ def run_module_safely (self , module_name , mock_modules ):
29+ """Imports and runs a module with a strict 30-second timeout."""
30+ with patch .dict ('sys.modules' , mock_modules ): # type: ignore
2931 # Set an alarm for 30 seconds (Works on Linux/GitHub Actions)
3032 if hasattr (signal , 'SIGALRM' ):
3133 # Ensure any previous alarm is cleared
@@ -54,7 +56,7 @@ def run_module_safely(self, module_name, mock_modules): """Imports and ru
5456 raise e # Re-raise to fail the test
5557 else :
5658 print (f" -> [INFO] Script stopped with: { e } " , flush = True )
57-
59+
5860 finally :
5961 if hasattr (signal , 'SIGALRM' ):
6062 signal .alarm (0 ) # Disable the alarm
@@ -143,9 +145,9 @@ def test_02_lakeshore_backend(self):
143145 with patch ('builtins.input' , side_effect = ['10' , '300' , '10' , '350' ]), \
144146 patch ('builtins.open' , mock_open ()), \
145147 patch ('matplotlib.pyplot.show' ), \
146- patch ('matplotlib.pyplot.subplots' , return_value = (mock_fig , mock_ax )):
148+ patch ('matplotlib.pyplot.subplots' , return_value = (mock_fig , mock_ax )): # noqa
147149 self .run_module_safely ("Lakeshore_350_340.Backends.T_Control_L350_Simple_Backend_v10" , mock_modules )
148-
150+
149151 def test_03_k6517b_pyro_backend (self ):
150152 mock_modules = {
151153 'tkinter' : MagicMock (),
@@ -252,7 +254,8 @@ def test_06_delta_sensing(self):
252254 with patch ('builtins.input' , side_effect = inputs ), \
253255 patch ('pandas.DataFrame.to_csv' ):
254256 try :
255- self .run_module_safely ("Delta_mode_Keithley_6221_2182.Backends.Delta_K6221_K2182_L350_T_Sensing_Backend_v1" , mock_modules )
257+ self .run_module_safely (
258+ "Delta_mode_Keithley_6221_2182.Backends.Delta_K6221_K2182_L350_T_Sensing_Backend_v1" , mock_modules )
256259 except ModuleNotFoundError :
257260 print (" [SKIP] Module not found, skipping." )
258261
@@ -319,7 +322,8 @@ def test_08_combined_2400_2182(self):
319322 inputs = ['10' , '1' , 'test_file' , 'y' , 'y' , 'y' , 'y' ]
320323 with patch ('builtins.input' , side_effect = inputs ), \
321324 patch ('pandas.DataFrame.to_csv' ):
322- self .run_module_safely ("Keithley_2400_Keithley_2182.Backends.IV_K2400_K2182_Backend_v1" , mock_modules )
325+ self .run_module_safely (
326+ "Keithley_2400_Keithley_2182.Backends.IV_K2400_K2182_Backend_v1" , mock_modules )
323327 mock_pymeasure .stop ()
324328
325329 def test_09_poling (self ):
@@ -414,9 +418,8 @@ def test_12_gpib_rescue(self):
414418 rm = MockRM .return_value
415419 rm .list_resources .return_value = ('GPIB0::1::INSTR' ,)
416420 self .run_module_safely (
417- "Utilities.GPIB_Interface_Rescue_Simple_Backened_v2_" , mock_modules )
418-
419-
420- if __name__ == '__main__' :
421- unittest .main ()
422-
421+ "Utilities.GPIB_Interface_Rescue_Simple_Backened_v2_" , mock_modules )
422+
423+
424+ if __name__ == '__main__' :
425+ unittest .main ()
0 commit comments