Skip to content

Commit 150489c

Browse files
tests fixes
1 parent e06b0c0 commit 150489c

6 files changed

Lines changed: 812 additions & 1102 deletions

tests/test_deep_simulation.py

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,44 @@
55
import signal
66
from unittest.mock import MagicMock, patch, mock_open
77

8-
# -------------------------------------------------------------------------
9-
# 1. GLOBAL MOCKS
10-
# -------------------------------------------------------------------------
11-
# Mock GUI elements
12-
sys.modules['tkinter'] = MagicMock()
13-
sys.modules['tkinter.ttk'] = MagicMock()
14-
sys.modules['tkinter.messagebox'] = MagicMock()
15-
sys.modules['tkinter.filedialog'] = MagicMock()
16-
17-
# Mock Multiprocessing to prevent Queue.get() hangs
18-
mock_mp = MagicMock()
19-
sys.modules['multiprocessing'] = mock_mp
20-
sys.modules['multiprocessing.queues'] = MagicMock()
21-
22-
# Mock Matplotlib
23-
mock_plt = MagicMock()
24-
mock_fig = MagicMock()
25-
mock_ax = MagicMock()
26-
mock_line = MagicMock()
27-
mock_ax.plot.return_value = [mock_line]
28-
mock_plt.subplots.return_value = (mock_fig, mock_ax)
29-
sys.modules['matplotlib'] = MagicMock()
30-
sys.modules['matplotlib.pyplot'] = mock_plt
31-
sys.modules['matplotlib.figure'] = MagicMock()
32-
sys.modules['matplotlib.backends'] = MagicMock()
33-
sys.modules['matplotlib.backends.backend_tkagg'] = MagicMock()
34-
35-
368
class TestDeepSimulation(unittest.TestCase):
379

3810
def setUp(self):
11+
# Mock GUI elements
12+
self.tkinter_patch = patch.dict('sys.modules', {
13+
'tkinter': MagicMock(),
14+
'tkinter.ttk': MagicMock(),
15+
'tkinter.messagebox': MagicMock(),
16+
'tkinter.filedialog': MagicMock(),
17+
})
18+
self.tkinter_patch.start()
19+
self.addCleanup(self.tkinter_patch.stop)
20+
21+
# Mock Multiprocessing to prevent Queue.get() hangs
22+
self.mp_patch = patch.dict('sys.modules', {
23+
'multiprocessing': MagicMock(),
24+
'multiprocessing.queues': MagicMock(),
25+
})
26+
self.mp_patch.start()
27+
self.addCleanup(self.mp_patch.stop)
28+
29+
# Mock Matplotlib
30+
mock_plt = MagicMock()
31+
mock_fig = MagicMock()
32+
mock_ax = MagicMock()
33+
mock_line = MagicMock()
34+
mock_ax.plot.return_value = [mock_line]
35+
mock_plt.subplots.return_value = (mock_fig, mock_ax)
36+
self.matplotlib_patch = patch.dict('sys.modules', {
37+
'matplotlib': MagicMock(),
38+
'matplotlib.pyplot': mock_plt,
39+
'matplotlib.figure': MagicMock(),
40+
'matplotlib.backends': MagicMock(),
41+
'matplotlib.backends.backend_tkagg': MagicMock(),
42+
})
43+
self.matplotlib_patch.start()
44+
self.addCleanup(self.matplotlib_patch.stop)
45+
3946
self.root_dir = os.path.abspath(
4047
os.path.join(os.path.dirname(__file__), '..'))
4148
if self.root_dir not in sys.path:

tests/test_fixes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
class TestFixes(unittest.TestCase):
55

6-
@patch('time.sleep', MagicMock()) # Add mock for time.sleep to isolate the test
7-
@patch('builtins.input', side_effect=['10', '2', 'test_output'])
6+
@patch('Keithley_2400.Backends.IV_K2400_Loop_Backend_v10.sleep', MagicMock()) # Add mock for time.sleep to isolate the test
7+
@patch('builtins.input', side_effect=['10', '2', 'test_output'])
88
@patch('Keithley_2400.Backends.IV_K2400_Loop_Backend_v10.Keithley2400')
99
@patch('matplotlib.pyplot.show')
1010
@patch('pandas.DataFrame.to_csv')
@@ -23,7 +23,7 @@ def test_iv_k2400_fix(self, mock_to_csv, mock_plt_show, mock_keithley_class, moc
2323
@patch('Lakeshore_350_340.Backends.T_Control_L350_Simple_Backend_v10.Lakeshore350')
2424
@patch('matplotlib.pyplot.show')
2525
@patch('builtins.open', new_callable=mock_open)
26-
@patch('time.sleep', MagicMock())
26+
@patch('Lakeshore_350_340.Backends.T_Control_L350_Simple_Backend_v10.sleep', MagicMock())
2727
@patch('time.time', side_effect=[1000, 1002, 1004, 1006, 1008, 1010])
2828
def test_t_control_l350_fix(self, mock_time, mock_open_file,
2929
mock_plt_show, mock_ls_class, mock_input, mock_file_dialog, mock_tk):

tests/test_iv_k2400_loop_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class TestIVK2400LoopBackend(unittest.TestCase):
1010

1111
@patch('builtins.input', side_effect=['10', '2', 'test_output'])
12-
@patch('pymeasure.instruments.keithley.Keithley2400')
12+
@patch('Keithley_2400.Backends.IV_K2400_Loop_Backend_v10.Keithley2400')
1313
@patch('matplotlib.pyplot.show')
1414
@patch('pandas.DataFrame.to_csv')
1515
def test_main_full_run(self, mock_to_csv, mock_plt_show, mock_keithley_class, mock_input):

tests/test_iv_k6517b_simple_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class TestIVK6517BSimpleBackend(unittest.TestCase):
99
@patch('time.sleep', MagicMock())
1010
@patch('builtins.input', side_effect=['-10', '10', '5', '0.1', 'test_iv_simple.csv'])
11-
@patch('pymeasure.instruments.keithley.Keithley6517B')
11+
@patch('Keithley_6517B.High_Resistance.Backends.IV_K6517B_Simple_Backend_v10.Keithley6517B')
1212
@patch('builtins.open', new_callable=mock_open)
1313
@patch('matplotlib.pyplot.show')
1414
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
@@ -116,7 +116,7 @@ def test_main_runs_and_completes(self, mock_time, mock_open_file,
116116

117117
# --- ASSERTIONS ---
118118
# Check initialization
119-
mock_ls_class.assert_called_once_with("GPIB0::12::INSTR", adapter_args={"py_library": "@sim"})
119+
mock_ls_class.assert_called_once_with("GPIB0::13::INSTR")
120120
mock_controller.reset_and_clear.assert_called_once()
121121
mock_controller.setup_heater.assert_called_once()
122122

0 commit comments

Comments
 (0)