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

Skip to content

Commit b96ebd4

Browse files
committed
Merge with 3.4
2 parents 0dfce56 + 6936159 commit b96ebd4

1 file changed

Lines changed: 32 additions & 29 deletions

File tree

Lib/idlelib/idle_test/htest.py

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
1-
'''Run a human test of Idle wndow, dialog, and other widget classes.
1+
'''Run human tests of Idle's window, dialog, and popup widgets.
22
3-
run(klass) runs a test for one class.
4-
runall() runs all the defined tests
3+
run(test): run *test*, a callable that causes a widget to be displayed.
4+
runall(): run all tests defined in this file.
5+
6+
Let X be a global name bound to a widget callable. End the module with
57
6-
The file wih the widget class should end with
78
if __name__ == '__main__':
89
<unittest, if there is one>
910
from idlelib.idle_test.htest import run
1011
run(X)
11-
where X is a global object of the module. X must be a callable with a
12-
.__name__ attribute that accepts a 'parent' attribute. X will usually be
13-
a widget class, but a callable instance with .__name__ or a wrapper
14-
function also work. The name of wrapper functions, like _Editor_Window,
15-
should start with '_'.
1612
17-
This file must then contain an instance of this template.
13+
The X object must have a .__name__ attribute and a 'parent' parameter.
14+
X will often be a widget class, but a callable instance with .__name__
15+
or a wrapper function also work. The name of wrapper functions, like
16+
'_Editor_Window', should start with '_'.
17+
18+
This file must contain a matching instance of the folling template,
19+
with X.__name__ prepended, as in '_Editor_window_spec ...'.
20+
1821
_spec = {
1922
'file': '',
2023
'kwds': {'title': ''},
2124
'msg': ""
2225
}
23-
with X.__name__ prepended to _spec.
24-
File (no .py) is used in runall() to import the file and get the class.
25-
Kwds is passed to X (**kwds) after 'parent' is added, to initialize X.
26-
Msg. displayed is a window with a start button. hint as to how the user
27-
might test the widget. Closing The box skips or ends the test.
26+
27+
file (no .py): used in runall() to import the file and get X.
28+
kwds: passed to X (**kwds), after 'parent' is added, to initialize X.
29+
title: an example; used for some widgets, delete if not.
30+
msg: displayed in a master window. Hints as to how the user might
31+
test the widget. Close the window to skip or end the test.
2832
'''
2933
from importlib import import_module
3034
import tkinter as tk
3135

32-
# Template for class_spec dicts, copy and uncomment
3336

3437
_Editor_window_spec = {
3538
'file': 'EditorWindow',
@@ -61,30 +64,30 @@
6164
"Close 'Get Name' with a valid entry (printed to Shell), [Cancel], or [X]",
6265
}
6366

64-
def run(klas):
65-
"Test the widget class klas using _spec dict"
67+
def run(test):
68+
"Display a widget with callable *test* using a _spec dict"
6669
root = tk.Tk()
67-
klas_spec = globals()[klas.__name__+'_spec']
68-
klas_kwds = klas_spec['kwds']
69-
klas_kwds['parent'] = root
70-
# This presumes that Idle consistently uses 'parent'
71-
def run_klas():
72-
widget = klas(**klas_kwds)
70+
test_spec = globals()[test.__name__ + '_spec']
71+
test_kwds = test_spec['kwds']
72+
test_kwds['parent'] = root
73+
74+
def run_test():
75+
widget = test(**test_kwds)
7376
try:
7477
print(widget.result)
7578
except AttributeError:
7679
pass
77-
tk.Label(root, text=klas_spec['msg'], justify='left').pack()
78-
tk.Button(root, text='Test ' + klas.__name__, command=run_klas).pack()
80+
tk.Label(root, text=test_spec['msg'], justify='left').pack()
81+
tk.Button(root, text='Test ' + test.__name__, command=run_test).pack()
7982
root.mainloop()
8083

8184
def runall():
82-
'Run all tests. Quick and dirty version.'
85+
"Run all tests. Quick and dirty version."
8386
for k, d in globals().items():
8487
if k.endswith('_spec'):
8588
mod = import_module('idlelib.' + d['file'])
86-
klas = getattr(mod, k[:-5])
87-
run(klas)
89+
test = getattr(mod, k[:-5])
90+
run(test)
8891

8992
if __name__ == '__main__':
9093
runall()

0 commit comments

Comments
 (0)