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

Skip to content

Commit a2fc99e

Browse files
committed
Issue #21477: Idle htest: modify run; add more tests.
Patch by Saimadhav Heblikar. 2.7 version will follow.
1 parent e1d54e5 commit a2fc99e

9 files changed

Lines changed: 160 additions & 79 deletions

File tree

Lib/idlelib/ClassBrowser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import os
1414
import sys
1515
import pyclbr
16-
import re
1716

1817
from idlelib import PyShell
1918
from idlelib.WindowList import ListedToplevel
@@ -223,6 +222,7 @@ def _class_browser(parent): #Wrapper for htest
223222
name = os.path.splitext(file)[0]
224223
flist = PyShell.PyShellFileList(parent)
225224
ClassBrowser(flist, name, [dir], _htest=True)
225+
parent.mainloop()
226226

227227
if __name__ == "__main__":
228228
from idlelib.idle_test.htest import run

Lib/idlelib/ColorDelegator.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,9 @@ def _color_delegator(parent):
259259
root.title("Test ColorDelegator")
260260
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
261261
root.geometry("+%d+%d"%(x, y + 150))
262-
with open(__file__, 'r') as f:
263-
source = f.read()
262+
source = "if somename: x = 'abc' # comment\nprint"
264263
text = Text(root, background="white")
265-
# insert only a sample portion
266-
text.insert("insert", source[:690])
264+
text.insert("insert", source)
267265
text.pack(expand=1, fill="both")
268266
p = Percolator(text)
269267
d = ColorDelegator()

Lib/idlelib/EditorWindow.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,18 +1705,15 @@ def fixwordbreaks(root):
17051705
def _editor_window(parent):
17061706
root = parent
17071707
fixwordbreaks(root)
1708-
## root.withdraw()
17091708
if sys.argv[1:]:
17101709
filename = sys.argv[1]
17111710
else:
17121711
filename = None
17131712
macosxSupport.setupApp(root, None)
17141713
edit = EditorWindow(root=root, filename=filename)
1715-
## edit.set_close_hook(root.quit)
1716-
## edit.text.bind("<<close-all-windows>>", edit.close_event)
1714+
edit.text.bind("<<close-all-windows>>", edit.close_event)
1715+
parent.mainloop()
17171716

17181717
if __name__ == '__main__':
17191718
from idlelib.idle_test.htest import run
1720-
if len(sys.argv) <= 1:
1721-
run(_help_dialog)
1722-
run(_editor_window)
1719+
run(_help_dialog, _editor_window)

Lib/idlelib/PathBrowser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import sys
3-
import re
43
import importlib.machinery
54

65
from idlelib.TreeWidget import TreeItem
@@ -97,6 +96,7 @@ def listmodules(self, allnames):
9796
def _path_browser(parent):
9897
flist = PyShellFileList(parent)
9998
PathBrowser(flist, _htest=True)
99+
parent.mainloop()
100100

101101
if __name__ == "__main__":
102102
from unittest import main

Lib/idlelib/Percolator.py

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ def removefilter(self, filter):
5151
f.setdelegate(filter.delegate)
5252
filter.setdelegate(None)
5353

54-
def main():
55-
import tkinter as Tk
54+
def _percolator(parent):
55+
import tkinter as tk
56+
import re
5657
class Tracer(Delegator):
5758
def __init__(self, name):
5859
self.name = name
@@ -63,22 +64,41 @@ def insert(self, *args):
6364
def delete(self, *args):
6465
print(self.name, ": delete", args)
6566
self.delegate.delete(*args)
66-
root = Tk.Tk()
67-
root.wm_protocol("WM_DELETE_WINDOW", root.quit)
68-
text = Tk.Text()
69-
text.pack()
70-
text.focus_set()
67+
root = tk.Tk()
68+
root.title("Test Percolator")
69+
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
70+
root.geometry("+%d+%d"%(x, y + 150))
71+
text = tk.Text(root)
7172
p = Percolator(text)
7273
t1 = Tracer("t1")
7374
t2 = Tracer("t2")
74-
p.insertfilter(t1)
75-
p.insertfilter(t2)
76-
root.mainloop() # click close widget to continue...
77-
p.removefilter(t2)
78-
root.mainloop()
79-
p.insertfilter(t2)
80-
p.removefilter(t1)
75+
76+
def toggle1():
77+
if var1.get() == 0:
78+
var1.set(1)
79+
p.insertfilter(t1)
80+
elif var1.get() == 1:
81+
var1.set(0)
82+
p.removefilter(t1)
83+
84+
def toggle2():
85+
if var2.get() == 0:
86+
var2.set(1)
87+
p.insertfilter(t2)
88+
elif var2.get() == 1:
89+
var2.set(0)
90+
p.removefilter(t2)
91+
92+
text.pack()
93+
var1 = tk.IntVar()
94+
cb1 = tk.Checkbutton(root, text="Tracer1", command=toggle1, variable=var1)
95+
cb1.pack()
96+
var2 = tk.IntVar()
97+
cb2 = tk.Checkbutton(root, text="Tracer2", command=toggle2, variable=var2)
98+
cb2.pack()
99+
81100
root.mainloop()
82101

83102
if __name__ == "__main__":
84-
main()
103+
from idlelib.idle_test.htest import run
104+
run(_percolator)

Lib/idlelib/StackViewer.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import os
22
import sys
33
import linecache
4+
import re
5+
import tkinter as tk
46

57
from idlelib.TreeWidget import TreeNode, TreeItem, ScrolledCanvas
68
from idlelib.ObjectBrowser import ObjectTreeItem, make_objecttreeitem
9+
from idlelib.PyShell import PyShellFileList
710

811
def StackBrowser(root, flist=None, tb=None, top=None):
912
if top is None:
@@ -120,3 +123,30 @@ def setfunction(value, key=key, object=self.object):
120123
item = make_objecttreeitem(key + " =", value, setfunction)
121124
sublist.append(item)
122125
return sublist
126+
127+
def _stack_viewer(parent):
128+
root = tk.Tk()
129+
root.title("Test StackViewer")
130+
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
131+
root.geometry("+%d+%d"%(x, y + 150))
132+
flist = PyShellFileList(root)
133+
try: # to obtain a traceback object
134+
a
135+
except:
136+
exc_type, exc_value, exc_tb = sys.exc_info()
137+
138+
# inject stack trace to sys
139+
sys.last_type = exc_type
140+
sys.last_value = exc_value
141+
sys.last_traceback = exc_tb
142+
143+
StackBrowser(root, flist=flist, top=root, tb=exc_tb)
144+
145+
# restore sys to original state
146+
del sys.last_type
147+
del sys.last_value
148+
del sys.last_traceback
149+
150+
if __name__ == '__main__':
151+
from idlelib.idle_test.htest import run
152+
run(_stack_viewer)

Lib/idlelib/ToolTip.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ def _tooltip(parent):
8787
button2 = Button(root, text="Button 2")
8888
button1.pack()
8989
button2.pack()
90-
ToolTip(button1, "This is calltip text for button1.")
91-
ListboxToolTip(button2, ["This is","calltip text","for button2"])
90+
ToolTip(button1, "This is tooltip text for button1.")
91+
ListboxToolTip(button2, ["This is","multiple line",
92+
"tooltip text","for button2"])
9293
root.mainloop()
9394

9495
if __name__ == '__main__':

Lib/idlelib/idle_test/htest.py

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@
5353
'file': 'ClassBrowser',
5454
'kwds': {},
5555
'msg': "Inspect names of module, class(with superclass if "
56-
"applicable), methods and functions.\nToggle nested items."
57-
"\nN.S: Double click on items does not work",
56+
"applicable), methods and functions.\nToggle nested items.\n"
57+
"Double clicking on items prints a traceback print a traceback "
58+
"for an exception that is ignored."
5859
}
5960

6061
_color_delegator_spec = {
@@ -74,11 +75,11 @@
7475
"Select one of the many options in the 'new option set'."
7576
}
7677

77-
#_editor_window_spec = {
78-
# 'file': 'EditorWindow',
79-
# 'kwds': {},
80-
# 'msg': "Test editor functions of interest"
81-
# }
78+
_editor_window_spec = {
79+
'file': 'EditorWindow',
80+
'kwds': {},
81+
'msg': "Test editor functions of interest."
82+
}
8283

8384
GetCfgSectionNameDialog_spec = {
8485
'file': 'configSectionNameDialog',
@@ -91,6 +92,7 @@
9192
"Close 'Get Name' with a valid entry (printed to Shell), "
9293
"[Cancel], or [X]",
9394
}
95+
9496
GetHelpSourceDialog_spec = {
9597
'file': 'configHelpSourceEdit',
9698
'kwds': {'title': 'Get helpsource',
@@ -103,10 +105,27 @@
103105
"[Cancel] will print None to shell",
104106
}
105107

108+
# Update once issue21519 is resolved.
109+
GetKeysDialog_spec = {
110+
'file': 'keybindingDialog',
111+
'kwds': {'title': 'Test keybindings',
112+
'action': 'find-again',
113+
'currentKeySequences': [''] ,
114+
'_htest': True,
115+
},
116+
'msg': "Test for different key modifier sequences.\n"
117+
"<nothing> is invalid.\n"
118+
"No modifier key is invalid.\n"
119+
"Shift key with [a-z],[0-9], function key, move key, tab, space"
120+
"is invalid.\nNo validitity checking if advanced key binding "
121+
"entry is used."
122+
}
123+
106124
_help_dialog_spec = {
107125
'file': 'EditorWindow',
108126
'kwds': {},
109-
'msg': "If the help text displays, this works"
127+
'msg': "If the help text displays, this works.\n"
128+
"Text is selectable. Window is scrollable."
110129
}
111130

112131
_io_binding_spec = {
@@ -115,17 +134,16 @@
115134
'msg': "Test the following bindings\n"
116135
"<Control-o> to display open window from file dialog.\n"
117136
"<Control-s> to save the file\n"
118-
119137
}
120138

121139
_multi_call_spec = {
122140
'file': 'MultiCall',
123141
'kwds': {},
124-
'msg': "The following actions should trigger a print to console.\n"
125-
"Entering and leaving the text area, key entry, <Control-Key>,\n"
126-
"<Alt-Key-a>, <Control-Key-a>, <Alt-Control-Key-a>, \n"
127-
"<Control-Button-1>, <Alt-Button-1> and focussing out of the window\n"
128-
"are sequences to be tested."
142+
'msg': "The following actions should trigger a print to console or IDLE"
143+
" Shell.\nEntering and leaving the text area, key entry, "
144+
"<Control-Key>,\n<Alt-Key-a>, <Control-Key-a>, "
145+
"<Alt-Control-Key-a>, \n<Control-Button-1>, <Alt-Button-1> and "
146+
"focusing out of the window\nare sequences to be tested."
129147
}
130148

131149
_multistatus_bar_spec = {
@@ -146,18 +164,38 @@
146164
_path_browser_spec = {
147165
'file': 'PathBrowser',
148166
'kwds': {},
149-
'msg': "Test for correct display of all paths in sys.path."
150-
"\nToggle nested items upto the lowest level."
151-
"\nN.S: Double click on items does not work."
167+
'msg': "Test for correct display of all paths in sys.path.\n"
168+
"Toggle nested items upto the lowest level.\n"
169+
"Double clicking on an item prints a traceback\n"
170+
"for an exception that is ignored."
171+
}
172+
173+
_percolator_spec = {
174+
'file': 'Percolator',
175+
'kwds': {},
176+
'msg': "There are two tracers which can be toggled using a checkbox.\n"
177+
"Toggling a tracer 'on' by checking it should print tracer"
178+
"output to the console or to the IDLE shell.\n"
179+
"If both the tracers are 'on', the output from the tracer which "
180+
"was switched 'on' later, should be printed first\n"
181+
"Test for actions like text entry, and removal."
152182
}
153183

154184
_scrolled_list_spec = {
155185
'file': 'ScrolledList',
156186
'kwds': {},
157187
'msg': "You should see a scrollable list of items\n"
158-
"Selecting an item will print it to console.\n"
159-
"Double clicking an item will print it to console\n"
160-
"Right click on an item will display a popup."
188+
"Selecting (clicking) or double clicking an item "
189+
"prints the name to the console or Idle shell.\n"
190+
"Right clicking an item will display a popup."
191+
}
192+
193+
_stack_viewer_spec = {
194+
'file': 'StackViewer',
195+
'kwds': {},
196+
'msg': "A stacktrace for a NameError exception.\n"
197+
"Expand 'idlelib ...' and '<locals>'.\n"
198+
"Check that exc_value, exc_tb, and exc_type are correct.\n"
161199
}
162200

163201
_tabbed_pages_spec = {
@@ -189,7 +227,7 @@
189227
_tree_widget_spec = {
190228
'file': 'TreeWidget',
191229
'kwds': {},
192-
'msg': "You should see two canvas' side-by-side.\n"
230+
'msg': "You should see two canvases side-by-side.\n"
193231
"The left canvas is scrollable.\n"
194232
"The right canvas is not scrollable.\n"
195233
"Click on folders upto to the lowest level."
@@ -198,29 +236,27 @@
198236
_widget_redirector_spec = {
199237
'file': 'WidgetRedirector',
200238
'kwds': {},
201-
'msg': "Every text insert should be printed to console."
239+
'msg': "Every text insert should be printed to the console."
240+
"or the IDLE shell."
202241
}
203242

204-
def run(test=None):
243+
def run(*tests):
205244
root = tk.Tk()
206-
test_list = [] # List of tuples of the form (spec, kwds, callable widget)
207-
if test:
208-
test_spec = globals()[test.__name__ + '_spec']
209-
test_spec['name'] = test.__name__
210-
test_kwds = test_spec['kwds']
211-
test_kwds['parent'] = root
212-
test_list.append((test_spec, test_kwds, test))
245+
test_list = [] # List of tuples of the form (spec, callable widget)
246+
if tests:
247+
for test in tests:
248+
test_spec = globals()[test.__name__ + '_spec']
249+
test_spec['name'] = test.__name__
250+
test_list.append((test_spec, test))
213251
else:
214252
for k, d in globals().items():
215253
if k.endswith('_spec'):
216254
test_name = k[:-5]
217255
test_spec = d
218256
test_spec['name'] = test_name
219-
test_kwds = test_spec['kwds']
220-
test_kwds['parent'] = root
221257
mod = import_module('idlelib.' + test_spec['file'])
222258
test = getattr(mod, test_name)
223-
test_list.append((test_spec, test_kwds, test))
259+
test_list.append((test_spec, test))
224260

225261
help_string = tk.StringVar('')
226262
test_name = tk.StringVar('')
@@ -232,10 +268,11 @@ def next():
232268
nonlocal help_string, test_name, callable_object, test_kwds
233269
if len(test_list) == 1:
234270
next_button.pack_forget()
235-
test_spec, test_kwds, test = test_list.pop()
271+
test_spec, callable_object = test_list.pop()
272+
test_kwds = test_spec['kwds']
273+
test_kwds['parent'] = root
236274
help_string.set(test_spec['msg'])
237-
test_name.set('test ' + test_spec['name'])
238-
callable_object = test
275+
test_name.set('Test ' + test_spec['name'])
239276

240277

241278
def run_test():

0 commit comments

Comments
 (0)