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

Replace: occurrences of tests.utils.wait_until_signal with qtbot.wait_signal #2247

Merged
merged 10 commits into from
Mar 1, 2024
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,7 +34,6 @@
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 wait_until_signal


class Test_MSS_LV_Options_Dialog:
Expand Down Expand Up @@ -107,15 +106,15 @@ def setup(self, qapp, mswms_server):
self.window.hide()
shutil.rmtree(self.tempdir)

def query_server(self, url):
def query_server(self, qtbot, url):
QtTest.QTest.keyClicks(self.wms_control.multilayers.cbWMS_URL, url)
QtTest.QTest.mouseClick(self.wms_control.multilayers.btGetCapabilities, QtCore.Qt.LeftButton)
wait_until_signal(self.wms_control.cpdlg.canceled)
with qtbot.wait_signal(self.wms_control.cpdlg.canceled):
QtTest.QTest.mouseClick(self.wms_control.multilayers.btGetCapabilities, QtCore.Qt.LeftButton)

def test_server_getmap(self, qtbot):
"""
assert that a getmap call to a WMS server displays an image
"""
self.query_server(self.url)
self.query_server(qtbot, self.url)
with qtbot.wait_signal(self.wms_control.image_displayed):
QtTest.QTest.mouseClick(self.wms_control.btGetMap, QtCore.Qt.LeftButton)
9 changes: 4 additions & 5 deletions tests/_test_msui/test_sideview.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from mslib.msui import flighttrack as ft
import mslib.msui.sideview as tv
from mslib.msui.mpl_qtwidget import _DEFAULT_SETTINGS_SIDEVIEW
from tests.utils import wait_until_signal


class Test_MSS_SV_OptionsDialog:
Expand Down Expand Up @@ -147,16 +146,16 @@ def setup(self, qapp, mswms_server):
self.window.hide()
shutil.rmtree(self.tempdir)

def query_server(self, url):
def query_server(self, qtbot, url):
QtTest.QTest.keyClicks(self.wms_control.multilayers.cbWMS_URL, url)
QtTest.QTest.mouseClick(self.wms_control.multilayers.btGetCapabilities, QtCore.Qt.LeftButton)
wait_until_signal(self.wms_control.cpdlg.canceled)
with qtbot.wait_signal(self.wms_control.cpdlg.canceled):
QtTest.QTest.mouseClick(self.wms_control.multilayers.btGetCapabilities, QtCore.Qt.LeftButton)

def test_server_getmap(self, qtbot):
"""
assert that a getmap call to a WMS server displays an image
"""
self.query_server(self.url)
self.query_server(qtbot, self.url)
with qtbot.wait_signal(self.wms_control.image_displayed):
QtTest.QTest.mouseClick(self.wms_control.btGetMap, QtCore.Qt.LeftButton)
assert self.window.getView().plotter.image is not None
Expand Down
15 changes: 7 additions & 8 deletions tests/_test_msui/test_topview.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from mslib.msui import flighttrack as ft
from mslib.msui.msui import MSUIMainWindow
from mslib.msui.mpl_qtwidget import _DEFAULT_SETTINGS_TOPVIEW
from tests.utils import wait_until_signal


class Test_MSS_TV_MapAppearanceDialog:
Expand Down Expand Up @@ -222,18 +221,18 @@ def setup(self, qapp, mswms_server):
self.window.hide()
shutil.rmtree(self.tempdir)

def query_server(self, url):
def query_server(self, qtbot, url):
QtTest.QTest.keyClicks(self.wms_control.multilayers.cbWMS_URL, url)
QtTest.QTest.mouseClick(self.wms_control.multilayers.btGetCapabilities, QtCore.Qt.LeftButton)
wait_until_signal(self.wms_control.cpdlg.canceled)
with qtbot.wait_signal(self.wms_control.cpdlg.canceled):
QtTest.QTest.mouseClick(self.wms_control.multilayers.btGetCapabilities, QtCore.Qt.LeftButton)

def test_server_getmap(self):
def test_server_getmap(self, qtbot):
"""
assert that a getmap call to a WMS server displays an image
"""
self.query_server(self.url)
QtTest.QTest.mouseClick(self.wms_control.btGetMap, QtCore.Qt.LeftButton)
wait_until_signal(self.wms_control.image_displayed)
self.query_server(qtbot, self.url)
with qtbot.wait_signal(self.wms_control.image_displayed):
QtTest.QTest.mouseClick(self.wms_control.btGetMap, QtCore.Qt.LeftButton)
assert self.window.getView().map.image is not None
self.window.getView().set_settings({})
self.window.getView().clear_figure()
Expand Down
97 changes: 50 additions & 47 deletions tests/_test_msui/test_wms_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from PyQt5 import QtCore, QtTest
from mslib.msui import flighttrack as ft
import mslib.msui.wms_control as wc
from tests.utils import wait_until_signal


class HSecViewMockup(mock.Mock):
Expand Down Expand Up @@ -88,12 +87,12 @@ def _teardown(self):
self.window.hide()
shutil.rmtree(self.tempdir)

def query_server(self, url):
def query_server(self, qtbot, url):
while len(self.window.multilayers.cbWMS_URL.currentText()) > 0:
QtTest.QTest.keyClick(self.window.multilayers.cbWMS_URL, QtCore.Qt.Key_Backspace)
QtTest.QTest.keyClicks(self.window.multilayers.cbWMS_URL, url)
QtTest.QTest.mouseClick(self.window.multilayers.btGetCapabilities, QtCore.Qt.LeftButton)
wait_until_signal(self.window.cpdlg.canceled)
with qtbot.wait_signal(self.window.cpdlg.canceled):
QtTest.QTest.mouseClick(self.window.multilayers.btGetCapabilities, QtCore.Qt.LeftButton)


class Test_HSecWMSControlWidget(WMSControlWidgetSetup):
Expand All @@ -103,49 +102,54 @@ def setup(self, qapp):
yield
self._teardown()

def test_no_server(self):
def test_no_server(self, qtbot):
"""
assert that a message box informs about server troubles
"""
mock_url = f"{self.scheme}://{self.host}:{self.port-1}"
rohit2p marked this conversation as resolved.
Show resolved Hide resolved
with mock.patch("PyQt5.QtWidgets.QMessageBox.critical") as mock_critical:
self.query_server(f"{self.scheme}://{self.host}:{self.port-1}")
self.query_server(qtbot, mock_url)
mock_critical.assert_called_once()

def test_no_schema(self):
def test_no_schema(self, qtbot):
"""
assert that a message box informs about server troubles
"""
mock_url = f"{self.host}:{self.port}"
with mock.patch("PyQt5.QtWidgets.QMessageBox.critical") as mock_critical:
self.query_server(f"{self.host}:{self.port}")
self.query_server(qtbot, mock_url)
mock_critical.assert_called_once()

def test_invalid_schema(self):
def test_invalid_schema(self, qtbot):
"""
assert that a message box informs about server troubles
"""
mock_url = f"hppd://{self.host}:{self.port}"
with mock.patch("PyQt5.QtWidgets.QMessageBox.critical") as mock_critical:
self.query_server(f"hppd://{self.host}:{self.port}")
self.query_server(qtbot, mock_url)
mock_critical.assert_called_once()

def test_invalid_url(self):
def test_invalid_url(self, qtbot):
"""
assert that a message box informs about server troubles
"""
mock_url = f"{self.scheme}://???{self.host}:{self.port}"
with mock.patch("PyQt5.QtWidgets.QMessageBox.critical") as mock_critical:
self.query_server(f"{self.scheme}://???{self.host}:{self.port}")
self.query_server(qtbot, mock_url)
mock_critical.assert_called_once()

def test_connection_error(self):
def test_connection_error(self, qtbot):
"""
assert that a message box informs about server troubles
"""
mock_url = f"{self.scheme}://.....{self.host}:{self.port}"
with mock.patch("PyQt5.QtWidgets.QMessageBox.critical") as mock_critical:
self.query_server(f"{self.scheme}://.....{self.host}:{self.port}")
self.query_server(qtbot, mock_url)
mock_critical.assert_called_once()

@pytest.mark.skip("Breaks other tests in this class because of a lingering message box, for some reason")
def test_forward_backward_clicks(self):
self.query_server(self.url)
def test_forward_backward_clicks(self, qtbot):
self.query_server(qtbot, self.url)
self.window.init_time_back_click()
self.window.init_time_fwd_click()
self.window.valid_time_fwd_click()
Expand All @@ -162,15 +166,14 @@ def test_forward_backward_clicks(self):
pass

@pytest.mark.skip("Has a race condition where the abort might not happen fast enough")
def test_server_abort_getmap(self):
def test_server_abort_getmap(self, qtbot):
"""
assert that an aborted getmap call does not change the displayed image
"""
self.query_server(self.url)
rohit2p marked this conversation as resolved.
Show resolved Hide resolved
QtTest.QTest.mouseClick(self.window.btGetMap, QtCore.Qt.LeftButton)
self.query_server(qtbot, self.url)
QtTest.QTest.keyClick(self.window.pdlg, QtCore.Qt.Key_Enter)
wait_until_signal(self.window.image_displayed)

with qtbot.wait_signal(self.window.image_displayed):
QtTest.QTest.mouseClick(self.window.btGetMap, QtCore.Qt.LeftButton)
assert self.view.draw_image.call_count == 0
assert self.view.draw_legend.call_count == 0
assert self.view.draw_metadata.call_count == 0
Expand All @@ -180,7 +183,7 @@ def test_server_getmap(self, qtbot):
"""
assert that a getmap call to a WMS server displays an image
"""
self.query_server(self.url)
self.query_server(qtbot, self.url)

with qtbot.wait_signal(self.window.image_displayed):
QtTest.QTest.mouseClick(self.window.btGetMap, QtCore.Qt.LeftButton)
Expand All @@ -193,7 +196,7 @@ def test_server_getmap_cached(self, qtbot):
"""
assert that a getmap call to a WMS server displays an image
"""
self.query_server(self.url)
self.query_server(qtbot, self.url)

with qtbot.wait_signal(self.window.image_displayed):
QtTest.QTest.mouseClick(self.window.btGetMap, QtCore.Qt.LeftButton)
Expand All @@ -204,8 +207,8 @@ def test_server_getmap_cached(self, qtbot):
self.view.reset_mock()

QtTest.QTest.mouseClick(self.window.cbCacheEnabled, QtCore.Qt.LeftButton)
QtTest.QTest.mouseClick(self.window.btGetMap, QtCore.Qt.LeftButton)
wait_until_signal(self.window.image_displayed)
with qtbot.wait_signal(self.window.image_displayed):
QtTest.QTest.mouseClick(self.window.btGetMap, QtCore.Qt.LeftButton)

assert self.view.draw_image.call_count == 1
assert self.view.draw_legend.call_count == 1
Expand All @@ -215,7 +218,7 @@ def test_server_service_cache(self, qtbot):
"""
assert that changing between servers still allows image retrieval
"""
self.query_server(self.url)
self.query_server(qtbot, self.url)

with mock.patch("PyQt5.QtWidgets.QMessageBox.critical") as qm_critical:
with qtbot.wait_signal(self.window.cpdlg.canceled):
Expand All @@ -239,11 +242,11 @@ def test_server_service_cache(self, qtbot):
assert self.view.draw_legend.call_count == 1
assert self.view.draw_metadata.call_count == 1

def test_multilayer_handling(self):
def test_multilayer_handling(self, qtbot):
"""
assert that multilayers get created, handled and drawn properly
"""
self.query_server(self.url)
self.query_server(qtbot, self.url)
server = self.window.multilayers.listLayers.findItems(f"{self.url}/",
QtCore.Qt.MatchFixedString)[0]
self.window.cbAutoUpdate.setCheckState(False)
Expand Down Expand Up @@ -273,15 +276,15 @@ def test_multilayer_handling(self):
assert self.window.multilayers.listLayers.itemWidget(server.child(0), 2).currentText() == "1"

# Check drawing not causing errors
QtTest.QTest.mouseClick(self.window.btGetMap, QtCore.Qt.LeftButton)
wait_until_signal(self.window.image_displayed)
with qtbot.wait_signal(self.window.image_displayed):
QtTest.QTest.mouseClick(self.window.btGetMap, QtCore.Qt.LeftButton)

assert self.view.draw_image.call_count == 1
assert self.view.draw_legend.call_count == 1
assert self.view.draw_metadata.call_count == 1

def test_filter_handling(self):
self.query_server(self.url)
def test_filter_handling(self, qtbot):
self.query_server(qtbot, self.url)
server = self.window.multilayers.listLayers.findItems(f"{self.url}/",
QtCore.Qt.MatchFixedString)[0]
self.window.cbAutoUpdate.setCheckState(False)
Expand Down Expand Up @@ -321,11 +324,11 @@ def test_filter_handling(self):
assert len(self.window.multilayers.listLayers.findItems(f"{self.url}/",
QtCore.Qt.MatchFixedString)) == 0

def test_singlelayer_handling(self):
def test_singlelayer_handling(self, qtbot):
"""
assert that singlelayer mode behaves as expected
"""
self.query_server(self.url)
self.query_server(qtbot, self.url)
server = self.window.multilayers.listLayers.findItems(f"{self.url}/",
QtCore.Qt.MatchFixedString)[0]
self.window.cbAutoUpdate.setCheckState(False)
Expand All @@ -348,18 +351,18 @@ def test_singlelayer_handling(self):
assert self.window.lLayerName.text().endswith(server.child(1).text(0))

# Check drawing not causing errors
QtTest.QTest.mouseClick(self.window.btGetMap, QtCore.Qt.LeftButton)
wait_until_signal(self.window.image_displayed)
with qtbot.wait_signal(self.window.image_displayed):
QtTest.QTest.mouseClick(self.window.btGetMap, QtCore.Qt.LeftButton)

assert self.view.draw_image.call_count == 1
assert self.view.draw_legend.call_count == 1
assert self.view.draw_metadata.call_count == 1

def test_multilayer_syncing(self):
def test_multilayer_syncing(self, qtbot):
"""
assert that synced layers share their options
"""
self.query_server(self.url)
self.query_server(qtbot, self.url)
server = self.window.multilayers.listLayers.findItems(f"{self.url}/",
QtCore.Qt.MatchFixedString)[0]
self.window.cbAutoUpdate.setCheckState(False)
Expand All @@ -386,8 +389,8 @@ def test_multilayer_syncing(self):
assert layer_a.get_itime() == layer_a.get_itimes()[-1]

@mock.patch("mslib.msui.wms_control.WMSMapFetcher.moveToThread")
def test_server_no_thread(self, mockthread):
self.query_server(self.url)
def test_server_no_thread(self, mockthread, qtbot):
self.query_server(qtbot, self.url)
server = self.window.multilayers.listLayers.findItems(f"{self.url}/",
QtCore.Qt.MatchFixedString)[0]
self.window.cbAutoUpdate.setCheckState(False)
Expand All @@ -396,8 +399,8 @@ def test_server_no_thread(self, mockthread):
server.child(0).setCheckState(0, 2)
server.child(1).setCheckState(0, 2)

QtTest.QTest.mouseClick(self.window.btGetMap, QtCore.Qt.LeftButton)
wait_until_signal(self.window.image_displayed)
with qtbot.wait_signal(self.window.image_displayed):
QtTest.QTest.mouseClick(self.window.btGetMap, QtCore.Qt.LeftButton)

urlstr = f"{self.url}/mss/logo.png"
md5_filname = os.path.join(self.window.wms_cache, hashlib.md5(urlstr.encode('utf-8')).hexdigest() + ".png")
Expand All @@ -420,23 +423,23 @@ def test_server_getmap(self, qtbot):
"""
assert that a getmap call to a WMS server displays an image
"""
self.query_server(self.url)
self.query_server(qtbot, self.url)
with qtbot.wait_signal(self.window.image_displayed):
QtTest.QTest.mouseClick(self.window.btGetMap, QtCore.Qt.LeftButton)

assert self.view.draw_image.call_count == 1
assert self.view.draw_legend.call_count == 1
assert self.view.draw_metadata.call_count == 1

def test_multilayer_drawing(self):
def test_multilayer_drawing(self, qtbot):
"""
assert that drawing a layer through code doesn't fail for vsec
"""
self.query_server(self.url)
self.query_server(qtbot, self.url)
server = self.window.multilayers.listLayers.findItems(f"{self.url}/",
QtCore.Qt.MatchFixedString)[0]
server.child(0).draw()
wait_until_signal(self.window.image_displayed)
with qtbot.wait_signal(self.window.image_displayed):
server.child(0).draw()


class TestWMSControlWidgetSetupSimple:
Expand Down