Skip to content

Commit 4a649f9

Browse files
committed
test_resize_dialog: attempt to fix for Qt6
1 parent a5102e9 commit 4a649f9

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed
Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
# -*- coding: utf-8 -*-
22
"""
33
ResizeDialog test
4-
5-
Interactive plotting interface with MATLAB-like syntax
64
"""
75

86
# guitest: show
97

10-
import guidata
118
import pytest
9+
from guidata.qthelpers import qt_app_context
1210
from qtpy.QtCore import Qt
1311

1412
from plotpy.widgets.resizedialog import ResizeDialog
@@ -18,48 +16,51 @@
1816
((800, 400), (200, 100), False, (800, 400, 4)),
1917
((800, 400), (200, 100), True, (800, 400, 1)),
2018
]
21-
qapp = guidata.qapplication()
2219

2320

2421
@pytest.mark.parametrize("new_size,old_size,keep_original_size,result", size_list)
2522
def test_resize_dialog(new_size, old_size, keep_original_size, result):
26-
dialog = ResizeDialog(
27-
None, new_size, old_size, "Enter the new size:", keep_original_size
28-
)
29-
assert result[0] == dialog.width
30-
assert result[1] == dialog.height
31-
assert result[2] == dialog.get_zoom()
32-
assert dialog.keep_original_size is keep_original_size
23+
with qt_app_context():
24+
dialog = ResizeDialog(
25+
None, new_size, old_size, "Enter the new size:", keep_original_size
26+
)
27+
assert result[0] == dialog.width
28+
assert result[1] == dialog.height
29+
assert result[2] == dialog.get_zoom()
30+
assert dialog.keep_original_size is keep_original_size
3331

3432

3533
def test_resize_dialog_qtbot_accept(qtbot):
36-
result = (1500, 1000, 5)
37-
dialog = ResizeDialog(None, (150, 100), (300, 200), "Enter the new size:")
38-
qtbot.addWidget(dialog) # Ensure widget is destroyed
39-
dialog.show()
40-
qtbot.waitActive(dialog)
41-
qtbot.keyClicks(dialog.w_edit, "0")
42-
qtbot.keyPress(dialog, Qt.Key_Enter)
43-
assert result[0] == dialog.width
44-
assert result[1] == dialog.height
45-
assert result[2] == dialog.get_zoom()
46-
assert dialog.keep_original_size is False
34+
with qt_app_context():
35+
result = (1500, 1000, 5)
36+
dialog = ResizeDialog(None, (150, 100), (300, 200), "Enter the new size:")
37+
qtbot.addWidget(dialog) # Ensure widget is destroyed
38+
dialog.show()
39+
qtbot.waitActive(dialog)
40+
qtbot.keyClicks(dialog.w_edit, "0")
41+
qtbot.keyPress(dialog, Qt.Key_Enter)
42+
assert result[0] == dialog.width
43+
assert result[1] == dialog.height
44+
assert result[2] == dialog.get_zoom()
45+
assert dialog.keep_original_size is False
4746

4847

4948
def test_resize_dialog_qtbot_reject(qtbot):
50-
result = (150, 100, 0.5)
51-
dialog = ResizeDialog(None, (150, 100), (300, 200), "Enter the new size:")
52-
qtbot.addWidget(dialog) # Ensure widget is destroyed
53-
dialog.show()
54-
qtbot.waitActive(dialog)
55-
qtbot.keyPress(dialog, Qt.Key_Return)
49+
with qt_app_context():
50+
result = (150, 100, 0.5)
51+
dialog = ResizeDialog(None, (150, 100), (300, 200), "Enter the new size:")
52+
qtbot.addWidget(dialog) # Ensure widget is destroyed
53+
dialog.show()
54+
qtbot.waitActive(dialog)
55+
qtbot.keyPress(dialog, Qt.Key_Return)
5656

57-
assert result[0] == dialog.width
58-
assert result[1] == dialog.height
59-
assert result[2] == dialog.get_zoom()
60-
assert dialog.keep_original_size is False
57+
assert result[0] == dialog.width
58+
assert result[1] == dialog.height
59+
assert result[2] == dialog.get_zoom()
60+
assert dialog.keep_original_size is False
6161

6262

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

0 commit comments

Comments
 (0)