|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | """ |
3 | 3 | ResizeDialog test |
4 | | -
|
5 | | -Interactive plotting interface with MATLAB-like syntax |
6 | 4 | """ |
7 | 5 |
|
8 | 6 | # guitest: show |
9 | 7 |
|
10 | | -import guidata |
11 | 8 | import pytest |
| 9 | +from guidata.qthelpers import qt_app_context |
12 | 10 | from qtpy.QtCore import Qt |
13 | 11 |
|
14 | 12 | from plotpy.widgets.resizedialog import ResizeDialog |
|
18 | 16 | ((800, 400), (200, 100), False, (800, 400, 4)), |
19 | 17 | ((800, 400), (200, 100), True, (800, 400, 1)), |
20 | 18 | ] |
21 | | -qapp = guidata.qapplication() |
22 | 19 |
|
23 | 20 |
|
24 | 21 | @pytest.mark.parametrize("new_size,old_size,keep_original_size,result", size_list) |
25 | 22 | 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 |
33 | 31 |
|
34 | 32 |
|
35 | 33 | 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 |
47 | 46 |
|
48 | 47 |
|
49 | 48 | 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) |
56 | 56 |
|
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 |
61 | 61 |
|
62 | 62 |
|
63 | 63 | 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