@@ -74,20 +74,25 @@ def test_keithley2400_iv_protocol(self):
7474 def test_lakeshore_visa_communication (self ):
7575 print ("\n [SIMULATION] Testing Lakeshore 350 SCPI Commands..." )
7676
77- # We tell the mock axis that when .plot() is called, it returns a list with 1 item
78- mock_ax .plot .return_value = [MagicMock ()]
79-
80- # Handle "ax1, ax2 = fig.subplots()" (expected 2)
81- mock_fig .subplots .return_value = (mock_ax , mock_ax )
82-
83- # Patch ResourceManager AND pyplot
84- with patch ('pyvisa.ResourceManager' ) as MockResourceManager , \
85- patch ('matplotlib.pyplot.subplots' , return_value = (mock_fig , mock_ax )):
86-
77+ with patch ('pyvisa.ResourceManager' ) as MockResourceManager :
8778 mock_rm_instance = MockResourceManager .return_value
8879 spy_instr = MagicMock ()
8980 mock_rm_instance .open_resource .return_value = spy_instr
9081
82+ # FIX 1: Create mocks for Figure and Axes
83+ mock_fig = MagicMock ()
84+ mock_ax = MagicMock ()
85+
86+ # FIX 2: Handle "line, = ax.plot()" failure (expected 1, got 0)
87+ # We tell the mock axis that when .plot() is called, it returns a list with 1 item
88+ mock_ax .plot .return_value = [MagicMock ()]
89+
90+ # FIX 3: Handle "ax1, ax2 = fig.subplots()" (expected 2)
91+ mock_fig .subplots .return_value = (mock_ax , mock_ax )
92+
93+ # Patch matplotlib.pyplot.subplots
94+ with patch ('matplotlib.pyplot.subplots' , return_value = (mock_fig , mock_ax )):
95+
9196
9297 spy_instr .query .side_effect = [
9398 "LSCI,MODEL350,123456,1.0" , # Response to *IDN?
0 commit comments