diff --git a/hyo2/ssm2/__init__.py b/hyo2/ssm2/__init__.py index 7a3adab..928e1bb 100644 --- a/hyo2/ssm2/__init__.py +++ b/hyo2/ssm2/__init__.py @@ -12,7 +12,7 @@ logger.addHandler(logging.NullHandler()) name = "Sound Speed" -__version__ = '2024.2.1' +__version__ = '2024.2.2' __copyright__ = 'Copyright 2024 University of New Hampshire, Center for Coastal and Ocean Mapping' pkg_info = PkgInfo( diff --git a/hyo2/ssm2/app/gui/soundspeedmanager/mainwin.py b/hyo2/ssm2/app/gui/soundspeedmanager/mainwin.py index 73d5e82..d82c7fb 100644 --- a/hyo2/ssm2/app/gui/soundspeedmanager/mainwin.py +++ b/hyo2/ssm2/app/gui/soundspeedmanager/mainwin.py @@ -208,6 +208,9 @@ def __init__(self): self.data_cleared() self.tabs.blockSignals(False) + # using in app tests + self.skip_do_you_really_quit = False + logger.info("* > APP: initialized!") def on_change(self, i): @@ -830,17 +833,24 @@ def _do_you_really_want(self, title="Quit", text="quit"): def closeEvent(self, event): """ actions to be done before close the app """ + if self.skip_do_you_really_quit: + self._close(event=event) + return + reply = self._do_you_really_want("Quit", "quit %s" % app_info.app_name) # reply = QtWidgets.QMessageBox.Yes if reply == QtWidgets.QMessageBox.StandardButton.Yes: - event.accept() - self.lib.close() - if self.has_sdm_support: - self.tab_monitor.stop_plotting() - super(MainWin, self).closeEvent(event) + self._close(event) else: event.ignore() + def _close(self, event): + event.accept() + self.lib.close() + if self.has_sdm_support: + self.tab_monitor.stop_plotting() + super(MainWin, self).closeEvent(event) + # -------------------------- development-only -------------------------- def do(self): diff --git a/tests/soundspeedmanager/test_main_win.py b/tests/soundspeedmanager/test_main_win.py new file mode 100644 index 0000000..12c0e10 --- /dev/null +++ b/tests/soundspeedmanager/test_main_win.py @@ -0,0 +1,36 @@ +import unittest + +from PySide6.QtWidgets import QApplication +from PySide6.QtTest import QTest +from PySide6.QtCore import Qt + +from hyo2.ssm2.app.gui.soundspeedmanager.mainwin import MainWin + + +class TestSoundSpeedManagerMainWin(unittest.TestCase): + + def setUp(self): + self.app = QApplication.instance() or QApplication([]) + self.window = MainWin() + self.window.skip_do_you_really_quit = True + self.window.show() + + def test_menu_file(self): + + # Simulate clicking the "File" menu + QTest.mouseClick(self.window.menu, Qt.LeftButton, + pos=self.window.menu.actionGeometry(self.window.menu.actions()[0]).center()) + + # Simulate clicking the "Import Input Data" menu + QTest.mouseClick(self.window.menu, Qt.LeftButton, + pos=self.window.file_menu.actionGeometry(self.window.file_menu.actions()[0]).center()) + + def tearDown(self): + self.window.close() + self.app.quit() + + +def suite(): + s = unittest.TestSuite() + s.addTests(unittest.TestLoader().loadTestsFromTestCase(TestSoundSpeedManagerMainWin)) + return s