@@ -92,37 +92,40 @@ def test_lakeshore_visa_communication(self):
9292
9393 # Patch matplotlib.pyplot.subplots
9494 with patch ('matplotlib.pyplot.subplots' , return_value = (mock_fig , mock_ax )):
95-
96-
97- spy_instr .query .side_effect = [
98- "LSCI,MODEL350,123456,1.0" , # Response to *IDN?
99- "10.0" , # Initial temp
100- "10.0" , # Stability check 1
101- "10.1,50.0" , # Loop 1
102- "10.1" , # Stability check 2
103- "10.2,55.0" , # Loop 2
104- "10.2" , # Stability check 3
105- Exception ("Force Test Exit" ) # Force exit
106- ]
107-
108-
109- fake_inputs = ['10' , '300' , '10' , '350' ]
110- mock_file_dialog = MagicMock (return_value = "dummy.csv" )
111-
112-
113- with patch ('builtins.input' , side_effect = fake_inputs ), \
114- patch ('builtins.open' , mock_open ()), \
115- patch ('time.sleep' , MagicMock ()), \
116- patch ('tkinter.filedialog.asksaveasfilename' , mock_file_dialog ):
117-
118- self .run_module_safely (
119- "pica.lakeshore.Instrument_Control.T_Control_L350_Simple_Instrument_Control" )
120-
121- # --- ASSERTIONS ---
122- # Now that the script runs fully without crashing on .plot(),
123- # the cleanup code (RANGE 0) should finally execute.
124-
125- write_calls = [str (c ) for c in spy_instr .write .mock_calls ]
95+ # 1. Mock Responses (IDN, then temperature readings)
96+ spy_instr .query .side_effect = [
97+ "LSCI,MODEL350,123456,1.0" , # Response to *IDN?
98+ "10.0" , # Initial temp
99+ "10.0" , # Stability check 1
100+ "10.1,50.0" , # Loop 1
101+ "10.1" , # Stability check 2
102+ "10.2,55.0" , # Loop 2
103+ "10.2" , # Stability check 3
104+ Exception ("Force Test Exit" ) # Force exit
105+ ]
106+
107+ # 2. Mock Inputs and File Dialog
108+ fake_inputs = ['10' , '300' , '10' , '350' ]
109+ mock_file_dialog = MagicMock (return_value = "dummy.csv" )
110+
111+ # 3. Run It
112+ with patch ('builtins.input' , side_effect = fake_inputs ), \
113+ patch ('builtins.open' , mock_open ()), \
114+ patch ('time.sleep' , MagicMock ()), \
115+ patch ('tkinter.filedialog.asksaveasfilename' , mock_file_dialog ):
116+
117+ self .run_module_safely (
118+ "pica.lakeshore.Instrument_Control.T_Control_L350_Simple_Instrument_Control" )
119+
120+
121+ write_calls = [str (c ) for c in spy_instr .write .mock_calls ]
122+
123+ self .assertTrue (any ("HTRSET" in c for c in write_calls ), "HTRSET command not found" )
124+ print (" -> Verified: Heater Configured (HTRSET)" )
125+
126+ self .assertTrue (any ("RANGE 1,0" in c for c in write_calls ) or spy_instr .close .called ,
127+ "Safety Shutdown Failed: Heater not off and connection not closed." )
128+ print (" -> Verified: Safety Shutdown (Heater Off or Connection Closed)" )
126129
127130
128131
0 commit comments