1
1
"""Test idlelib.configdialog.
2
2
3
3
Half the class creates dialog, half works with user customizations.
4
- Coverage: 46% just by creating dialog, 56 % with current tests.
4
+ Coverage: 46% just by creating dialog, 60 % with current tests.
5
5
"""
6
6
from idlelib .configdialog import ConfigDialog , idleConf , changes
7
7
from test .support import requires
8
8
requires ('gui' )
9
9
from tkinter import Tk
10
10
import unittest
11
11
import idlelib .config as config
12
+ from idlelib .idle_test .mock_idle import Func
12
13
13
14
# Tests should not depend on fortuitous user configurations.
14
15
# They must not affect actual user .cfg files.
22
23
}
23
24
24
25
root = None
25
- configure = None
26
+ dialog = None
26
27
mainpage = changes ['main' ]
27
28
highpage = changes ['highlight' ]
28
29
keyspage = changes ['keys' ]
29
30
30
- class TestDialog (ConfigDialog ): pass # Delete?
31
+
32
+ class TestDialog (ConfigDialog ):
33
+ pass # Delete?
31
34
32
35
33
36
def setUpModule ():
34
- global root , configure
37
+ global root , dialog
35
38
idleConf .userCfg = testcfg
36
39
root = Tk ()
37
- root .withdraw ()
38
- configure = TestDialog (root , 'Test' , _utest = True )
40
+ # root.withdraw() # Comment out, see issue 30870
41
+ dialog = TestDialog (root , 'Test' , _utest = True )
39
42
40
43
41
44
def tearDownModule ():
42
- global root , configure
45
+ global root , dialog
43
46
idleConf .userCfg = usercfg
44
- configure .remove_var_callbacks ()
45
- del configure
47
+ dialog .remove_var_callbacks ()
48
+ del dialog
46
49
root .update_idletasks ()
47
50
root .destroy ()
48
51
del root
@@ -58,31 +61,105 @@ def test_font(self):
58
61
default_font = idleConf .GetFont (root , 'main' , 'EditorWindow' )
59
62
default_size = str (default_font [1 ])
60
63
default_bold = default_font [2 ] == 'bold'
61
- configure .font_name .set ('Test Font' )
64
+ dialog .font_name .set ('Test Font' )
62
65
expected = {'EditorWindow' : {'font' : 'Test Font' ,
63
66
'font-size' : default_size ,
64
67
'font-bold' : str (default_bold )}}
65
68
self .assertEqual (mainpage , expected )
66
69
changes .clear ()
67
- configure .font_size .set (20 )
70
+ dialog .font_size .set (20 )
68
71
expected = {'EditorWindow' : {'font' : 'Test Font' ,
69
72
'font-size' : '20' ,
70
73
'font-bold' : str (default_bold )}}
71
74
self .assertEqual (mainpage , expected )
72
75
changes .clear ()
73
- configure .font_bold .set (not default_bold )
76
+ dialog .font_bold .set (not default_bold )
74
77
expected = {'EditorWindow' : {'font' : 'Test Font' ,
75
78
'font-size' : '20' ,
76
79
'font-bold' : str (not default_bold )}}
77
80
self .assertEqual (mainpage , expected )
78
81
79
- #def test_sample(self): pass # TODO
82
+ def test_set_sample (self ):
83
+ # Set_font_sample also sets highlight_sample.
84
+ pass
80
85
81
86
def test_tabspace (self ):
82
- configure .space_num .set (6 )
87
+ dialog .space_num .set (6 )
83
88
self .assertEqual (mainpage , {'Indent' : {'num-spaces' : '6' }})
84
89
85
90
91
+ class FontSelectTest (unittest .TestCase ):
92
+ # These two functions test that selecting a new font in the
93
+ # list of fonts changes font_name and calls set_font_sample.
94
+ # The fontlist widget and on_fontlist_select event handler
95
+ # are tested here together.
96
+
97
+ @classmethod
98
+ def setUpClass (cls ):
99
+ if dialog .fontlist .size () < 2 :
100
+ cls .skipTest ('need at least 2 fonts' )
101
+ dialog .set_font_sample = Func () # Mask instance method.
102
+
103
+ @classmethod
104
+ def tearDownClass (cls ):
105
+ del dialog .set_font_sample # Unmask instance method.
106
+
107
+ def setUp (self ):
108
+ dialog .set_font_sample .called = 0
109
+ changes .clear ()
110
+
111
+ def test_select_font_key (self ):
112
+ # Up and Down keys should select a new font.
113
+
114
+ fontlist = dialog .fontlist
115
+ fontlist .activate (0 )
116
+ font = dialog .fontlist .get ('active' )
117
+
118
+ # Test Down key.
119
+ fontlist .focus_force ()
120
+ fontlist .update ()
121
+ fontlist .event_generate ('<Key-Down>' )
122
+ fontlist .event_generate ('<KeyRelease-Down>' )
123
+
124
+ down_font = fontlist .get ('active' )
125
+ self .assertNotEqual (down_font , font )
126
+ self .assertIn (dialog .font_name .get (), down_font .lower ())
127
+ self .assertEqual (dialog .set_font_sample .called , 1 )
128
+
129
+ # Test Up key.
130
+ fontlist .focus_force ()
131
+ fontlist .update ()
132
+ fontlist .event_generate ('<Key-Up>' )
133
+ fontlist .event_generate ('<KeyRelease-Up>' )
134
+
135
+ up_font = fontlist .get ('active' )
136
+ self .assertEqual (up_font , font )
137
+ self .assertIn (dialog .font_name .get (), up_font .lower ())
138
+ self .assertEqual (dialog .set_font_sample .called , 2 )
139
+
140
+ def test_select_font_mouse (self ):
141
+ # Click on item should select that item.
142
+
143
+ fontlist = dialog .fontlist
144
+ fontlist .activate (0 )
145
+
146
+ # Select next item in listbox
147
+ fontlist .focus_force ()
148
+ fontlist .see (1 )
149
+ fontlist .update ()
150
+ x , y , dx , dy = fontlist .bbox (1 )
151
+ x += dx // 2
152
+ y += dy // 2
153
+ fontlist .event_generate ('<Button-1>' , x = x , y = y )
154
+ fontlist .event_generate ('<ButtonRelease-1>' , x = x , y = y )
155
+
156
+ font1 = fontlist .get (1 )
157
+ select_font = fontlist .get ('anchor' )
158
+ self .assertEqual (select_font , font1 )
159
+ self .assertIn (dialog .font_name .get (), font1 .lower ())
160
+ self .assertEqual (dialog .set_font_sample .called , 1 )
161
+
162
+
86
163
class HighlightTest (unittest .TestCase ):
87
164
88
165
def setUp (self ):
@@ -103,19 +180,19 @@ def setUp(self):
103
180
changes .clear ()
104
181
105
182
def test_startup (self ):
106
- configure .radio_startup_edit .invoke ()
183
+ dialog .radio_startup_edit .invoke ()
107
184
self .assertEqual (mainpage ,
108
185
{'General' : {'editor-on-startup' : '1' }})
109
186
110
187
def test_autosave (self ):
111
- configure .radio_save_auto .invoke ()
188
+ dialog .radio_save_auto .invoke ()
112
189
self .assertEqual (mainpage , {'General' : {'autosave' : '1' }})
113
190
114
191
def test_editor_size (self ):
115
- configure .entry_win_height .insert (0 , '1' )
192
+ dialog .entry_win_height .insert (0 , '1' )
116
193
self .assertEqual (mainpage , {'EditorWindow' : {'height' : '140' }})
117
194
changes .clear ()
118
- configure .entry_win_width .insert (0 , '1' )
195
+ dialog .entry_win_width .insert (0 , '1' )
119
196
self .assertEqual (mainpage , {'EditorWindow' : {'width' : '180' }})
120
197
121
198
#def test_help_sources(self): pass # TODO
0 commit comments