Issue #22629: Revise idle_test.htest, mostly docstring. Start revisi… · pythoncapi/cpython@cd56736 · GitHub
Skip to content

Commit cd56736

Browse files
committed
Issue python#22629: Revise idle_test.htest, mostly docstring. Start revision of
htests to add # htest # marker for coveragepy and stop tcl errors.
1 parent 9a6f8e1 commit cd56736

8 files changed

Lines changed: 112 additions & 82 deletions

File tree

Lib/idlelib/CallTipWindow.py

Lines changed: 21 additions & 31 deletions

Lib/idlelib/ClassBrowser.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
from idlelib.TreeWidget import TreeNode, TreeItem, ScrolledCanvas
2020
from idlelib.configHandler import idleConf
2121

22+
file_open = None # Method...Item and Class...Item use this.
23+
# Normally PyShell.flist.open, but there is no PyShell.flist for htest.
24+
2225
class ClassBrowser:
2326

2427
def __init__(self, flist, name, path, _htest=False):
@@ -27,6 +30,9 @@ def __init__(self, flist, name, path, _htest=False):
2730
"""
2831
_htest - bool, change box when location running htest.
2932
"""
33+
global file_open
34+
if not _htest:
35+
file_open = PyShell.flist.open
3036
self.name = name
3137
self.file = os.path.join(path[0], self.name + ".py")
3238
self._htest = _htest
@@ -170,7 +176,7 @@ def GetSubList(self):
170176
def OnDoubleClick(self):
171177
if not os.path.exists(self.file):
172178
return
173-
edit = PyShell.flist.open(self.file)
179+
edit = file_open(self.file)
174180
if hasattr(self.cl, 'lineno'):
175181
lineno = self.cl.lineno
176182
edit.gotoline(lineno)
@@ -206,7 +212,7 @@ def IsExpandable(self):
206212
def OnDoubleClick(self):
207213
if not os.path.exists(self.file):
208214
return
209-
edit = PyShell.flist.open(self.file)
215+
edit = file_open(self.file)
210216
edit.gotoline(self.cl.methods[self.name])
211217

212218
def _class_browser(parent): #Wrapper for htest
@@ -221,8 +227,9 @@ def _class_browser(parent): #Wrapper for htest
221227
dir, file = os.path.split(file)
222228
name = os.path.splitext(file)[0]
223229
flist = PyShell.PyShellFileList(parent)
230+
global file_open
231+
file_open = flist.open
224232
ClassBrowser(flist, name, [dir], _htest=True)
225-
parent.mainloop()
226233

227234
if __name__ == "__main__":
228235
from idlelib.idle_test.htest import run

Lib/idlelib/ColorDelegator.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import re
33
import keyword
44
import builtins
5-
from tkinter import *
65
from idlelib.Delegator import Delegator
76
from idlelib.configHandler import idleConf
87

@@ -234,20 +233,23 @@ def removecolors(self):
234233
for tag in self.tagdefs:
235234
self.tag_remove(tag, "1.0", "end")
236235

237-
def _color_delegator(parent):
236+
def _color_delegator(parent): # htest #
237+
from tkinter import Toplevel, Text
238238
from idlelib.Percolator import Percolator
239-
root = Tk()
240-
root.title("Test ColorDelegator")
241-
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
242-
root.geometry("+%d+%d"%(x, y + 150))
243-
source = "if somename: x = 'abc' # comment\nprint"
244-
text = Text(root, background="white")
245-
text.insert("insert", source)
239+
240+
top = Toplevel(parent)
241+
top.title("Test ColorDelegator")
242+
top.geometry("200x100+%d+%d" % (parent.winfo_rootx() + 200,
243+
parent.winfo_rooty() + 150))
244+
source = "if somename: x = 'abc' # comment\nprint\n"
245+
text = Text(top, background="white")
246246
text.pack(expand=1, fill="both")
247+
text.insert("insert", source)
248+
text.focus_set()
249+
247250
p = Percolator(text)
248251
d = ColorDelegator()
249252
p.insertfilter(d)
250-
root.mainloop()
251253

252254
if __name__ == "__main__":
253255
from idlelib.idle_test.htest import run

Lib/idlelib/EditorWindow.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,8 @@ def fixwordbreaks(root):
17111711
tk.call('set', 'tcl_nonwordchars', '[^a-zA-Z0-9_]')
17121712

17131713

1714-
def _editor_window(parent):
1714+
def _editor_window(parent): # htest #
1715+
# error if close master window first - timer event, after script
17151716
root = parent
17161717
fixwordbreaks(root)
17171718
if sys.argv[1:]:
@@ -1721,7 +1722,8 @@ def _editor_window(parent):
17211722
macosxSupport.setupApp(root, None)
17221723
edit = EditorWindow(root=root, filename=filename)
17231724
edit.text.bind("<<close-all-windows>>", edit.close_event)
1724-
parent.mainloop()
1725+
# Does not stop error, neither does following
1726+
# edit.text.bind("<<close-window>>", edit.close_event)
17251727

17261728
if __name__ == '__main__':
17271729
from idlelib.idle_test.htest import run

Lib/idlelib/GrepDialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def close(self, event=None):
131131
self.top.withdraw()
132132

133133

134-
def _grep_dialog(parent): # for htest
134+
def _grep_dialog(parent): # htest #
135135
from idlelib.PyShell import PyShellFileList
136136
root = Tk()
137137
root.title("Test GrepDialog")

Lib/idlelib/configDialog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
class ConfigDialog(Toplevel):
2626

27-
def __init__(self, parent, title, _htest=False, _utest=False):
27+
def __init__(self, parent, title='', _htest=False, _utest=False):
2828
"""
2929
_htest - bool, change box location when running htest
3030
_utest - bool, don't wait_window when running unittest
@@ -36,7 +36,7 @@ def __init__(self, parent, title, _htest=False, _utest=False):
3636
self.wm_withdraw()
3737

3838
self.configure(borderwidth=5)
39-
self.title('IDLE Preferences')
39+
self.title(title or 'IDLE Preferences')
4040
self.geometry(
4141
"+%d+%d" % (parent.winfo_rootx() + 20,
4242
parent.winfo_rooty() + (30 if not _htest else 150)))

Lib/idlelib/dynOptionMenuWidget.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
OptionMenu widget modified to allow dynamic menu reconfiguration
33
and setting of highlightthickness
44
"""
5-
from tkinter import OptionMenu, _setit, Tk, StringVar, Button
6-
75
import copy
8-
import re
6+
from tkinter import OptionMenu, _setit, StringVar, Button
97

108
class DynOptionMenu(OptionMenu):
119
"""
1210
unlike OptionMenu, our kwargs can include highlightthickness
1311
"""
1412
def __init__(self, master, variable, value, *values, **kwargs):
15-
#get a copy of kwargs before OptionMenu.__init__ munges them
13+
# TODO copy value instead of whole dict
1614
kwargsCopy=copy.copy(kwargs)
1715
if 'highlightthickness' in list(kwargs.keys()):
1816
del(kwargs['highlightthickness'])
@@ -35,22 +33,24 @@ def SetMenu(self,valueList,value=None):
3533
if value:
3634
self.variable.set(value)
3735

38-
def _dyn_option_menu(parent):
39-
root = Tk()
40-
root.title("Tets dynamic option menu")
41-
var = StringVar(root)
42-
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
43-
root.geometry("+%d+%d"%(x, y + 150))
36+
def _dyn_option_menu(parent): # htest #
37+
from tkinter import Toplevel
38+
39+
top = Toplevel()
40+
top.title("Tets dynamic option menu")
41+
top.geometry("200x100+%d+%d" % (parent.winfo_rootx() + 200,
42+
parent.winfo_rooty() + 150))
43+
top.focus_set()
44+
45+
var = StringVar(top)
4446
var.set("Old option set") #Set the default value
45-
dyn = DynOptionMenu(root,var, "old1","old2","old3","old4")
47+
dyn = DynOptionMenu(top,var, "old1","old2","old3","old4")
4648
dyn.pack()
4749

4850
def update():
49-
dyn.SetMenu(["new1","new2","new3","new4"],value="new option set")
50-
51-
button = Button(root, text="Change option set", command=update)
51+
dyn.SetMenu(["new1","new2","new3","new4"], value="new option set")
52+
button = Button(top, text="Change option set", command=update)
5253
button.pack()
53-
root.mainloop()
5454

5555
if __name__ == '__main__':
5656
from idlelib.idle_test.htest import run

Lib/idlelib/idle_test/htest.py

Lines changed: 47 additions & 18 deletions

0 commit comments

Comments
 (0)