Skip to content

Commit

Permalink
test_resize_dialog: attempt to fix for Qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreRaybaut committed Nov 22, 2023
1 parent a5102e9 commit 4a649f9
Showing 1 changed file with 35 additions and 34 deletions.
69 changes: 35 additions & 34 deletions plotpy/tests/widgets/test_resize_dialog.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# -*- coding: utf-8 -*-
"""
ResizeDialog test
Interactive plotting interface with MATLAB-like syntax
"""

# guitest: show

import guidata
import pytest
from guidata.qthelpers import qt_app_context
from qtpy.QtCore import Qt

from plotpy.widgets.resizedialog import ResizeDialog
Expand All @@ -18,48 +16,51 @@
((800, 400), (200, 100), False, (800, 400, 4)),
((800, 400), (200, 100), True, (800, 400, 1)),
]
qapp = guidata.qapplication()


@pytest.mark.parametrize("new_size,old_size,keep_original_size,result", size_list)
def test_resize_dialog(new_size, old_size, keep_original_size, result):
dialog = ResizeDialog(
None, new_size, old_size, "Enter the new size:", keep_original_size
)
assert result[0] == dialog.width
assert result[1] == dialog.height
assert result[2] == dialog.get_zoom()
assert dialog.keep_original_size is keep_original_size
with qt_app_context():
dialog = ResizeDialog(
None, new_size, old_size, "Enter the new size:", keep_original_size
)
assert result[0] == dialog.width
assert result[1] == dialog.height
assert result[2] == dialog.get_zoom()
assert dialog.keep_original_size is keep_original_size


def test_resize_dialog_qtbot_accept(qtbot):
result = (1500, 1000, 5)
dialog = ResizeDialog(None, (150, 100), (300, 200), "Enter the new size:")
qtbot.addWidget(dialog) # Ensure widget is destroyed
dialog.show()
qtbot.waitActive(dialog)
qtbot.keyClicks(dialog.w_edit, "0")
qtbot.keyPress(dialog, Qt.Key_Enter)
assert result[0] == dialog.width
assert result[1] == dialog.height
assert result[2] == dialog.get_zoom()
assert dialog.keep_original_size is False
with qt_app_context():
result = (1500, 1000, 5)
dialog = ResizeDialog(None, (150, 100), (300, 200), "Enter the new size:")
qtbot.addWidget(dialog) # Ensure widget is destroyed
dialog.show()
qtbot.waitActive(dialog)
qtbot.keyClicks(dialog.w_edit, "0")
qtbot.keyPress(dialog, Qt.Key_Enter)
assert result[0] == dialog.width
assert result[1] == dialog.height
assert result[2] == dialog.get_zoom()
assert dialog.keep_original_size is False


def test_resize_dialog_qtbot_reject(qtbot):
result = (150, 100, 0.5)
dialog = ResizeDialog(None, (150, 100), (300, 200), "Enter the new size:")
qtbot.addWidget(dialog) # Ensure widget is destroyed
dialog.show()
qtbot.waitActive(dialog)
qtbot.keyPress(dialog, Qt.Key_Return)
with qt_app_context():
result = (150, 100, 0.5)
dialog = ResizeDialog(None, (150, 100), (300, 200), "Enter the new size:")
qtbot.addWidget(dialog) # Ensure widget is destroyed
dialog.show()
qtbot.waitActive(dialog)
qtbot.keyPress(dialog, Qt.Key_Return)

assert result[0] == dialog.width
assert result[1] == dialog.height
assert result[2] == dialog.get_zoom()
assert dialog.keep_original_size is False
assert result[0] == dialog.width
assert result[1] == dialog.height
assert result[2] == dialog.get_zoom()
assert dialog.keep_original_size is False


if __name__ == "__main__":
dialog = ResizeDialog(None, (150, 100), (300, 250), "Enter the new size:")
dialog.exec()
with qt_app_context():
dialog = ResizeDialog(None, (150, 100), (300, 250), "Enter the new size:")
dialog.exec()

0 comments on commit 4a649f9

Please sign in to comment.