Skip to content

Commit 906d1b9

Browse files
tests corrected
1 parent 680d601 commit 906d1b9

3 files changed

Lines changed: 1109 additions & 633 deletions

File tree

tests/test_deep_simulation.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def side_effect(*args, **kwargs):
105105

106106
def test_01_k2400_iv_backend(self):
107107
# GLOBAL PATCH for sleep is critical here
108-
with patch('pymeasure.instruments.keithley.Keithley2400') as MockInst, \
108+
with patch('pymeasure.instruments.keithley.Keithley2400', autospec=True) as MockInst, \
109109
patch('time.sleep', side_effect=self.get_circuit_breaker(5)):
110110

111111
spy = MockInst.return_value
@@ -123,10 +123,15 @@ def test_02_lakeshore_backend(self):
123123
spy.query.side_effect = [
124124
"LSCI,MODEL350,0,0"] + ["10.0", "300.0"] * 20
125125

126+
# Create local mocks for matplotlib to avoid issues with global mocks
127+
mock_fig, mock_ax = MagicMock(), MagicMock()
128+
mock_ax.plot.return_value = [MagicMock()]
129+
126130
with patch('builtins.input', side_effect=['10', '300', '10', '350']), \
127131
patch('builtins.open', mock_open()), \
128132
patch('tkinter.filedialog.asksaveasfilename', return_value="test.csv"), \
129-
patch('matplotlib.pyplot.show'):
133+
patch('matplotlib.pyplot.show'), \
134+
patch('matplotlib.pyplot.subplots', return_value=(mock_fig, mock_ax)):
130135
self.run_module_safely(
131136
"Lakeshore_350_340.Backends.T_Control_L350_Simple_Backend_v10")
132137

@@ -193,9 +198,9 @@ def test_08_combined_2400_2182(self):
193198
patch('time.sleep', side_effect=self.get_circuit_breaker(10)):
194199

195200
rm = MockRM.return_value
196-
# Ensure side_effect doesn't run out if script asks for many
197-
# resources
198-
rm.open_resource.return_value = MagicMock()
201+
k2182_spy = MagicMock()
202+
k2182_spy.assert_trigger = MagicMock()
203+
rm.open_resource.return_value = k2182_spy
199204

200205
# Add extra inputs just in case the script asks for more than
201206
# expected

tests/test_full_stack_simulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def run_module_safely(self, module_name):
6868
def test_keithley2400_iv_protocol(self):
6969
print("\n[SIMULATION] Testing Keithley 2400 I-V Protocol...")
7070

71-
with patch('pymeasure.instruments.keithley.Keithley2400') as MockK2400:
71+
with patch('pymeasure.instruments.keithley.Keithley2400', autospec=True) as MockK2400:
7272
spy_inst = MockK2400.return_value
7373
spy_inst.voltage = 1.23
7474

0 commit comments

Comments
 (0)