Coverage for test_gui.py: 92%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

51 statements  

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""" 

6 

7import time 

8from leo.core import leoGlobals as g 

9from leo.core.leoTest2 import LeoUnitTest, create_app 

10from leo.core.leoQt import QtCore 

11 

12#@+others 

13#@+node:ekr.20210910084607.2: ** class TestNullGui(LeoUnitTest) 

14class TestNullGui(LeoUnitTest): 

15 """Test cases for gui base classes.""" 

16 

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.""" 

35 

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 assert option.ShowTabsAndSpaces is not None # pragma: no cover 

60 #@+node:ekr.20210912140946.1: *3* TestQtGui.test_do_nothing1/2/3 

61 # These tests exist to test the startup logic. 

62 if 0: 

63 

64 def test_do_nothing1(self): 

65 time.sleep(0.1) 

66 

67 def test_do_nothing2(self): 

68 time.sleep(0.1) 

69 

70 def test_do_nothing3(self): 

71 time.sleep(0.1) 

72 #@+node:ekr.20210912064439.2: *3* TestQtGui.test_qt_ctors_for_all_dialogs 

73 def test_qt_ctors_for_all_dialogs(self): 

74 # Make sure the dialogs don't crash. 

75 c = self.c 

76 gui = g.app.gui 

77 self.assertEqual(gui.__class__.__name__, 'LeoQtGui') 

78 gui.runAboutLeoDialog(c, 'version', 'copyright', 'url', 'email') 

79 gui.runAskLeoIDDialog() 

80 gui.runAskOkDialog(c, 'title', 'message') 

81 gui.runAskOkCancelNumberDialog(c, 'title', 'message') 

82 gui.runAskOkCancelStringDialog(c, 'title', 'message') 

83 gui.runAskYesNoDialog(c, 'title', 'message') 

84 gui.runAskYesNoCancelDialog(c, 'title', 'message') 

85 #@+node:ekr.20210912133358.1: *3* TestQtGui.test_qt_enums 

86 def test_qt_enums(self): 

87 

88 # https://github.com/leo-editor/leo-editor/issues/1973 list of enums 

89 

90 if not QtCore and QtCore.Qt: 

91 self.skipTest('no qt') # pragma: no cover 

92 table = ( 

93 'DropAction', 'ItemFlag', 'KeyboardModifier', 

94 'MouseButton', 'Orientation', 

95 'TextInteractionFlag', 'ToolBarArea', 

96 'WindowType', 'WindowState', 

97 ) 

98 for ivar in table: 

99 assert hasattr(QtCore.Qt, ivar), repr(ivar) 

100 #@-others 

101#@-others 

102#@-leo