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

Skip to content

Commit 1b392ff

Browse files
committed
Issue #21477: Idle htest: merge and modify run and runall; add many tests.
Patch by Saimadhav Heblikar
1 parent 10cbb1e commit 1b392ff

18 files changed

Lines changed: 414 additions & 181 deletions

Lib/idlelib/CallTipWindow.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -133,37 +133,36 @@ def is_active(self):
133133
return bool(self.tipwindow)
134134

135135

136+
def _calltip_window(parent):
137+
root = Tk()
138+
root.title("Test calltips")
139+
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
140+
root.geometry("+%d+%d"%(x, y + 150))
136141

137-
###############################
138-
#
139-
# Test Code
140-
#
141-
class container: # Conceptually an editor_window
142-
def __init__(self):
143-
root = Tk()
144-
text = self.text = Text(root)
145-
text.pack(side=LEFT, fill=BOTH, expand=1)
146-
text.insert("insert", "string.split")
147-
root.update()
148-
self.calltip = CallTip(text)
149-
150-
text.event_add("<<calltip-show>>", "(")
151-
text.event_add("<<calltip-hide>>", ")")
152-
text.bind("<<calltip-show>>", self.calltip_show)
153-
text.bind("<<calltip-hide>>", self.calltip_hide)
154-
155-
text.focus_set()
156-
root.mainloop()
157-
158-
def calltip_show(self, event):
159-
self.calltip.showtip("Hello world")
160-
161-
def calltip_hide(self, event):
162-
self.calltip.hidetip()
163-
164-
def main():
165-
# Test code
166-
c=container()
142+
class MyEditWin: # comparenceptually an editor_window
143+
def __init__(self):
144+
text = self.text = Text(root)
145+
text.pack(side=LEFT, fill=BOTH, expand=1)
146+
text.insert("insert", "string.split")
147+
root.update()
148+
self.calltip = CallTip(text)
149+
150+
text.event_add("<<calltip-show>>", "(")
151+
text.event_add("<<calltip-hide>>", ")")
152+
text.bind("<<calltip-show>>", self.calltip_show)
153+
text.bind("<<calltip-hide>>", self.calltip_hide)
154+
155+
text.focus_set()
156+
root.mainloop()
157+
158+
def calltip_show(self, event):
159+
self.calltip.showtip("Hello world", "insert", "end")
160+
161+
def calltip_hide(self, event):
162+
self.calltip.hidetip()
163+
164+
editwin = MyEditWin()
167165

168166
if __name__=='__main__':
169-
main()
167+
from idlelib.idle_test.htest import run
168+
run(_calltip_window)

Lib/idlelib/ClassBrowser.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import sys
1515
import pyclbr
16+
import re
1617

1718
from idlelib import PyShell
1819
from idlelib.WindowList import ListedToplevel
@@ -21,11 +22,15 @@
2122

2223
class ClassBrowser:
2324

24-
def __init__(self, flist, name, path):
25+
def __init__(self, flist, name, path, _htest=False):
2526
# XXX This API should change, if the file doesn't end in ".py"
2627
# XXX the code here is bogus!
28+
"""
29+
_htest - bool, change box when location running htest.
30+
"""
2731
self.name = name
2832
self.file = os.path.join(path[0], self.name + ".py")
33+
self._htest = _htest
2934
self.init(flist)
3035

3136
def close(self, event=None):
@@ -40,6 +45,9 @@ def init(self, flist):
4045
self.top = top = ListedToplevel(flist.root)
4146
top.protocol("WM_DELETE_WINDOW", self.close)
4247
top.bind("<Escape>", self.close)
48+
if self._htest: # place dialog below parent if running htest
49+
top.geometry("+%d+%d" %
50+
(flist.root.winfo_rootx(), flist.root.winfo_rooty() + 200))
4351
self.settitle()
4452
top.focus_set()
4553
# create scrolled canvas
@@ -202,7 +210,7 @@ def OnDoubleClick(self):
202210
edit = PyShell.flist.open(self.file)
203211
edit.gotoline(self.cl.methods[self.name])
204212

205-
def main():
213+
def _class_browser(parent): #Wrapper for htest
206214
try:
207215
file = __file__
208216
except NameError:
@@ -213,9 +221,9 @@ def main():
213221
file = sys.argv[0]
214222
dir, file = os.path.split(file)
215223
name = os.path.splitext(file)[0]
216-
ClassBrowser(PyShell.flist, name, [dir])
217-
if sys.stdin is sys.__stdin__:
218-
mainloop()
224+
flist = PyShell.PyShellFileList(parent)
225+
ClassBrowser(flist, name, [dir], _htest=True)
219226

220227
if __name__ == "__main__":
221-
main()
228+
from idlelib.idle_test.htest import run
229+
run(_class_browser)

Lib/idlelib/ColorDelegator.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,23 @@ def removecolors(self):
253253
for tag in self.tagdefs:
254254
self.tag_remove(tag, "1.0", "end")
255255

256-
def main():
256+
def _color_delegator(parent):
257257
from idlelib.Percolator import Percolator
258258
root = Tk()
259-
root.wm_protocol("WM_DELETE_WINDOW", root.quit)
260-
text = Text(background="white")
259+
root.title("Test ColorDelegator")
260+
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
261+
root.geometry("+%d+%d"%(x, y + 150))
262+
with open(__file__, 'r') as f:
263+
source = f.read()
264+
text = Text(root, background="white")
265+
# insert only a sample portion
266+
text.insert("insert", source[:690])
261267
text.pack(expand=1, fill="both")
262-
text.focus_set()
263268
p = Percolator(text)
264269
d = ColorDelegator()
265270
p.insertfilter(d)
266271
root.mainloop()
267272

268273
if __name__ == "__main__":
269-
main()
274+
from idlelib.idle_test.htest import run
275+
run(_color_delegator)

Lib/idlelib/IOBinding.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -525,33 +525,31 @@ def updaterecentfileslist(self,filename):
525525
if self.editwin.flist:
526526
self.editwin.update_recent_files_list(filename)
527527

528-
def test():
528+
def _io_binding(parent):
529529
root = Tk()
530+
root.title("Test IOBinding")
531+
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
532+
root.geometry("+%d+%d"%(x, y + 150))
530533
class MyEditWin:
531534
def __init__(self, text):
532535
self.text = text
533536
self.flist = None
534537
self.text.bind("<Control-o>", self.open)
535538
self.text.bind("<Control-s>", self.save)
536-
self.text.bind("<Alt-s>", self.save_as)
537-
self.text.bind("<Alt-z>", self.save_a_copy)
538539
def get_saved(self): return 0
539540
def set_saved(self, flag): pass
540541
def reset_undo(self): pass
541542
def open(self, event):
542543
self.text.event_generate("<<open-window-from-file>>")
543544
def save(self, event):
544545
self.text.event_generate("<<save-window>>")
545-
def save_as(self, event):
546-
self.text.event_generate("<<save-window-as-file>>")
547-
def save_a_copy(self, event):
548-
self.text.event_generate("<<save-copy-of-window-as-file>>")
546+
549547
text = Text(root)
550548
text.pack()
551549
text.focus_set()
552550
editwin = MyEditWin(text)
553551
io = IOBinding(editwin)
554-
root.mainloop()
555552

556553
if __name__ == "__main__":
557-
test()
554+
from idlelib.idle_test.htest import run
555+
run(_io_binding)

Lib/idlelib/MultiCall.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,12 @@ def __del__(self):
420420
_multicall_dict[widget] = MultiCall
421421
return MultiCall
422422

423-
if __name__ == "__main__":
424-
# Test
423+
424+
def _multi_call(parent):
425425
root = tkinter.Tk()
426+
root.title("Test MultiCall")
427+
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
428+
root.geometry("+%d+%d"%(x, y + 150))
426429
text = MultiCallCreator(tkinter.Text)(root)
427430
text.pack()
428431
def bindseq(seq, n=[0]):
@@ -438,8 +441,13 @@ def handler(event):
438441
bindseq("<Alt-Control-Key-a>")
439442
bindseq("<Key-b>")
440443
bindseq("<Control-Button-1>")
444+
bindseq("<Button-2>")
441445
bindseq("<Alt-Button-1>")
442446
bindseq("<FocusOut>")
443447
bindseq("<Enter>")
444448
bindseq("<Leave>")
445449
root.mainloop()
450+
451+
if __name__ == "__main__":
452+
from idlelib.idle_test.htest import run
453+
run(_multi_call)

Lib/idlelib/MultiStatusBar.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,29 @@ def set_label(self, name, text='', side=LEFT):
1717
label = self.labels[name]
1818
label.config(text=text)
1919

20-
def _test():
21-
b = Frame()
22-
c = Text(b)
23-
c.pack(side=TOP)
24-
a = MultiStatusBar(b)
25-
a.set_label("one", "hello")
26-
a.set_label("two", "world")
27-
a.pack(side=BOTTOM, fill=X)
28-
b.pack()
29-
b.mainloop()
20+
def _multistatus_bar(parent):
21+
root = Tk()
22+
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
23+
root.geometry("+%d+%d" %(x, y + 150))
24+
root.title("Test multistatus bar")
25+
frame = Frame(root)
26+
text = Text(frame)
27+
text.pack()
28+
msb = MultiStatusBar(frame)
29+
msb.set_label("one", "hello")
30+
msb.set_label("two", "world")
31+
msb.pack(side=BOTTOM, fill=X)
32+
33+
def change():
34+
msb.set_label("one", "foo")
35+
msb.set_label("two", "bar")
36+
37+
button = Button(root, text="Update status", command=change)
38+
button.pack(side=BOTTOM)
39+
frame.pack()
40+
frame.mainloop()
41+
root.mainloop()
3042

3143
if __name__ == '__main__':
32-
_test()
44+
from idlelib.idle_test.htest import run
45+
run(_multistatus_bar)

Lib/idlelib/ObjectBrowser.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# XXX TO DO:
1010
# - for classes/modules, add "open source" to object browser
1111

12+
import re
13+
1214
from idlelib.TreeWidget import TreeItem, TreeNode, ScrolledCanvas
1315

1416
from reprlib import Repr
@@ -119,12 +121,13 @@ def make_objecttreeitem(labeltext, object, setfunction=None):
119121
c = ObjectTreeItem
120122
return c(labeltext, object, setfunction)
121123

122-
# Test script
123124

124-
def _test():
125+
def _object_browser(parent):
125126
import sys
126127
from tkinter import Tk
127128
root = Tk()
129+
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
130+
root.geometry("+%d+%d"%(x, y + 100))
128131
root.configure(bd=0, bg="yellow")
129132
root.focus_set()
130133
sc = ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)
@@ -135,4 +138,5 @@ def _test():
135138
root.mainloop()
136139

137140
if __name__ == '__main__':
138-
_test()
141+
from idlelib.idle_test.htest import run
142+
run(_object_browser)

Lib/idlelib/PathBrowser.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import os
22
import sys
3+
import re
34
import importlib.machinery
45

56
from idlelib.TreeWidget import TreeItem
67
from idlelib.ClassBrowser import ClassBrowser, ModuleBrowserTreeItem
8+
from idlelib.PyShell import PyShellFileList
9+
710

811
class PathBrowser(ClassBrowser):
912

10-
def __init__(self, flist):
13+
def __init__(self, flist, _htest=False):
14+
"""
15+
_htest - bool, change box location when running htest
16+
"""
17+
self._htest = _htest
1118
self.init(flist)
1219

1320
def settitle(self):
@@ -87,12 +94,13 @@ def listmodules(self, allnames):
8794
sorted.sort()
8895
return sorted
8996

90-
def main():
91-
from idlelib import PyShell
92-
PathBrowser(PyShell.flist)
93-
if sys.stdin is sys.__stdin__:
94-
mainloop()
97+
def _path_browser(parent):
98+
flist = PyShellFileList(parent)
99+
PathBrowser(flist, _htest=True)
95100

96101
if __name__ == "__main__":
97102
from unittest import main
98103
main('idlelib.idle_test.test_pathbrowser', verbosity=2, exit=False)
104+
105+
from idlelib.idle_test.htest import run
106+
run(_path_browser)

Lib/idlelib/ScrolledList.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,22 @@ def on_double(self, index):
119119
pass
120120

121121

122-
def test():
122+
def _scrolled_list(parent):
123123
root = Tk()
124-
root.protocol("WM_DELETE_WINDOW", root.destroy)
124+
root.title("Test ScrolledList")
125+
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
126+
root.geometry("+%d+%d"%(x, y + 150))
125127
class MyScrolledList(ScrolledList):
126-
def fill_menu(self): self.menu.add_command(label="pass")
128+
def fill_menu(self): self.menu.add_command(label="right click")
127129
def on_select(self, index): print("select", self.get(index))
128130
def on_double(self, index): print("double", self.get(index))
129-
s = MyScrolledList(root)
131+
132+
scrolled_list = MyScrolledList(root)
130133
for i in range(30):
131-
s.append("item %02d" % i)
132-
return root
134+
scrolled_list.append("Item %02d" % i)
133135

134-
def main():
135-
root = test()
136136
root.mainloop()
137137

138138
if __name__ == '__main__':
139-
main()
139+
from idlelib.idle_test.htest import run
140+
run(_scrolled_list)

Lib/idlelib/ToolTip.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,21 @@ def showcontents(self):
7676
for item in self.items:
7777
listbox.insert(END, item)
7878

79-
def main():
80-
# Test code
79+
def _tooltip(parent):
8180
root = Tk()
82-
b = Button(root, text="Hello", command=root.destroy)
83-
b.pack()
84-
root.update()
85-
tip = ListboxToolTip(b, ["Hello", "world"])
81+
root.title("Test tooltip")
82+
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
83+
root.geometry("+%d+%d"%(x, y + 150))
84+
label = Label(root, text="Place your mouse over buttons")
85+
label.pack()
86+
button1 = Button(root, text="Button 1")
87+
button2 = Button(root, text="Button 2")
88+
button1.pack()
89+
button2.pack()
90+
ToolTip(button1, "This is calltip text for button1.")
91+
ListboxToolTip(button2, ["This is","calltip text","for button2"])
8692
root.mainloop()
8793

8894
if __name__ == '__main__':
89-
main()
95+
from idlelib.idle_test.htest import run
96+
run(_tooltip)

0 commit comments

Comments
 (0)