Coverage for test_gui.py: 94%
63 statements
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 10:21 -0500
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 10:21 -0500
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 os
8import time
9from leo.core import leoGlobals as g
10from leo.core.leoTest2 import LeoUnitTest, create_app
11from leo.core.leoQt import QtCore
13#@+others
14#@+node:ekr.20210910084607.2: ** class TestNullGui(LeoUnitTest)
15class TestNullGui(LeoUnitTest):
16 """Test cases for gui base classes."""
18 # Note: the default setUpClass creates a null gui.
19 #@+others
20 #@+node:ekr.20210909194336.23: *3* TestNullGui.test_null_gui_ctors_for_all_dialogs
21 def test_null_gui_ctors_for_all_dialogs(self):
22 c = self.c
23 # Make sure the ctors don't crash.
24 gui = g.app.gui
25 gui.runAboutLeoDialog(c, 'version', 'copyright', 'url', 'email')
26 gui.runAskLeoIDDialog()
27 gui.runAskOkDialog(c, 'title', 'message')
28 gui.runAskOkCancelNumberDialog(c, 'title', 'message')
29 gui.runAskOkCancelStringDialog(c, 'title', 'message')
30 gui.runAskYesNoDialog(c, 'title', 'message')
31 gui.runAskYesNoCancelDialog(c, 'title', 'message')
32 #@-others
33#@+node:ekr.20210912064439.1: ** class TestQtGui(LeoUnitTest)
34class TestQtGui(LeoUnitTest):
35 """Test cases for gui base classes."""
37 #@+others
38 #@+node:ekr.20210912143315.1: *3* TestQtGui.setUpClass
39 # Override LeoUnitTest setUpClass.
40 @classmethod
41 def setUpClass(cls):
42 create_app(gui_name='qt')
43 #@+node:ekr.20210913120449.1: *3* TestQtGui.test_bug_2164
44 def test_bug_2164(self):
45 # show-invisibles crashes with PyQt6.
46 from leo.core.leoQt import QtGui, isQt6
47 # Test the commands.
48 c = self.c
49 for command in ('toggle-invisibles', 'hide-invisibles', 'show-invisibles'):
50 c.k.simulateCommand(command)
51 option = QtGui.QTextOption()
52 # Test the old code.
53 if isQt6:
54 # Skip this test when using PyQt5.
55 with self.assertRaises(AttributeError):
56 flag = option.ShowTabsAndSpaces # As in the old code.
57 assert flag is not None
58 return
59 # Test the new code.
60 assert option.ShowTabsAndSpaces is not None # pragma: no cover
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') # pragma: no cover
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 #@+node:ekr.20220411165627.1: *3* TestQtGui.test_put_html_links
102 def test_put_html_links(self):
104 c, p = self.c, self.c.p
105 # Create a test outline.
106 assert p == self.root_p
107 assert p.h == 'root'
108 p2 = p.insertAsLastChild()
109 p2.h = '@file test_file.py'
110 # Run the tests.
111 table = (
112 # python.
113 (True, 'File "test_file.py", line 5'),
114 # pylint.
115 (True, r'leo\unittest\test_file.py:1326:8: W0101: Unreachable code (unreachable)'),
116 # pyflakes.
117 (True, r"test_file.py:51:13 'leo.core.leoQt5.*' imported but unused"),
118 # mypy...
119 (True, 'test_file.py:116: error: Function is missing a return type annotation [no-untyped-def]'),
120 (True, r'leo\core\test_file.py:116: note: Use "-> None" if function does not return a value'),
121 (False, 'Found 1 error in 1 file (checked 1 source file)'),
122 (False, 'mypy: done'),
123 # Random output.
124 (False, 'Hello world\n'),
125 )
126 for expected, s in table:
127 s = s.replace('\\', os.sep).rstrip() + '\n'
128 result = c.frame.log.put_html_links(s)
129 self.assertEqual(result, expected, msg=repr(s))
130 #@-others
131#@-others
132#@-leo