Skip to content

Commit 1f93c18

Browse files
tests updated
1 parent 4852217 commit 1f93c18

5 files changed

Lines changed: 10 additions & 22 deletions

File tree

tests/test_fixes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ class 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('pyvisa.ResourceManager') # Patch pyvisa.ResourceManager
9+
@patch('pymeasure.instruments.keithley.Keithley2400') # Patch Keithley2400 from pymeasure
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_rm, mock_input):
12+
def test_iv_k2400_fix(self, mock_to_csv, mock_plt_show, mock_keithley_class, mock_input):
1313
"""
1414
This test verifies that the Keithley2400 is correctly mocked in the
1515
IV_K2400_Loop_Backend_v10 script, preventing real hardware calls.
1616
"""
1717
from Keithley_2400.Backends import IV_K2400_Loop_Backend_v10 as iv_backend
1818

1919
mock_keithley_instance = MagicMock()
20-
mock_rm.return_value.open_resource.return_value = mock_keithley_instance
20+
mock_keithley_class.return_value = mock_keithley_instance
2121
mock_keithley_instance.query.return_value = "KEITHLEY INSTRUMENTS INC., MODEL 2400" # Simulate IDN query
2222

2323
iv_backend.main()
24-
mock_rm.return_value.open_resource.assert_called_once_with("GPIB::4")
24+
mock_keithley_class.assert_called_once_with("GPIB::4")
2525

2626

2727
@patch('tkinter.Tk')

tests/test_gui_iv_k2400.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def tearDown(self):
2323
self.root.destroy()
2424

2525
@patch('Keithley_2400.IV_K2400_GUI_v5.Keithley2400_IV_Backend')
26-
@patch('Keithley_2400.IV_K2400_GUI_v5.Figure.subplots')
27-
def test_start_measurement_logic(self, mock_fig_subplots, MockBackend):
26+
@patch('Keithley_2400.IV_K2400_GUI_v5.Figure') # Patch the Figure class itself
27+
def test_start_measurement_logic(self, mock_figure_class, MockBackend):
2828
"""
2929
Tests the core logic of the 'Start' button click.
3030
Verifies that parameters are read from the UI and passed to the backend correctly.
@@ -33,7 +33,7 @@ def test_start_measurement_logic(self, mock_fig_subplots, MockBackend):
3333
# Configure the mock for subplots to return two mock axes
3434
mock_ax_vi = MagicMock()
3535
mock_ax_ri = MagicMock()
36-
mock_fig_subplots.return_value = [mock_ax_vi, mock_ax_ri]
36+
mock_figure_class.return_value.subplots.return_value = [mock_ax_vi, mock_ax_ri]
3737

3838
# Instantiate the GUI. This also creates all the tk widgets.
3939
app = MeasurementAppGUI(self.root)

tests/test_iv_k2400_loop_backend.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import unittest
22
from unittest.mock import patch, MagicMock
3-
import pyvisa
43

54

65
# Now we can import the module to be tested
@@ -10,7 +9,7 @@
109
class TestIVK2400LoopBackend(unittest.TestCase):
1110

1211
@patch('builtins.input', side_effect=['10', '2', 'test_output'])
13-
@patch('Keithley_2400.Backends.IV_K2400_Loop_Backend_v10.Keithley2400') # Patch Keithley2400 directly
12+
@patch('pymeasure.instruments.keithley.Keithley2400') # Patch Keithley2400 from pymeasure
1413
@patch('matplotlib.pyplot.show')
1514
@patch('pandas.DataFrame.to_csv')
1615
def test_main_full_run(self, mock_to_csv, mock_plt_show, mock_keithley_class, mock_input):
@@ -32,16 +31,6 @@ def voltage_side_effect():
3231
# so we will use a side effect to track it
3332
latest_current = [0]
3433

35-
# Simulate the voltage measurement
36-
# Let's return a voltage that is proportional to the current
37-
def voltage_side_effect():
38-
# A simple linear relationship for testing
39-
return mock_keithley_instance.source_current * 10
40-
41-
# We can't directly access the source_current from ramp_to_current,
42-
# so we will use a side effect to track it
43-
latest_current = [0]
44-
4534
def ramp_side_effect(current):
4635
latest_current[0] = current
4736
# Also update the mock's internal state

tests/test_iv_k6517b_simple_backend.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import unittest
22
from unittest.mock import patch, MagicMock, mock_open
33
import numpy as np
4-
# import pyvisa # Removed pyvisa import as it's not needed with direct class patching
54

65
# Import the main function from the script we want to test
76
from Keithley_6517B.High_Resistance.Backends.IV_K6517B_Simple_Backend_v10 import main as iv_simple_main
87

98
class TestIVK6517BSimpleBackend(unittest.TestCase):
109
@patch('time.sleep', MagicMock())
1110
@patch('builtins.input', side_effect=['-10', '10', '5', '0.1', 'test_iv_simple.csv'])
12-
@patch('Keithley_6517B.High_Resistance.Backends.IV_K6517B_Simple_Backend_v10.Keithley6517B') # Re-patch Keithley6517B directly
11+
@patch('pymeasure.instruments.keithley.Keithley6517B') # Patch Keithley6517B from pymeasure
1312
@patch('builtins.open', new_callable=mock_open)
1413
@patch('matplotlib.pyplot.show')
1514
def test_full_run(self, mock_show, mock_file, mock_keithley_class, mock_input):

tests/test_t_control_l350_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_get_user_parameters(self, mock_input):
9494
@patch('tkinter.filedialog.asksaveasfilename', return_value='test.csv')
9595
@patch('builtins.input', side_effect=['10', '20', '5', '30'])
9696
@patch('Lakeshore_350_340.Backends.T_Control_L350_Simple_Backend_v10.Lakeshore350')
97-
@patch('matplotlib.pyplot.subplots') # NEW PATCH
97+
@patch('Lakeshore_350_340.Backends.T_Control_L350_Simple_Backend_v10.plt.subplots') # Patch plt.subplots in the backend module
9898
@patch('matplotlib.pyplot.show')
9999
@patch('builtins.open', new_callable=mock_open)
100100
@patch('time.sleep', MagicMock())

0 commit comments

Comments
 (0)