Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail tests if there are any widgets left open #2150

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions mslib/msui/mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def __init__(self, parent=None, data_dir=None):
self.ui.serverOptionsCb.currentIndexChanged.connect(self.server_options_handler)

# set up user menu and add to toolbutton
self.user_menu = QtWidgets.QMenu()
self.user_menu = QtWidgets.QMenu(self.ui)
self.profile_action = self.user_menu.addAction("Profile", self.open_profile_window)
self.user_menu.addSeparator()
self.logout_action = self.user_menu.addAction("Logout", self.logout)
Expand Down Expand Up @@ -790,7 +790,7 @@ def open_profile_window(self):
def on_context_menu(point):
self.gravatar_menu.exec_(self.profile_dialog.gravatarLabel.mapToGlobal(point))

self.prof_diag = QtWidgets.QDialog()
self.prof_diag = QtWidgets.QDialog(self.ui)
self.profile_dialog = ui_profile.Ui_ProfileWindow()
self.profile_dialog.setupUi(self.prof_diag)
self.profile_dialog.buttonBox.accepted.connect(lambda: self.prof_diag.close())
Expand All @@ -800,7 +800,7 @@ def on_context_menu(point):
self.profile_dialog.deleteAccountBtn.clicked.connect(self.delete_account)

# add context menu for right click on image
self.gravatar_menu = QtWidgets.QMenu()
self.gravatar_menu = QtWidgets.QMenu(self.ui)
self.gravatar_menu.addAction('Fetch Gravatar', lambda: self.fetch_gravatar(refresh=True))
self.gravatar_menu.addAction('Remove Gravatar', lambda: self.remove_gravatar())
self.profile_dialog.gravatarLabel.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
Expand All @@ -812,7 +812,7 @@ def on_context_menu(point):
def delete_account(self):
# ToDo rename to delete_own_account
if verify_user_token(self.mscolab_server_url, self.token):
w = QtWidgets.QWidget()
w = QtWidgets.QWidget(self.ui)
qm = QtWidgets.QMessageBox
reply = qm.question(w, self.tr('Continue?'),
self.tr("You're about to delete your account. You cannot undo this operation!"),
Expand Down Expand Up @@ -870,7 +870,7 @@ def browse():
self.add_proj_dialog.f_content = file_content
self.add_proj_dialog.selectedFile.setText(file_name)

self.proj_diag = QtWidgets.QDialog()
self.proj_diag = QtWidgets.QDialog(self.ui)
self.add_proj_dialog = add_operation_ui.Ui_addOperationDialog()
self.add_proj_dialog.setupUi(self.proj_diag)
self.add_proj_dialog.f_content = None
Expand All @@ -897,21 +897,21 @@ def add_operation(self):
description = self.add_proj_dialog.description.toPlainText()
category = self.add_proj_dialog.category.text()
if not path:
self.error_dialog = QtWidgets.QErrorMessage()
self.error_dialog = QtWidgets.QErrorMessage(self.ui)
self.error_dialog.showMessage('Path can\'t be empty')
return
elif not description:
self.error_dialog = QtWidgets.QErrorMessage()
self.error_dialog = QtWidgets.QErrorMessage(self.ui)
self.error_dialog.showMessage('Description can\'t be empty')
return
# same regex as for path validation
elif not re.match("^[a-zA-Z0-9_-]*$", category):
self.error_dialog = QtWidgets.QErrorMessage()
self.error_dialog = QtWidgets.QErrorMessage(self.ui)
self.error_dialog.showMessage('Category can\'t contain spaces or special characters')
return
# regex checks if the whole path from beginning to end only contains alphanumerical characters or _ and -
elif not re.match("^[a-zA-Z0-9_-]*$", path):
self.error_dialog = QtWidgets.QErrorMessage()
self.error_dialog = QtWidgets.QErrorMessage(self.ui)
self.error_dialog.showMessage('Path can\'t contain spaces or special characters')
return

Expand Down Expand Up @@ -943,7 +943,7 @@ def add_operation(self):
self.conn.handle_new_operation(op_id)
self.signal_operation_added.emit(op_id, path)
else:
self.error_dialog = QtWidgets.QErrorMessage()
self.error_dialog = QtWidgets.QErrorMessage(self.ui)
self.error_dialog.showMessage('The path already exists')

def get_recent_op_id(self):
Expand Down Expand Up @@ -1134,7 +1134,7 @@ def handle_delete_operation(self):

def handle_leave_operation(self):
logging.debug("handle_leave_operation")
w = QtWidgets.QWidget()
w = QtWidgets.QWidget(self.ui)
qm = QtWidgets.QMessageBox
reply = qm.question(w, self.tr('Mission Support System'),
self.tr("Do you want to leave this operation?"),
Expand Down
2 changes: 1 addition & 1 deletion mslib/msui/mscolab_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def __init__(self, message, chat_window):
else:
self.attachment_path = message["text"]
self.context_menu = QtWidgets.QMenu(self)
self.textArea = QtWidgets.QWidget()
self.textArea = QtWidgets.QWidget(self)
self.replyArea = None
self.replyScroll = QtWidgets.QScrollArea()
self.setup_message_box()
Expand Down
12 changes: 8 additions & 4 deletions mslib/msui/msui_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ def __init__(self, mscolab_data_dir=None, tutorial_mode=False, *args):
except (ImportError, AttributeError) as error:
logging.debug("AttributeError, ImportError Exception %s", error)

self.force_close = False
self.config_editor = None
self.local_active = True
self.new_flight_track_counter = 0
Expand Down Expand Up @@ -1069,10 +1070,13 @@ def closeEvent(self, event):
Overloads QtGui.QMainWindow.closeEvent(). This method is called if
Qt receives a window close request for our application window.
"""
ret = QtWidgets.QMessageBox.warning(
self, self.tr("Mission Support System"),
self.tr("Do you want to close the Mission Support System application?"),
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)
if self.force_close:
ret = QtWidgets.QMessageBox.Yes
else:
ret = QtWidgets.QMessageBox.warning(
self, self.tr("Mission Support System"),
self.tr("Do you want to close the Mission Support System application?"),
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No)

if ret == QtWidgets.QMessageBox.Yes:
if self.mscolab.help_dialog is not None:
Expand Down
4 changes: 2 additions & 2 deletions mslib/msui/multiple_flightpath_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def select_color(self):
self.list_flighttrack.currentItem().checkState() == QtCore.Qt.Checked):
wp_model = self.list_flighttrack.currentItem().flighttrack_model
if wp_model == self.active_flight_track:
self.error_dialog = QtWidgets.QErrorMessage()
self.error_dialog = QtWidgets.QErrorMessage(self)
self.error_dialog.showMessage('Use "options" to change color of an activated flighttrack.')
else:
color = QtWidgets.QColorDialog.getColor()
Expand Down Expand Up @@ -735,7 +735,7 @@ def select_color(self):
self.list_operation_track.currentItem().checkState() == QtCore.Qt.Checked):
op_id = self.list_operation_track.currentItem().op_id
if self.list_operation_track.currentItem().op_id == self.active_op_id:
self.error_dialog = QtWidgets.QErrorMessage()
self.error_dialog = QtWidgets.QErrorMessage(self)
self.error_dialog.showMessage('Use "options" to change color of an activated operation.')
else:
color = QtWidgets.QColorDialog.getColor()
Expand Down
1 change: 0 additions & 1 deletion mslib/msui/qt5/ui_kmloverlay_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,3 @@ def retranslateUi(self, KMLOverlayDockWidget):
ui.setupUi(KMLOverlayDockWidget)
KMLOverlayDockWidget.show()
sys.exit(app.exec_())

8 changes: 4 additions & 4 deletions mslib/msui/qt5/ui_mscolab_connect_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def setupUi(self, MSColabConnectDialog):
self.gridLayout_4.addWidget(self.line, 1, 0, 1, 1)
self.stackedWidget = QtWidgets.QStackedWidget(MSColabConnectDialog)
self.stackedWidget.setObjectName("stackedWidget")
self.loginPage = QtWidgets.QWidget()
self.loginPage = QtWidgets.QWidget(MSColabConnectDialog)
self.loginPage.setObjectName("loginPage")
self.gridLayout_3 = QtWidgets.QGridLayout(self.loginPage)
self.gridLayout_3.setContentsMargins(100, 0, 100, 0)
Expand Down Expand Up @@ -74,7 +74,7 @@ def setupUi(self, MSColabConnectDialog):
self.loginPasswordLe.setObjectName("loginPasswordLe")
self.gridLayout_3.addWidget(self.loginPasswordLe, 2, 0, 1, 2)
self.stackedWidget.addWidget(self.loginPage)
self.newuserPage = QtWidgets.QWidget()
self.newuserPage = QtWidgets.QWidget(MSColabConnectDialog)
self.newuserPage.setObjectName("newuserPage")
self.gridLayout_2 = QtWidgets.QGridLayout(self.newuserPage)
self.gridLayout_2.setContentsMargins(50, 0, 50, 0)
Expand Down Expand Up @@ -118,7 +118,7 @@ def setupUi(self, MSColabConnectDialog):
self.newConfirmPasswordLe.setObjectName("newConfirmPasswordLe")
self.gridLayout_2.addWidget(self.newConfirmPasswordLe, 4, 1, 1, 1)
self.stackedWidget.addWidget(self.newuserPage)
self.httpAuthPage = QtWidgets.QWidget()
self.httpAuthPage = QtWidgets.QWidget(MSColabConnectDialog)
self.httpAuthPage.setObjectName("httpAuthPage")
self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.httpAuthPage)
self.verticalLayout_4.setContentsMargins(0, 0, 0, 0)
Expand Down Expand Up @@ -147,7 +147,7 @@ def setupUi(self, MSColabConnectDialog):
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_4.addItem(spacerItem)
self.stackedWidget.addWidget(self.httpAuthPage)
self.idpAuthPage = QtWidgets.QWidget()
self.idpAuthPage = QtWidgets.QWidget(MSColabConnectDialog)
self.idpAuthPage.setEnabled(True)
self.idpAuthPage.setObjectName("idpAuthPage")
self.layoutWidget = QtWidgets.QWidget(self.idpAuthPage)
Expand Down
12 changes: 6 additions & 6 deletions mslib/msui/qt5/ui_mscolab_help_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setupUi(self, mscolabHelpDialog):
self.tabWidget = QtWidgets.QTabWidget(mscolabHelpDialog)
self.tabWidget.setTabShape(QtWidgets.QTabWidget.Rounded)
self.tabWidget.setObjectName("tabWidget")
self.connectingTab = QtWidgets.QWidget()
self.connectingTab = QtWidgets.QWidget(mscolabHelpDialog)
self.connectingTab.setObjectName("connectingTab")
self.gridLayout_4 = QtWidgets.QGridLayout(self.connectingTab)
self.gridLayout_4.setContentsMargins(0, 0, 0, 0)
Expand Down Expand Up @@ -91,7 +91,7 @@ def setupUi(self, mscolabHelpDialog):
self.verticalLayout_3.setStretch(3, 1)
self.gridLayout_4.addLayout(self.verticalLayout_3, 0, 0, 1, 1)
self.tabWidget.addTab(self.connectingTab, "")
self.createOperationTab = QtWidgets.QWidget()
self.createOperationTab = QtWidgets.QWidget(mscolabHelpDialog)
self.createOperationTab.setObjectName("createOperationTab")
self.gridLayout_3 = QtWidgets.QGridLayout(self.createOperationTab)
self.gridLayout_3.setContentsMargins(0, 0, 0, 0)
Expand Down Expand Up @@ -119,7 +119,7 @@ def setupUi(self, mscolabHelpDialog):
self.verticalLayout_4.addLayout(self.horizontalLayout_11)
self.gridLayout_3.addLayout(self.verticalLayout_4, 0, 0, 1, 1)
self.tabWidget.addTab(self.createOperationTab, "")
self.adminTab = QtWidgets.QWidget()
self.adminTab = QtWidgets.QWidget(mscolabHelpDialog)
self.adminTab.setObjectName("adminTab")
self.gridLayout_5 = QtWidgets.QGridLayout(self.adminTab)
self.gridLayout_5.setContentsMargins(0, 0, 0, 0)
Expand Down Expand Up @@ -149,7 +149,7 @@ def setupUi(self, mscolabHelpDialog):
self.verticalLayout_5.addLayout(self.horizontalLayout_12)
self.gridLayout_5.addLayout(self.verticalLayout_5, 0, 0, 1, 1)
self.tabWidget.addTab(self.adminTab, "")
self.chatTab = QtWidgets.QWidget()
self.chatTab = QtWidgets.QWidget(mscolabHelpDialog)
self.chatTab.setObjectName("chatTab")
self.gridLayout_7 = QtWidgets.QGridLayout(self.chatTab)
self.gridLayout_7.setContentsMargins(0, 0, 0, 0)
Expand Down Expand Up @@ -179,7 +179,7 @@ def setupUi(self, mscolabHelpDialog):
self.verticalLayout_6.addLayout(self.horizontalLayout_13)
self.gridLayout_7.addLayout(self.verticalLayout_6, 0, 0, 1, 1)
self.tabWidget.addTab(self.chatTab, "")
self.versionTab = QtWidgets.QWidget()
self.versionTab = QtWidgets.QWidget(mscolabHelpDialog)
self.versionTab.setObjectName("versionTab")
self.gridLayout_9 = QtWidgets.QGridLayout(self.versionTab)
self.gridLayout_9.setContentsMargins(0, 0, 0, 0)
Expand Down Expand Up @@ -209,7 +209,7 @@ def setupUi(self, mscolabHelpDialog):
self.verticalLayout_7.addLayout(self.horizontalLayout_14)
self.gridLayout_9.addLayout(self.verticalLayout_7, 0, 0, 1, 1)
self.tabWidget.addTab(self.versionTab, "")
self.operationWorkTab = QtWidgets.QWidget()
self.operationWorkTab = QtWidgets.QWidget(mscolabHelpDialog)
self.operationWorkTab.setObjectName("operationWorkTab")
self.gridLayout_8 = QtWidgets.QGridLayout(self.operationWorkTab)
self.gridLayout_8.setContentsMargins(0, 0, 0, 0)
Expand Down
4 changes: 2 additions & 2 deletions mslib/msui/wms_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,13 @@ def __init__(self, parent=None, default_WMS=None, wms_cache=None, view=None):

# Progress dialog to inform the user about image ongoing retrievals.
self.pdlg = QtWidgets.QProgressDialog(
"retrieving image...", "Cancel", 0, 10, parent=self.parent())
"retrieving image...", "Cancel", 0, 10, parent=self)
self.pdlg.close()

# Progress dialog to inform the user about ongoing capability requests.
self.capabilities_worker = Worker(None)
self.cpdlg = QtWidgets.QProgressDialog(
"retrieving wms capabilities...", "Cancel", 0, 10, parent=self.multilayers)
"retrieving wms capabilities...", "Cancel", 0, 10, parent=self)
self.cpdlg.canceled.connect(self.stop_capabilities_retrieval)
self.cpdlg.close()

Expand Down
2 changes: 1 addition & 1 deletion mslib/support/qt_json_view/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, parent=None):

def _menu(self, position):
"""Show the actions of the DataType (if any)."""
menu = QtWidgets.QMenu()
menu = QtWidgets.QMenu(self)
index = self.indexAt(position)
data = index.data(TypeRole)
if data is None:
Expand Down
1 change: 0 additions & 1 deletion tests/_test_msui/test_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def setup(self, qtbot):
yield
if os.path.exists(self.save_file_name):
os.remove(self.save_file_name)
self.window.hide()

@mock.patch("mslib.msui.editor.get_open_filename", return_value=sample_file)
def test_file_open(self, mockfile):
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_msui/test_kmloverlay_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def setup(self, qtbot):
self.view.map.gcpoints_path = mock.Mock(side_effect=lambda x, y: (x, y))

self.window = kd.KMLOverlayControlWidget(view=self.view)
qtbot.add_widget(self.window)
self.window.show()
QtTest.QTest.qWaitForWindowExposed(self.window)
# start load test
self.window.select_all()
self.window.remove_file()
yield
self.window.close()
if os.path.exists(save_kml):
os.remove(save_kml)

Expand Down
9 changes: 4 additions & 5 deletions tests/_test_msui/test_linearview.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
from mslib.msui import flighttrack as ft
import mslib.msui.linearview as tv
from mslib.msui.mpl_qtwidget import _DEFAULT_SETTINGS_LINEARVIEW
from tests.utils import set_force_close


class Test_MSS_LV_Options_Dialog:
@pytest.fixture(autouse=True)
def setup(self, qtbot):
self.window = tv.MSUI_LV_Options_Dialog(settings=_DEFAULT_SETTINGS_LINEARVIEW)
qtbot.add_widget(self.window)
self.window.show()
QtTest.QTest.qWaitForWindowExposed(self.window)
yield
self.window.hide()

def test_show(self):
pass
Expand All @@ -62,10 +62,9 @@ def setup(self, qtbot):
0, rows=len(initial_waypoints), waypoints=initial_waypoints)

self.window = tv.MSUILinearViewWindow(model=waypoints_model)
qtbot.add_widget(self.window, before_close_func=set_force_close)
self.window.show()
QtTest.QTest.qWaitForWindowExposed(self.window)
yield
self.window.hide()

def test_open_wms(self):
self.window.cbTools.currentIndexChanged.emit(1)
Expand Down Expand Up @@ -97,13 +96,13 @@ def setup(self, qtbot, mswms_server):
waypoints_model.insertRows(
0, rows=len(initial_waypoints), waypoints=initial_waypoints)
self.window = tv.MSUILinearViewWindow(model=waypoints_model)
qtbot.add_widget(self.window, before_close_func=set_force_close)
self.window.show()
QtTest.QTest.qWaitForWindowExposed(self.window)
self.window.cbTools.currentIndexChanged.emit(1)
self.wms_control = self.window.docks[0].widget()
self.wms_control.multilayers.cbWMS_URL.setEditText("")
yield
self.window.hide()
shutil.rmtree(self.tempdir)

def query_server(self, qtbot, url):
Expand Down
1 change: 1 addition & 0 deletions tests/_test_msui/test_mpl_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def setup(self, qtbot):
kwargs = {'resolution': 'l', 'area_thresh': 1000.0, 'ax': plt.gca(), 'llcrnrlon': -15.0, 'llcrnrlat': 35.0,
'urcrnrlon': 30.0, 'urcrnrlat': 65.0, 'epsg': '4326'}
self.map = MapCanvas(**kwargs)
qtbot.add_widget(plt.get_current_fig_manager().window)

def test_no_coastsegs(self):
"""
Expand Down
13 changes: 3 additions & 10 deletions tests/_test_msui/test_mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from mslib.msui.flighttrack import WaypointsTableModel
from PyQt5 import QtCore, QtTest, QtWidgets
from mslib.utils.config import read_config_file, config_loader, modify_config_file
from tests.utils import create_msui_settings_file, ExceptionMock
from tests.utils import create_msui_settings_file, ExceptionMock, set_force_close
from mslib.msui import msui
from mslib.msui import mscolab
from mslib.mscolab.seed import add_user, get_user, add_operation, add_user_to_operation
Expand All @@ -57,6 +57,7 @@ def setup(self, qtbot, mscolab_server):
self.user = get_user(self.userdata[0])

self.main_window = msui.MSUIMainWindow(mscolab_data_dir=mscolab_settings.MSCOLAB_DATA_DIR)
qtbot.add_widget(self.main_window, before_close_func=set_force_close)
self.main_window.create_new_flight_track()
self.main_window.show()
self.window = mscolab.MSColab_ConnectDialog(parent=self.main_window, mscolab=self.main_window.mscolab)
Expand All @@ -69,8 +70,6 @@ def setup(self, qtbot, mscolab_server):
mslib.utils.auth.del_password_from_keyring(service_name="MSCOLAB", username=email)
yield
self.main_window.mscolab.logout()
self.window.hide()
self.main_window.hide()

def test_url_combo(self):
assert self.window.urlCb.count() >= 1
Expand Down Expand Up @@ -279,21 +278,15 @@ def setup(self, qtbot, mscolab_app, mscolab_server):
assert add_user_to_operation(path=self.operation_name3, access_level="collaborator", emailid=self.userdata3[0])

self.window = msui.MSUIMainWindow(mscolab_data_dir=mscolab_settings.MSCOLAB_DATA_DIR)
qtbot.add_widget(self.window, before_close_func=set_force_close)
self.window.create_new_flight_track()
self.window.show()

self.total_created_operations = 0
yield
self.window.mscolab.logout()
if self.window.mscolab.version_window:
self.window.mscolab.version_window.close()
if self.window.mscolab.conn:
self.window.mscolab.conn.disconnect()
# force close all open views
while self.window.listViews.count() > 0:
self.window.listViews.item(0).window.handle_force_close()
# close all hanging operation option windows
self.window.mscolab.close_external_windows()

def test_activate_operation(self, qtbot):
self._connect_to_mscolab(qtbot)
Expand Down
Loading
Loading