88
99In a tested module, let X be a global name bound to a callable (class or
1010function) 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
2122End the module with
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' ,
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 = {
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.\n Entering 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\n are 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. \n Toggle 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 }
367367 }
368368
369369def 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
0 commit comments