11import unittest
22from unittest .mock import patch , MagicMock , mock_open
3- import pyvisa # Added import for pyvisa
3+ import pyvisa
44
55class TestFixes (unittest .TestCase ):
66
77 @patch ('Keithley_2400.Backends.IV_K2400_Loop_Backend_v10.sleep' , MagicMock ())
88 @patch ('builtins.input' , side_effect = ['10' , '2' , 'test_output' ])
9- @patch ('pymeasure.instruments.keithley .Keithley2400' ) # Patch Keithley2400 from pymeasure
9+ @patch ('Keithley_2400.Backends.IV_K2400_Loop_Backend_v10 .Keithley2400' )
1010 @patch ('matplotlib.pyplot.show' )
1111 @patch ('pandas.DataFrame.to_csv' )
12- def test_iv_k2400_fix (self , mock_to_csv , mock_plt_show , mock_keithley_class , mock_input ):
12+ def test_iv_k2400_fix (self , mock_to_csv , mock_plt_show , mock_keithley_class , mock_input ): # type: ignore
1313 """
1414 This test verifies that the Keithley2400 is correctly mocked in the
1515 IV_K2400_Loop_Backend_v10 script, preventing real hardware calls.
@@ -18,26 +18,19 @@ def test_iv_k2400_fix(self, mock_to_csv, mock_plt_show, mock_keithley_class, moc
1818
1919 mock_keithley_instance = MagicMock ()
2020 mock_keithley_class .return_value = mock_keithley_instance
21- mock_keithley_instance .query .return_value = "KEITHLEY INSTRUMENTS INC., MODEL 2400" # Simulate IDN query
21+ mock_keithley_instance .query .return_value = "KEITHLEY INSTRUMENTS INC., MODEL 2400"
2222
2323 iv_backend .main ()
2424 mock_keithley_class .assert_called_once_with ("GPIB::4" )
2525
2626
27- @patch ('tkinter.Tk' )
28- @patch ('tkinter.filedialog.asksaveasfilename' , return_value = 'test.csv' )
29- @patch ('builtins.input' , side_effect = ['10' , '20' , '5' , '30' ])
30- @patch ('Lakeshore_350_340.Backends.T_Control_L350_Simple_Backend_v10.pyvisa.ResourceManager' ) # Patch pyvisa.ResourceManager
31- @patch ('matplotlib.pyplot.show' )
32- @patch ('builtins.open' , new_callable = mock_open )
33- @patch ('Lakeshore_350_340.Backends.T_Control_L350_Simple_Backend_v10.time.sleep' , MagicMock ())
34- @patch ('time.time' , side_effect = [1000 , 1002 , 1004 , 1006 , 1008 , 1010 ])
35- def test_t_control_l350_fix (self , mock_time , mock_open_file , mock_plt_show , mock_rm , mock_input , mock_file_dialog , mock_tk ):
27+ @patch ('Lakeshore_350_340.Backends.T_Control_L350_Simple_Backend_v10.Lakeshore350' )
28+ def test_t_control_l350_fix (self , mock_ls_class ):
3629 from Lakeshore_350_340 .Backends .T_Control_L350_Simple_Backend_v10 import main
3730
38- mock_instrument_from_rm = MagicMock ()
39- mock_rm . return_value . open_resource . return_value = mock_instrument_from_rm
40- mock_instrument_from_rm . query . return_value = "LSCI,MODEL350,12345,1.0"
41-
42- main ()
43- mock_rm . return_value . open_resource .assert_called_once_with ("GPIB0::13::INSTR" )
31+ with patch ( 'builtins.input' , side_effect = [ '10' , '20' , '5' , '30' ]), \
32+ patch ( 'tkinter.filedialog.asksaveasfilename' , return_value = 'test.csv' ), \
33+ patch ( 'matplotlib.pyplot.show' ), \
34+ patch ( 'builtins.open' , mock_open ()):
35+ main ()
36+ mock_ls_class .assert_called_once_with ("GPIB0::13::INSTR" )
0 commit comments