Skip to content

Commit 36ad8e6

Browse files
[3.11] gh-66819: More IDLE htest updates(2) (GH-112642) (#112644)
Examine and update spec -- callable pairs. Revise run method. (cherry picked from commit 3855b45) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
1 parent 3d87a98 commit 36ad8e6

File tree

9 files changed

+70
-69
lines changed

9 files changed

+70
-69
lines changed

Lib/idlelib/browser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,5 +254,6 @@ class Nested_in_closure: pass
254254
if len(sys.argv) == 1: # If pass file on command line, unittest fails.
255255
from unittest import main
256256
main('idlelib.idle_test.test_browser', verbosity=2, exit=False)
257+
257258
from idlelib.idle_test.htest import run
258259
run(_module_browser)

Lib/idlelib/debugobj.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def make_objecttreeitem(labeltext, object, setfunction=None):
120120
return c(labeltext, object, setfunction)
121121

122122

123-
def _object_browser(parent): # htest #
123+
def _debug_object_browser(parent): # htest #
124124
import sys
125125
from tkinter import Toplevel
126126
top = Toplevel(parent)
@@ -140,4 +140,4 @@ def _object_browser(parent): # htest #
140140
main('idlelib.idle_test.test_debugobj', verbosity=2, exit=False)
141141

142142
from idlelib.idle_test.htest import run
143-
run(_object_browser)
143+
run(_debug_object_browser)

Lib/idlelib/idle_test/htest.py

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
99
In a tested module, let X be a global name bound to a callable (class or
1010
function) whose .__name__ attribute is also X (the usual situation). The
11-
first parameter of X must be 'parent'. When called, the parent argument
12-
will be the root window. X must create a child Toplevel(parent) window
13-
(or subclass thereof). The Toplevel may be a test widget or dialog, in
14-
which case the callable is the corresponding class. Or the Toplevel may
15-
contain the widget to be tested or set up a context in which a test
16-
widget is invoked. In this latter case, the callable is a wrapper
17-
function that sets up the Toplevel and other objects. Wrapper function
18-
names, such as _editor_window', should start with '_' and be lowercase.
11+
first parameter of X must be 'parent' or 'master'. When called, the
12+
first argument will be the root window. X must create a child
13+
Toplevel(parent/master) (or subclass thereof). The Toplevel may be a
14+
test widget or dialog, in which case the callable is the corresponding
15+
class. Or the Toplevel may contain the widget to be tested or set up a
16+
context in which a test widget is invoked. In this latter case, the
17+
callable is a wrapper function that sets up the Toplevel and other
18+
objects. Wrapper function names, such as _editor_window', should start
19+
with '_' and be lowercase.
1920
2021
2122
End the module with
@@ -117,12 +118,20 @@
117118
'file': 'query',
118119
'kwds': {'title': 'Customize query.py Run',
119120
'_htest': True},
120-
'msg': "Enter with <Return> or [Run]. Print valid entry to Shell\n"
121+
'msg': "Enter with <Return> or [OK]. Print valid entry to Shell\n"
121122
"Arguments are parsed into a list\n"
122123
"Mode is currently restart True or False\n"
123124
"Close dialog with valid entry, <Escape>, [Cancel], [X]"
124125
}
125126

127+
_debug_object_browser_spec = {
128+
'file': 'debugobj',
129+
'kwds': {},
130+
'msg': "Double click on items up to the lowest level.\n"
131+
"Attributes of the objects and related information "
132+
"will be displayed side-by-side at each level."
133+
}
134+
126135
# TODO Improve message
127136
_dyn_option_menu_spec = {
128137
'file': 'dynoption',
@@ -178,7 +187,7 @@
178187
"Any url ('www...', 'http...') is accepted.\n"
179188
"Test Browse with and without path, as cannot unittest.\n"
180189
"[Ok] or <Return> prints valid entry to shell\n"
181-
"[Cancel] or <Escape> prints None to shell"
190+
"<Escape>, [Cancel], or [X] prints None to shell"
182191
}
183192

184193
_io_binding_spec = {
@@ -199,60 +208,51 @@
199208
'kwds': {},
200209
'msg': textwrap.dedent("""\
201210
1. Click on the line numbers and drag down below the edge of the
202-
window, moving the mouse a bit and then leaving it there for a while.
203-
The text and line numbers should gradually scroll down, with the
204-
selection updated continuously.
211+
window, moving the mouse a bit and then leaving it there for a
212+
while. The text and line numbers should gradually scroll down,
213+
with the selection updated continuously.
205214
206-
2. With the lines still selected, click on a line number above the
207-
selected lines. Only the line whose number was clicked should be
208-
selected.
215+
2. With the lines still selected, click on a line number above
216+
or below the selected lines. Only the line whose number was
217+
clicked should be selected.
209218
210-
3. Repeat step #1, dragging to above the window. The text and line
211-
numbers should gradually scroll up, with the selection updated
212-
continuously.
219+
3. Repeat step #1, dragging to above the window. The text and
220+
line numbers should gradually scroll up, with the selection
221+
updated continuously.
213222
214223
4. Repeat step #2, clicking a line number below the selection."""),
215224
}
216225

217226
_multi_call_spec = {
218227
'file': 'multicall',
219228
'kwds': {},
220-
'msg': "The following actions should trigger a print to console or IDLE"
221-
" Shell.\nEntering and leaving the text area, key entry, "
222-
"<Control-Key>,\n<Alt-Key-a>, <Control-Key-a>, "
223-
"<Alt-Control-Key-a>, \n<Control-Button-1>, <Alt-Button-1> and "
224-
"focusing out of the window\nare sequences to be tested."
229+
'msg': "The following should trigger a print to console or IDLE Shell.\n"
230+
"Entering and leaving the text area, key entry, <Control-Key>,\n"
231+
"<Alt-Key-a>, <Control-Key-a>, <Alt-Control-Key-a>, \n"
232+
"<Control-Button-1>, <Alt-Button-1> and focusing elsewhere."
225233
}
226234

227235
_module_browser_spec = {
228236
'file': 'browser',
229237
'kwds': {},
230-
'msg': "Inspect names of module, class(with superclass if "
231-
"applicable), methods and functions.\nToggle nested items.\n"
232-
"Double clicking on items prints a traceback for an exception "
233-
"that is ignored."
238+
'msg': textwrap.dedent("""
239+
"Inspect names of module, class(with superclass if applicable),
240+
"methods and functions. Toggle nested items. Double clicking
241+
"on items prints a traceback for an exception that is ignored.""")
234242
}
235243

236244
_multistatus_bar_spec = {
237245
'file': 'statusbar',
238246
'kwds': {},
239247
'msg': "Ensure presence of multi-status bar below text area.\n"
240-
"Click 'Update Status' to change the multi-status text"
241-
}
242-
243-
_object_browser_spec = {
244-
'file': 'debugobj',
245-
'kwds': {},
246-
'msg': "Double click on items up to the lowest level.\n"
247-
"Attributes of the objects and related information "
248-
"will be displayed side-by-side at each level."
248+
"Click 'Update Status' to change the status text"
249249
}
250250

251-
_path_browser_spec = {
251+
PathBrowser_spec = {
252252
'file': 'pathbrowser',
253-
'kwds': {},
253+
'kwds': {'_htest': True},
254254
'msg': "Test for correct display of all paths in sys.path.\n"
255-
"Toggle nested items up to the lowest level.\n"
255+
"Toggle nested items out to the lowest level.\n"
256256
"Double clicking on an item prints a traceback\n"
257257
"for an exception that is ignored."
258258
}
@@ -367,11 +367,12 @@
367367
}
368368

369369
def run(*tests):
370+
"Run callables in tests."
370371
root = tk.Tk()
371372
root.title('IDLE htest')
372373
root.resizable(0, 0)
373374

374-
# a scrollable Label like constant width text widget.
375+
# A scrollable Label-like constant width text widget.
375376
frameLabel = tk.Frame(root, padx=10)
376377
frameLabel.pack()
377378
text = tk.Text(frameLabel, wrap='word')
@@ -381,45 +382,44 @@ def run(*tests):
381382
scrollbar.pack(side='right', fill='y', expand=False)
382383
text.pack(side='left', fill='both', expand=True)
383384

384-
test_list = [] # List of tuples of the form (spec, callable widget)
385+
test_list = [] # Make list of (spec, callable) tuples.
385386
if tests:
386387
for test in tests:
387388
test_spec = globals()[test.__name__ + '_spec']
388389
test_spec['name'] = test.__name__
389390
test_list.append((test_spec, test))
390391
else:
391-
for k, d in globals().items():
392-
if k.endswith('_spec'):
393-
test_name = k[:-5]
394-
test_spec = d
392+
for key, dic in globals().items():
393+
if key.endswith('_spec'):
394+
test_name = key[:-5]
395+
test_spec = dic
395396
test_spec['name'] = test_name
396397
mod = import_module('idlelib.' + test_spec['file'])
397398
test = getattr(mod, test_name)
398399
test_list.append((test_spec, test))
400+
test_list.reverse() # So can pop in proper order in next_test.
399401

400402
test_name = tk.StringVar(root)
401403
callable_object = None
402404
test_kwds = None
403405

404406
def next_test():
405-
406407
nonlocal test_name, callable_object, test_kwds
407408
if len(test_list) == 1:
408409
next_button.pack_forget()
409410
test_spec, callable_object = test_list.pop()
410411
test_kwds = test_spec['kwds']
411-
test_kwds['parent'] = root
412412
test_name.set('Test ' + test_spec['name'])
413413

414-
text.configure(state='normal') # enable text editing
415-
text.delete('1.0','end')
416-
text.insert("1.0",test_spec['msg'])
417-
text.configure(state='disabled') # preserve read-only property
414+
text['state'] = 'normal' # Enable text replacement.
415+
text.delete('1.0', 'end')
416+
text.insert("1.0", test_spec['msg'])
417+
text['state'] = 'disabled' # Restore read-only property.
418418

419419
def run_test(_=None):
420-
widget = callable_object(**test_kwds)
420+
widget = callable_object(root, **test_kwds)
421421
try:
422-
print(widget.result)
422+
print(widget.result) # Only true for query classes(?).
423423
except AttributeError:
424424
pass
425425

Lib/idlelib/iomenu.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,11 @@ def updaterecentfileslist(self,filename):
396396
def _io_binding(parent): # htest #
397397
from tkinter import Toplevel, Text
398398

399-
root = Toplevel(parent)
400-
root.title("Test IOBinding")
399+
top = Toplevel(parent)
400+
top.title("Test IOBinding")
401401
x, y = map(int, parent.geometry().split('+')[1:])
402-
root.geometry("+%d+%d" % (x, y + 175))
402+
top.geometry("+%d+%d" % (x, y + 175))
403+
403404
class MyEditWin:
404405
def __init__(self, text):
405406
self.text = text
@@ -423,7 +424,7 @@ def saveas(self, event):
423424
def savecopy(self, event):
424425
self.text.event_generate("<<save-copy-of-window-as-file>>")
425426

426-
text = Text(root)
427+
text = Text(top)
427428
text.pack()
428429
text.focus_set()
429430
editwin = MyEditWin(text)

Lib/idlelib/multicall.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ def _multi_call(parent): # htest #
421421
top.geometry("+%d+%d" % (x, y + 175))
422422
text = MultiCallCreator(tkinter.Text)(top)
423423
text.pack()
424+
text.focus_set()
425+
424426
def bindseq(seq, n=[0]):
425427
def handler(event):
426428
print(seq)

Lib/idlelib/pathbrowser.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,9 @@ def listmodules(self, allnames):
9999
return sorted
100100

101101

102-
def _path_browser(parent): # htest #
103-
PathBrowser(parent, _htest=True)
104-
parent.mainloop()
105-
106102
if __name__ == "__main__":
107103
from unittest import main
108104
main('idlelib.idle_test.test_pathbrowser', verbosity=2, exit=False)
109105

110106
from idlelib.idle_test.htest import run
111-
run(_path_browser)
107+
run(PathBrowser)

Lib/idlelib/query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def create_extra(self):
368368
sticky='we')
369369

370370
def cli_args_ok(self):
371-
"Validity check and parsing for command line arguments."
371+
"Return command line arg list or None if error."
372372
cli_string = self.entry.get().strip()
373373
try:
374374
cli_args = shlex.split(cli_string, posix=True)

Lib/idlelib/sidebar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,13 @@ def update_colors(self):
517517
def _linenumbers_drag_scrolling(parent): # htest #
518518
from idlelib.idle_test.test_sidebar import Dummy_editwin
519519

520-
toplevel = tk.Toplevel(parent)
521-
text_frame = tk.Frame(toplevel)
520+
top = tk.Toplevel(parent)
521+
text_frame = tk.Frame(top)
522522
text_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
523523
text_frame.rowconfigure(1, weight=1)
524524
text_frame.columnconfigure(1, weight=1)
525525

526-
font = idleConf.GetFont(toplevel, 'main', 'EditorWindow')
526+
font = idleConf.GetFont(top, 'main', 'EditorWindow')
527527
text = tk.Text(text_frame, width=80, height=24, wrap=tk.NONE, font=font)
528528
text.grid(row=1, column=1, sticky=tk.NSEW)
529529

Lib/idlelib/statusbar.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def _multistatus_bar(parent): # htest #
2626
x, y = map(int, parent.geometry().split('+')[1:])
2727
top.geometry("+%d+%d" %(x, y + 175))
2828
top.title("Test multistatus bar")
29+
2930
frame = Frame(top)
3031
text = Text(frame, height=5, width=40)
3132
text.pack()

0 commit comments

Comments
 (0)