11import unittest
2- from unittest .mock import patch , MagicMock
3- import sys
4- import os
2+ from unittest .mock import patch
53
64# -----------------------------------------------------------------------------
75# MOCK HELPER CLASSES for GUI Testing
@@ -21,6 +19,7 @@ def invoke(self):
2119 if self .command :
2220 self .command ()
2321
22+
2423class MockPicaLauncher :
2524 """
2625 Simulates the PICA_v6.py launcher class structure.
@@ -30,7 +29,6 @@ def __init__(self):
3029 # Attach MockTkWidget to simulate the 'command' binding for the button
3130 self .button_iv_sweep = MockTkWidget (command = self .open_iv_sweep )
3231 self .button_temp_control = MockTkWidget (command = self .open_temp_control )
33-
3432 # Internal state tracker to confirm methods are called
3533 self .open_gui_calls = {'iv_sweep' : 0 , 'temp_control' : 0 }
3634
@@ -57,40 +55,34 @@ class TestPicaLauncher(unittest.TestCase):
5755 def test_iv_sweep_button_click_calls_function (self , mock_open_iv_sweep ):
5856 """Tests that clicking the IV Sweep button calls its launch function once."""
5957 launcher = MockPicaLauncher ()
60-
6158 # Simulate button click
6259 launcher .button_iv_sweep .invoke ()
6360
6461 # Assert the mocked function was called
6562 mock_open_iv_sweep .assert_called_once ()
66-
6763 # Assert the internal counter was incremented
6864 self .assertEqual (launcher .open_gui_calls ['iv_sweep' ], 1 )
6965
7066 @patch ('test_pica_launcher.MockPicaLauncher.open_temp_control' )
7167 def test_temp_control_button_click_calls_function (self , mock_open_temp_control ):
7268 """Tests that clicking the Temp Control button calls its launch function once."""
7369 launcher = MockPicaLauncher ()
74-
7570 # Simulate button click
7671 launcher .button_temp_control .invoke ()
7772
7873 # Assert the mocked function was called
7974 mock_open_temp_control .assert_called_once ()
80-
8175 # Assert the internal counter was incremented
8276 self .assertEqual (launcher .open_gui_calls ['temp_control' ], 1 )
8377
8478 def test_multiple_clicks (self ):
8579 """Tests that multiple clicks correctly register multiple calls."""
8680 launcher = MockPicaLauncher ()
87-
8881 # Simulate multiple clicks
8982 for _ in range (3 ):
9083 launcher .button_iv_sweep .invoke ()
91-
9284 self .assertEqual (launcher .open_gui_calls ['iv_sweep' ], 3 )
93- self .assertEqual (launcher .open_gui_calls ['temp_control' ], 0 ) # Ensure others are not called
85+ self .assertEqual (launcher .open_gui_calls ['temp_control' ], 0 ) # Ensure others are not called
9486
9587
9688if __name__ == '__main__' :
0 commit comments