Skip to content

Commit

Permalink
Reuse any existing QApplication instance in tests
Browse files Browse the repository at this point in the history
According to my observations, also while trying to package MSS with nix,
this fixes the segmentation fault that can occur when running the tests.
  • Loading branch information
matrss committed Nov 16, 2023
1 parent 85b3d32 commit 377e039
Show file tree
Hide file tree
Showing 20 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion tests/_test_msui/test_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Test_Editor(object):

@mock.patch("PyQt5.QtWidgets.QMessageBox.warning", return_value=QtWidgets.QMessageBox.Yes)
def setup_method(self, mockmessage):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)

self.window = editor.EditorMainWindow()
self.save_file_name = self.save_file_name
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 @@ -42,7 +42,7 @@
class Test_KmlOverlayDockWidget(object):

def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.view = mock.Mock()
self.view.map = mock.Mock(side_effect=lambda x, y: (x, y))
self.view.map.plot = mock.Mock(return_value=[mock.Mock()])
Expand Down
6 changes: 3 additions & 3 deletions tests/_test_msui/test_linearview.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

class Test_MSS_LV_Options_Dialog(object):
def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.window = tv.MSUI_LV_Options_Dialog(settings=_DEFAULT_SETTINGS_LINEARVIEW)
self.window.show()
QtWidgets.QApplication.processEvents()
Expand All @@ -69,7 +69,7 @@ def test_get(self, mockcrit):

class Test_MSSLinearViewWindow(object):
def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
initial_waypoints = [ft.Waypoint(40., 25., 300), ft.Waypoint(60., -10., 400), ft.Waypoint(40., 10, 300)]

waypoints_model = ft.WaypointsTableModel("")
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_options(self, mockdlg, mockbox):
reason="multiprocessing needs currently start_method fork")
class Test_LinearViewWMS(object):
def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.port = PORTS.pop()
self.tempdir = tempfile.mkdtemp()
if not os.path.exists(self.tempdir):
Expand Down
4 changes: 2 additions & 2 deletions tests/_test_msui/test_mscolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def setup_method(self):
self.user = get_user(self.userdata[0])

QtTest.QTest.qWait(500)
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.main_window = msui.MSUIMainWindow(mscolab_data_dir=mscolab_settings.MSCOLAB_DATA_DIR)
self.main_window.create_new_flight_track()
self.main_window.show()
Expand Down Expand Up @@ -302,7 +302,7 @@ def setup_method(self):
assert add_user_to_operation(path=self.operation_name3, access_level="collaborator", emailid=self.userdata3[0])

QtTest.QTest.qWait(500)
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.window = msui.MSUIMainWindow(mscolab_data_dir=mscolab_settings.MSCOLAB_DATA_DIR)
self.window.create_new_flight_track()
self.window.show()
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_msui/test_mscolab_admin_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def setup_method(self):
assert add_user_to_operation(path="tokyo", emailid=self.userdata[0], access_level="creator")

QtTest.QTest.qWait(500)
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.window = msui.MSUIMainWindow(mscolab_data_dir=mscolab_settings.MSCOLAB_DATA_DIR)
self.window.create_new_flight_track()
self.window.show()
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_msui/test_mscolab_merge_waypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def setup_method(self):
handle_db_reset()
self.process, self.url, self.app, _, self.cm, self.fm = mscolab_start_server(PORTS)
QtTest.QTest.qWait(500)
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.window = msui.MSUIMainWindow(mscolab_data_dir=mscolab_settings.MSCOLAB_DATA_DIR)
self.window.create_new_flight_track()
self.emailid = '[email protected]'
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_msui/test_mscolab_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def setup_method(self):
assert add_user_to_operation(path=self.operation_name, emailid=self.userdata[0])
self.user = get_user(self.userdata[0])
QtTest.QTest.qWait(500)
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.window = msui.MSUIMainWindow(mscolab_data_dir=mscolab_settings.MSCOLAB_DATA_DIR)
self.window.create_new_flight_track()
self.window.show()
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_msui/test_mscolab_version_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def setup_method(self):
assert add_user_to_operation(path=self.operation_name, emailid=self.userdata[0])
self.user = get_user(self.userdata[0])
QtTest.QTest.qWait(500)
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.window = msui.MSUIMainWindow(mscolab_data_dir=mscolab_settings.MSCOLAB_DATA_DIR)
self.window.create_new_flight_track()
self.window.show()
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_msui/test_mss.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@pytest.mark.skip(reason='needs review, assert missing')
def test_mss_rename_message():
application = QtWidgets.QApplication(sys.argv)
application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
main_window = mss.MSSMainWindow()
main_window.show()
QtTest.QTest.mouseClick(main_window.pushButton, QtCore.Qt.LeftButton)
Expand Down
6 changes: 3 additions & 3 deletions tests/_test_msui/test_msui.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_main():

class Test_MSS_AboutDialog():
def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.window = msui_mw.MSUI_AboutDialog()

def test_milestone_url(self):
Expand All @@ -86,7 +86,7 @@ def teardown_method(self):

class Test_MSS_ShortcutDialog():
def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.main_window = msui_mw.MSUIMainWindow()
self.main_window.show()
self.shortcuts = msui_mw.MSUI_ShortcutsDialog()
Expand Down Expand Up @@ -154,7 +154,7 @@ def setup_method(self):
os.path.dirname(os.path.abspath(__file__)),
'../',
'data/')
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)

self.window = msui.MSUIMainWindow()
self.window.create_new_flight_track()
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_msui/test_multiple_flightpath_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class Test_MultipleFlightpathControlWidget():

def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)

self.window = msui.MSUIMainWindow()
self.window.create_new_flight_track()
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_msui/test_remotesensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Test_RemoteSensingControlWidget(object):
Tests about RemoteSensingControlWidget
"""
def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.view = Mock()
self.map = qt.TopViewPlotter()
self.map.init_map()
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_msui/test_satellite_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

class Test_SatelliteDockWidget(object):
def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.view = mock.Mock()
self.window = sd.SatelliteControlWidget(view=self.view)
self.window.show()
Expand Down
6 changes: 3 additions & 3 deletions tests/_test_msui/test_sideview.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

class Test_MSS_SV_OptionsDialog(object):
def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.window = tv.MSUI_SV_OptionsDialog(settings=_DEFAULT_SETTINGS_SIDEVIEW)
self.window.show()
QtWidgets.QApplication.processEvents()
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_setColour(self, mockdlg):

class Test_MSSSideViewWindow(object):
def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
initial_waypoints = [ft.Waypoint(40., 25., 300), ft.Waypoint(60., -10., 400), ft.Waypoint(40., 10, 300)]

waypoints_model = ft.WaypointsTableModel("")
Expand Down Expand Up @@ -175,7 +175,7 @@ def test_y_axes(self, mockbox):
reason="multiprocessing needs currently start_method fork")
class Test_SideViewWMS(object):
def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.port = PORTS.pop()
self.tempdir = tempfile.mkdtemp()
if not os.path.exists(self.tempdir):
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_msui/test_suffix.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

class Test_SuffixChange(object):
def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.window = tv.MSUI_SV_OptionsDialog(settings=_DEFAULT_SETTINGS_SIDEVIEW)
self.window.show()
QtWidgets.QApplication.processEvents()
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_msui/test_tableview.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

class Test_TableView(object):
def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)

# Create an initital flight track.
initial_waypoints = [ft.Waypoint(flightlevel=0, location="EDMO", comments="take off OP"),
Expand Down
8 changes: 4 additions & 4 deletions tests/_test_msui/test_topview.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

class Test_MSS_TV_MapAppearanceDialog(object):
def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.window = tv.MSUI_TV_MapAppearanceDialog(settings=_DEFAULT_SETTINGS_TOPVIEW)
self.window.show()
QtWidgets.QApplication.processEvents()
Expand All @@ -72,7 +72,7 @@ def test_get(self, mockcrit):
class Test_MSSTopViewWindow(object):
def setup_method(self):
mainwindow = MSUIMainWindow()
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
initial_waypoints = [ft.Waypoint(40., 25., 0), ft.Waypoint(60., -10., 0), ft.Waypoint(40., 10, 0)]
waypoints_model = ft.WaypointsTableModel("")
waypoints_model.insertRows(
Expand Down Expand Up @@ -299,7 +299,7 @@ def test_map_options(self, mockbox):
class Test_TopViewWMS(object):
def setup_method(self):
self.port = PORTS.pop()
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)

self.tempdir = tempfile.mkdtemp()
if not os.path.exists(self.tempdir):
Expand Down Expand Up @@ -361,7 +361,7 @@ def test_server_getmap(self, mockbox):

class Test_MSUITopViewWindow():
def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)

def test_kwargs_update_does_not_harm(self):
initial_waypoints = [ft.Waypoint(40., 25., 0), ft.Waypoint(60., -10., 0), ft.Waypoint(40., 10, 0)]
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_msui/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def status_signal(s):
self.updater.on_update_available.connect(update_signal)
self.updater.on_status_update.connect(status_signal)
self.updater.on_update_finished.connect(update_finished_signal)
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)

def teardown_method(self):
self.application.quit()
Expand Down
2 changes: 1 addition & 1 deletion tests/_test_msui/test_wms_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class Test_WMSCapabilities(object):

def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.capabilities = mock.Mock()
self.capabilities.capabilities_document = u"Hölla die Waldfee".encode("utf-8")
self.capabilities.provider = mock.Mock()
Expand Down
4 changes: 2 additions & 2 deletions tests/_test_msui/test_wms_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class WMSControlWidgetSetup(object):
def _setup(self, widget_type):
wc.WMS_SERVICE_CACHE = {}
self.port = PORTS.pop()
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
if widget_type == "hsec":
self.view = HSecViewMockup()
else:
Expand Down Expand Up @@ -564,7 +564,7 @@ class TestWMSControlWidgetSetupSimple(object):
<Extent name="ELEVATION" default="900.0"> 500.0,600.0,700.0,900.0 </Extent>"""

def setup_method(self):
self.application = QtWidgets.QApplication(sys.argv)
self.application = QtWidgets.QApplication.instance() or QtWidgets.QApplication(sys.argv)
self.view = HSecViewMockup()
self.window = wc.HSecWMSControlWidget(view=self.view)
self.window.show()
Expand Down

0 comments on commit 377e039

Please sign in to comment.