Skip to content

Commit

Permalink
added gui test
Browse files Browse the repository at this point in the history
  • Loading branch information
giumas committed Oct 21, 2024
1 parent b684450 commit 71c8ca3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
2 changes: 1 addition & 1 deletion hyo2/ssm2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 15 additions & 5 deletions hyo2/ssm2/app/gui/soundspeedmanager/mainwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
36 changes: 36 additions & 0 deletions tests/soundspeedmanager/test_main_win.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 71c8ca3

Please sign in to comment.