Coverage for test_gui.py : 94%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2#@+leo-ver=5-thin
3#@+node:ekr.20210910084607.1: * @file ../unittests/test_gui.py
4#@@first
5"""Tests of gui base classes"""
7import time
8from leo.core import leoGlobals as g
9from leo.core.leoTest2 import LeoUnitTest, create_app
10from leo.core.leoQt import QtCore
12#@+others
13#@+node:ekr.20210910084607.2: ** class TestNullGui(LeoUnitTest)
14class TestNullGui(LeoUnitTest):
15 """Test cases for gui base classes."""
17 # Note: the default setUpClass creates a null gui.
18 #@+others
19 #@+node:ekr.20210909194336.23: *3* TestNullGui.test_null_gui_ctors_for_all_dialogs
20 def test_null_gui_ctors_for_all_dialogs(self):
21 c = self.c
22 # Make sure the ctors don't crash.
23 gui = g.app.gui
24 gui.runAboutLeoDialog(c, 'version', 'copyright', 'url', 'email')
25 gui.runAskLeoIDDialog()
26 gui.runAskOkDialog(c, 'title', 'message')
27 gui.runAskOkCancelNumberDialog(c, 'title', 'message')
28 gui.runAskOkCancelStringDialog(c, 'title', 'message')
29 gui.runAskYesNoDialog(c, 'title', 'message')
30 gui.runAskYesNoCancelDialog(c, 'title', 'message')
31 #@-others
32#@+node:ekr.20210912064439.1: ** class TestQtGui(LeoUnitTest)
33class TestQtGui(LeoUnitTest):
34 """Test cases for gui base classes."""
36 #@+others
37 #@+node:ekr.20210912143315.1: *3* TestQtGui.setUpClass
38 # Override LeoUnitTest setUpClass.
39 @classmethod
40 def setUpClass(cls):
41 create_app(gui_name='qt')
42 #@+node:ekr.20210913120449.1: *3* TestQtGui.test_bug_2164
43 def test_bug_2164(self):
44 # show-invisibles crashes with PyQt6.
45 from leo.core.leoQt import QtGui, isQt6
46 # Test the commands.
47 c = self.c
48 for command in ('toggle-invisibles', 'hide-invisibles', 'show-invisibles'):
49 c.k.simulateCommand(command)
50 option = QtGui.QTextOption()
51 # Test the old code.
52 if isQt6:
53 # Skip this test when using PyQt5.
54 with self.assertRaises(AttributeError):
55 flag = option.ShowTabsAndSpaces # As in the old code.
56 assert flag is not None
57 return
58 # Test the new code.
59 flag = option.ShowTabsAndSpaces
60 assert flag is not None
61 #@+node:ekr.20210912140946.1: *3* TestQtGui.test_do_nothing1/2/3
62 # These tests exist to test the startup logic.
63 if 0:
65 def test_do_nothing1(self):
66 time.sleep(0.1)
68 def test_do_nothing2(self):
69 time.sleep(0.1)
71 def test_do_nothing3(self):
72 time.sleep(0.1)
73 #@+node:ekr.20210912064439.2: *3* TestQtGui.test_qt_ctors_for_all_dialogs
74 def test_qt_ctors_for_all_dialogs(self):
75 # Make sure the dialogs don't crash.
76 c = self.c
77 gui = g.app.gui
78 self.assertEqual(gui.__class__.__name__, 'LeoQtGui')
79 gui.runAboutLeoDialog(c, 'version', 'copyright', 'url', 'email')
80 gui.runAskLeoIDDialog()
81 gui.runAskOkDialog(c, 'title', 'message')
82 gui.runAskOkCancelNumberDialog(c, 'title', 'message')
83 gui.runAskOkCancelStringDialog(c, 'title', 'message')
84 gui.runAskYesNoDialog(c, 'title', 'message')
85 gui.runAskYesNoCancelDialog(c, 'title', 'message')
86 #@+node:ekr.20210912133358.1: *3* TestQtGui.test_qt_enums
87 def test_qt_enums(self):
89 # https://github.com/leo-editor/leo-editor/issues/1973 list of enums
91 if not QtCore and QtCore.Qt:
92 self.skipTest('no qt')
93 table = (
94 'DropAction', 'ItemFlag', 'KeyboardModifier',
95 'MouseButton', 'Orientation',
96 'TextInteractionFlag', 'ToolBarArea',
97 'WindowType', 'WindowState',
98 )
99 for ivar in table:
100 assert hasattr(QtCore.Qt, ivar), repr(ivar)
101 #@-others
102#@-others
103#@-leo