Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e8234a

Browse files
committed
Issue #21477: Add htests for GrepDialog, UndoDelegator, and configDialog.
Put instructions in a fixed size scrollable Text. Patch by Saimadhav Heblikar.
1 parent a5b257a commit 2e8234a

5 files changed

Lines changed: 108 additions & 21 deletions

File tree

Lib/idlelib/GrepDialog.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,31 @@ def close(self, event=None):
120120
self.top.grab_release()
121121
self.top.withdraw()
122122

123+
def _grep_dialog(parent):
124+
from idlelib.PyShell import PyShellFileList
125+
root = Tk()
126+
root.title("Test GrepDialog")
127+
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
128+
root.geometry("+%d+%d"%(x, y + 150))
129+
130+
flist = PyShellFileList(root)
131+
text = Text(root, height=5)
132+
text.pack()
133+
134+
def show_grep_dialog():
135+
text.tag_add(SEL, "1.0", END)
136+
grep(text, flist=flist)
137+
text.tag_remove(SEL, "1.0", END)
138+
139+
button = Button(root, text="Show GrepDialog", command=show_grep_dialog)
140+
button.pack()
141+
root.mainloop()
142+
123143
if __name__ == "__main__":
124144
# A human test is a bit tricky since EditorWindow() imports this module.
125145
# Hence Idle must be restarted after editing this file for a live test.
126146
import unittest
127147
unittest.main('idlelib.idle_test.test_grep', verbosity=2, exit=False)
148+
149+
from idlelib.idle_test.htest import run
150+
run(_grep_dialog)

Lib/idlelib/ObjectBrowser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ def _object_browser(parent):
126126
import sys
127127
from tkinter import Tk
128128
root = Tk()
129+
root.title("Test ObjectBrowser")
129130
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
130-
root.geometry("+%d+%d"%(x, y + 100))
131+
root.geometry("+%d+%d"%(x, y + 150))
131132
root.configure(bd=0, bg="yellow")
132133
root.focus_set()
133134
sc = ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)

Lib/idlelib/UndoDelegator.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,17 +336,30 @@ def bump_depth(self, incr=1):
336336
self.depth = self.depth + incr
337337
return self.depth
338338

339-
def main():
339+
def _undo_delegator(parent):
340340
from idlelib.Percolator import Percolator
341341
root = Tk()
342-
root.wm_protocol("WM_DELETE_WINDOW", root.quit)
343-
text = Text()
342+
root.title("Test UndoDelegator")
343+
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
344+
root.geometry("+%d+%d"%(x, y + 150))
345+
346+
text = Text(root)
347+
text.config(height=10)
344348
text.pack()
345349
text.focus_set()
346350
p = Percolator(text)
347351
d = UndoDelegator()
348352
p.insertfilter(d)
353+
354+
undo = Button(root, text="Undo", command=lambda:d.undo_event(None))
355+
undo.pack(side='left')
356+
redo = Button(root, text="Redo", command=lambda:d.redo_event(None))
357+
redo.pack(side='left')
358+
dump = Button(root, text="Dump", command=lambda:d.dump_event(None))
359+
dump.pack(side='left')
360+
349361
root.mainloop()
350362

351363
if __name__ == "__main__":
352-
main()
364+
from idlelib.idle_test.htest import run
365+
run(_undo_delegator)

Lib/idlelib/configDialog.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@
2525

2626
class ConfigDialog(Toplevel):
2727

28-
def __init__(self,parent,title):
28+
def __init__(self,parent,title,_htest=False):
29+
"""
30+
_htest - bool, change box location when running htest
31+
"""
2932
Toplevel.__init__(self, parent)
3033
self.wm_withdraw()
3134

3235
self.configure(borderwidth=5)
3336
self.title('IDLE Preferences')
37+
if _htest:
38+
parent.instance_dict = {}
3439
self.geometry("+%d+%d" % (parent.winfo_rootx()+20,
35-
parent.winfo_rooty()+30))
40+
parent.winfo_rooty()+(30 if not _htest else 150)))
3641
#Theme Elements. Each theme element key is its display name.
3742
#The first value of the tuple is the sample area tag name.
3843
#The second value is the display name list sort index.
@@ -1140,9 +1145,5 @@ def Help(self):
11401145
pass
11411146

11421147
if __name__ == '__main__':
1143-
#test the dialog
1144-
root=Tk()
1145-
Button(root,text='Dialog',
1146-
command=lambda:ConfigDialog(root,'Settings')).pack()
1147-
root.instance_dict={}
1148-
root.mainloop()
1148+
from idlelib.idle_test.htest import run
1149+
run(ConfigDialog)

Lib/idlelib/idle_test/htest.py

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
test the widget. Close the window to skip or end the test.
3232
'''
3333
from importlib import import_module
34+
from idlelib.macosxSupport import _initializeTkVariantTests
3435
import tkinter as tk
3536

3637
AboutDialog_spec = {
@@ -67,6 +68,21 @@
6768
"The default color scheme is in idlelib/config-highlight.def"
6869
}
6970

71+
ConfigDialog_spec = {
72+
'file': 'configDialog',
73+
'kwds': {'title': 'Settings',
74+
'_htest': True,},
75+
'msg': "IDLE preferences dialog.\n"
76+
"In the 'Fonts/Tabs' tab, changing font face, should update the "
77+
"font face of the text in the area below it.\nIn the "
78+
"'Highlighting' tab, try different color schemes. Clicking "
79+
"items in the sample program should update the choices above it."
80+
"\nIn the 'Keys' and 'General' tab, test settings of interest."
81+
"\n[Ok] to close the dialog.[Apply] to apply the settings and "
82+
"and [Cancel] to revert all changes.\nRe-run the test to ensure "
83+
"changes made have persisted."
84+
}
85+
7086
_dyn_option_menu_spec = {
7187
'file': 'dynOptionMenuWidget',
7288
'kwds': {},
@@ -121,6 +137,16 @@
121137
"entry is used."
122138
}
123139

140+
_grep_dialog_spec = {
141+
'file': 'GrepDialog',
142+
'kwds': {},
143+
'msg': "Click the 'Show GrepDialog' button.\n"
144+
"Test the various 'Find-in-files' functions.\n"
145+
"The results should be displayed in a new '*Output*' window.\n"
146+
"'Right-click'->'Goto file/line' anywhere in the search results "
147+
"should open that file \nin a new EditorWindow."
148+
}
149+
124150
_help_dialog_spec = {
125151
'file': 'EditorWindow',
126152
'kwds': {},
@@ -186,15 +212,15 @@
186212
'kwds': {},
187213
'msg': "Click the 'Replace' button.\n"
188214
"Test various replace options in the 'Replace dialog'.\n"
189-
"Click [Close] or [X] to close to the 'Replace Dialog'."
215+
"Click [Close] or [X] to close 'Replace Dialog'."
190216
}
191217

192218
_search_dialog_spec = {
193219
'file': 'SearchDialog',
194220
'kwds': {},
195221
'msg': "Click the 'Search' button.\n"
196222
"Test various search options in the 'Search dialog'.\n"
197-
"Click [Close] or [X] to close to the 'Search Dialog'."
223+
"Click [Close] or [X] to close 'Search Dialog'."
198224
}
199225

200226
_scrolled_list_spec = {
@@ -247,6 +273,15 @@
247273
"Click on folders upto to the lowest level."
248274
}
249275

276+
_undo_delegator_spec = {
277+
'file': 'UndoDelegator',
278+
'kwds': {},
279+
'msg': "Click [Undo] to undo any action.\n"
280+
"Click [Redo] to redo any action.\n"
281+
"Click [Dump] to dump the current state "
282+
"by printing to the console or the IDLE shell.\n"
283+
}
284+
250285
_widget_redirector_spec = {
251286
'file': 'WidgetRedirector',
252287
'kwds': {},
@@ -256,6 +291,20 @@
256291

257292
def run(*tests):
258293
root = tk.Tk()
294+
root.title('IDLE htest')
295+
root.resizable(0, 0)
296+
_initializeTkVariantTests(root)
297+
298+
# a scrollable Label like constant width text widget.
299+
frameLabel = tk.Frame(root, padx=10)
300+
frameLabel.pack()
301+
text = tk.Text(frameLabel, wrap='word')
302+
text.configure(bg=root.cget('bg'), relief='flat', height=4, width=70)
303+
scrollbar = tk.Scrollbar(frameLabel, command=text.yview)
304+
text.config(yscrollcommand=scrollbar.set)
305+
scrollbar.pack(side='right', fill='y', expand=False)
306+
text.pack(side='left', fill='both', expand=True)
307+
259308
test_list = [] # List of tuples of the form (spec, callable widget)
260309
if tests:
261310
for test in tests:
@@ -272,22 +321,24 @@ def run(*tests):
272321
test = getattr(mod, test_name)
273322
test_list.append((test_spec, test))
274323

275-
help_string = tk.StringVar('')
276324
test_name = tk.StringVar('')
277325
callable_object = None
278326
test_kwds = None
279327

280-
281328
def next():
282-
nonlocal help_string, test_name, callable_object, test_kwds
329+
330+
nonlocal test_name, callable_object, test_kwds
283331
if len(test_list) == 1:
284332
next_button.pack_forget()
285333
test_spec, callable_object = test_list.pop()
286334
test_kwds = test_spec['kwds']
287335
test_kwds['parent'] = root
288-
help_string.set(test_spec['msg'])
289336
test_name.set('Test ' + test_spec['name'])
290337

338+
text.configure(state='normal') # enable text editing
339+
text.delete('1.0','end')
340+
text.insert("1.0",test_spec['msg'])
341+
text.configure(state='disabled') # preserve read-only property
291342

292343
def run_test():
293344
widget = callable_object(**test_kwds)
@@ -296,8 +347,6 @@ def run_test():
296347
except AttributeError:
297348
pass
298349

299-
label = tk.Label(root, textvariable=help_string, justify='left')
300-
label.pack()
301350
button = tk.Button(root, textvariable=test_name, command=run_test)
302351
button.pack()
303352
next_button = tk.Button(root, text="Next", command=next)

0 commit comments

Comments
 (0)