Files
dxdesigner-part-replacement/tests/ui/test_deferred_close_lifetime.py
T

54 lines
2.0 KiB
Python

"""Deferred diagnosis completion must respect the window's Qt lifetime."""
from PySide6.QtCore import QObject, Signal
from PySide6.QtWidgets import QApplication
from shiboken6 import delete
from dx_productivity.trial_task_center.ui.dsh_automation import DshAutomation
from dx_productivity.trial_task_center.ui.main_window import TrialTaskCenterWindow
def test_diagnosis_finished_close_is_cancelled_when_window_is_destroyed(ui, qtbot):
ui.settle()
window = TrialTaskCenterWindow(ui.service)
qtbot.waitUntil(lambda: not window._workers and not window._task_query.busy
and not window._context_query.busy and not window._feedback_query.busy
and not window._resource_status.busy)
window.archive_on_close_check.setChecked(False)
automation = DshAutomation(window)
window._dsh_automation = automation
window._close_pending = True
automation._finished()
# Another accepted close can finish before the scheduled retry is delivered.
window.close()
assert window._closed
delete(window)
with qtbot.captureExceptions() as exceptions:
QApplication.processEvents()
assert exceptions == []
def test_harness_stopped_close_is_cancelled_when_window_is_destroyed(ui, qtbot):
class Harness(QObject):
stopped = Signal()
is_running = True
def shutdown(self):
self.is_running = False
self.stopped.emit()
ui.settle()
window = TrialTaskCenterWindow(ui.service)
qtbot.waitUntil(lambda: not window._workers and not window._task_query.busy
and not window._context_query.busy and not window._feedback_query.busy
and not window._resource_status.busy)
window.archive_on_close_check.setChecked(False)
window._dsh_view = Harness(window)
window.close()
assert not window._closed
window.close()
assert window._closed
delete(window)
with qtbot.captureExceptions() as exceptions:
QApplication.processEvents()
assert exceptions == []