Commit 985ef280 authored by Terry Jan Reedy's avatar Terry Jan Reedy

Issue #21477: Idle htest: modify run; add more tests.

Patch by Saimadhav Heblikar. 2.7  backport of 90829, d7eea8f608c2.
parent 7e19b60d
...@@ -13,7 +13,6 @@ XXX TO DO: ...@@ -13,7 +13,6 @@ XXX TO DO:
import os import os
import sys import sys
import pyclbr import pyclbr
import re
from idlelib import PyShell from idlelib import PyShell
from idlelib.WindowList import ListedToplevel from idlelib.WindowList import ListedToplevel
...@@ -223,6 +222,7 @@ def _class_browser(parent): #Wrapper for htest ...@@ -223,6 +222,7 @@ def _class_browser(parent): #Wrapper for htest
name = os.path.splitext(file)[0] name = os.path.splitext(file)[0]
flist = PyShell.PyShellFileList(parent) flist = PyShell.PyShellFileList(parent)
ClassBrowser(flist, name, [dir], _htest=True) ClassBrowser(flist, name, [dir], _htest=True)
parent.mainloop()
if __name__ == "__main__": if __name__ == "__main__":
from idlelib.idle_test.htest import run from idlelib.idle_test.htest import run
......
...@@ -261,13 +261,9 @@ def _color_delegator(parent): ...@@ -261,13 +261,9 @@ def _color_delegator(parent):
root.title("Test ColorDelegator") root.title("Test ColorDelegator")
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry()))) width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
root.geometry("+%d+%d"%(x, y + 150)) root.geometry("+%d+%d"%(x, y + 150))
## with open(__file__, 'r') as f: source = "if somename: x = 'abc' # comment\nprint"
## source = f.read()
source = "if somename: x = 'abc' # comment"
text = Text(root, background="white") text = Text(root, background="white")
# insert only a sample portion text.insert("insert", source)
## text.insert("insert", source[:690])
text.insert("insert", source[:690])
text.pack(expand=1, fill="both") text.pack(expand=1, fill="both")
p = Percolator(text) p = Percolator(text)
d = ColorDelegator() d = ColorDelegator()
......
...@@ -1714,18 +1714,16 @@ def fixwordbreaks(root): ...@@ -1714,18 +1714,16 @@ def fixwordbreaks(root):
def _editor_window(parent): def _editor_window(parent):
root = parent root = parent
fixwordbreaks(root) fixwordbreaks(root)
## root.withdraw()
if sys.argv[1:]: if sys.argv[1:]:
filename = sys.argv[1] filename = sys.argv[1]
else: else:
filename = None filename = None
macosxSupport.setupApp(root, None) macosxSupport.setupApp(root, None)
edit = EditorWindow(root=root, filename=filename) edit = EditorWindow(root=root, filename=filename)
## edit.set_close_hook(root.quit) edit.text.bind("<<close-all-windows>>", edit.close_event)
## edit.text.bind("<<close-all-windows>>", edit.close_event) parent.mainloop()
if __name__ == '__main__': if __name__ == '__main__':
from idlelib.idle_test.htest import run from idlelib.idle_test.htest import run
if len(sys.argv) <= 1: run(_help_dialog, _editor_window)
run(_help_dialog)
run(_editor_window)
import os import os
import sys import sys
import re
import imp import imp
from idlelib.TreeWidget import TreeItem from idlelib.TreeWidget import TreeItem
...@@ -95,6 +94,7 @@ class DirBrowserTreeItem(TreeItem): ...@@ -95,6 +94,7 @@ class DirBrowserTreeItem(TreeItem):
def _path_browser(parent): def _path_browser(parent):
flist = PyShellFileList(parent) flist = PyShellFileList(parent)
PathBrowser(flist, _htest=True) PathBrowser(flist, _htest=True)
parent.mainloop()
if __name__ == "__main__": if __name__ == "__main__":
from unittest import main from unittest import main
......
...@@ -52,7 +52,9 @@ class Percolator: ...@@ -52,7 +52,9 @@ class Percolator:
filter.setdelegate(None) filter.setdelegate(None)
def main(): def _percolator(parent):
import Tkinter as tk
import re
class Tracer(Delegator): class Tracer(Delegator):
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
...@@ -63,23 +65,39 @@ def main(): ...@@ -63,23 +65,39 @@ def main():
def delete(self, *args): def delete(self, *args):
print self.name, ": delete", args print self.name, ": delete", args
self.delegate.delete(*args) self.delegate.delete(*args)
root = Tk() root = tk.Tk()
root.wm_protocol("WM_DELETE_WINDOW", root.quit) root.title("Test Percolator")
text = Text() width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
text.pack() root.geometry("+%d+%d"%(x, y + 150))
text.focus_set() text = tk.Text(root)
p = Percolator(text) p = Percolator(text)
t1 = Tracer("t1") t1 = Tracer("t1")
t2 = Tracer("t2") t2 = Tracer("t2")
def toggle1():
if var1.get() == 0:
var1.set(1)
p.insertfilter(t1) p.insertfilter(t1)
elif var1.get() == 1:
var1.set(0)
p.removefilter(t1)
def toggle2():
if var2.get() == 0:
var2.set(1)
p.insertfilter(t2) p.insertfilter(t2)
root.mainloop() elif var2.get() == 1:
var2.set(0)
p.removefilter(t2) p.removefilter(t2)
root.mainloop()
p.insertfilter(t2) text.pack()
p.removefilter(t1) var1 = tk.IntVar()
root.mainloop() cb1 = tk.Checkbutton(root, text="Tracer1", command=toggle1, variable=var1)
cb1.pack()
var2 = tk.IntVar()
cb2 = tk.Checkbutton(root, text="Tracer2", command=toggle2, variable=var2)
cb2.pack()
if __name__ == "__main__": if __name__ == "__main__":
from Tkinter import * from idlelib.idle_test.htest import run
main() run(_percolator)
import os import os
import sys import sys
import linecache import linecache
import re
import Tkinter as tk
from idlelib.TreeWidget import TreeNode, TreeItem, ScrolledCanvas from idlelib.TreeWidget import TreeNode, TreeItem, ScrolledCanvas
from idlelib.ObjectBrowser import ObjectTreeItem, make_objecttreeitem from idlelib.ObjectBrowser import ObjectTreeItem, make_objecttreeitem
from idlelib.PyShell import PyShellFileList
def StackBrowser(root, flist=None, tb=None, top=None): def StackBrowser(root, flist=None, tb=None, top=None):
if top is None: if top is None:
...@@ -121,17 +124,29 @@ class VariablesTreeItem(ObjectTreeItem): ...@@ -121,17 +124,29 @@ class VariablesTreeItem(ObjectTreeItem):
sublist.append(item) sublist.append(item)
return sublist return sublist
def _stack_viewer(parent):
def _test(): root = tk.Tk()
try: root.title("Test StackViewer")
import testcode width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
reload(testcode) root.geometry("+%d+%d"%(x, y + 150))
flist = PyShellFileList(root)
try: # to obtain a traceback object
a
except: except:
sys.last_type, sys.last_value, sys.last_traceback = sys.exc_info() exc_type, exc_value, exc_tb = sys.exc_info()
from Tkinter import Tk
root = Tk() # inject stack trace to sys
StackBrowser(None, top=root) sys.last_type = exc_type
root.mainloop() sys.last_value = exc_value
sys.last_traceback = exc_tb
if __name__ == "__main__":
_test() StackBrowser(root, flist=flist, top=root, tb=exc_tb)
# restore sys to original state
del sys.last_type
del sys.last_value
del sys.last_traceback
if __name__ == '__main__':
from idlelib.idle_test.htest import run
run(_stack_viewer)
...@@ -87,8 +87,9 @@ def _tooltip(parent): ...@@ -87,8 +87,9 @@ def _tooltip(parent):
button2 = Button(root, text="Button 2") button2 = Button(root, text="Button 2")
button1.pack() button1.pack()
button2.pack() button2.pack()
ToolTip(button1, "This is calltip text for button1.") ToolTip(button1, "This is tooltip text for button1.")
ListboxToolTip(button2, ["This is","calltip text","for button2"]) ListboxToolTip(button2, ["This is","multiple line",
"tooltip text","for button2"])
root.mainloop() root.mainloop()
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -53,8 +53,9 @@ _class_browser_spec = { ...@@ -53,8 +53,9 @@ _class_browser_spec = {
'file': 'ClassBrowser', 'file': 'ClassBrowser',
'kwds': {}, 'kwds': {},
'msg': "Inspect names of module, class(with superclass if " 'msg': "Inspect names of module, class(with superclass if "
"applicable), methods and functions.\nToggle nested items." "applicable), methods and functions.\nToggle nested items.\n"
"\nN.S: Double click on items does not work", "Double clicking on items prints a traceback for an exception "
"that is ignored."
} }
_color_delegator_spec = { _color_delegator_spec = {
...@@ -74,11 +75,11 @@ _dyn_option_menu_spec = { ...@@ -74,11 +75,11 @@ _dyn_option_menu_spec = {
"Select one of the many options in the 'new option set'." "Select one of the many options in the 'new option set'."
} }
#_editor_window_spec = { _editor_window_spec = {
# 'file': 'EditorWindow', 'file': 'EditorWindow',
# 'kwds': {}, 'kwds': {},
# 'msg': "Test editor functions of interest" 'msg': "Test editor functions of interest"
# } }
GetCfgSectionNameDialog_spec = { GetCfgSectionNameDialog_spec = {
'file': 'configSectionNameDialog', 'file': 'configSectionNameDialog',
...@@ -91,6 +92,7 @@ GetCfgSectionNameDialog_spec = { ...@@ -91,6 +92,7 @@ GetCfgSectionNameDialog_spec = {
"Close 'Get Name' with a valid entry (printed to Shell), " "Close 'Get Name' with a valid entry (printed to Shell), "
"[Cancel], or [X]", "[Cancel], or [X]",
} }
GetHelpSourceDialog_spec = { GetHelpSourceDialog_spec = {
'file': 'configHelpSourceEdit', 'file': 'configHelpSourceEdit',
'kwds': {'title': 'Get helpsource', 'kwds': {'title': 'Get helpsource',
...@@ -103,10 +105,27 @@ GetHelpSourceDialog_spec = { ...@@ -103,10 +105,27 @@ GetHelpSourceDialog_spec = {
"[Cancel] will print None to shell", "[Cancel] will print None to shell",
} }
# Update once issue21519 is resolved.
GetKeysDialog_spec = {
'file': 'keybindingDialog',
'kwds': {'title': 'Test keybindings',
'action': 'find-again',
'currentKeySequences': [''] ,
'_htest': True,
},
'msg': "Test for different key modifier sequences.\n"
"<nothing> is invalid.\n"
"No modifier key is invalid.\n"
"Shift key with [a-z],[0-9], function key, move key, tab, space"
"is invalid.\nNo validitity checking if advanced key binding "
"entry is used."
}
_help_dialog_spec = { _help_dialog_spec = {
'file': 'EditorWindow', 'file': 'EditorWindow',
'kwds': {}, 'kwds': {},
'msg': "If the help text displays, this works" 'msg': "If the help text displays, this works.\n"
"Text is selectable. Window is scrollable."
} }
_io_binding_spec = { _io_binding_spec = {
...@@ -115,17 +134,16 @@ _io_binding_spec = { ...@@ -115,17 +134,16 @@ _io_binding_spec = {
'msg': "Test the following bindings\n" 'msg': "Test the following bindings\n"
"<Control-o> to display open window from file dialog.\n" "<Control-o> to display open window from file dialog.\n"
"<Control-s> to save the file\n" "<Control-s> to save the file\n"
} }
_multi_call_spec = { _multi_call_spec = {
'file': 'MultiCall', 'file': 'MultiCall',
'kwds': {}, 'kwds': {},
'msg': "The following actions should trigger a print to console.\n" 'msg': "The following actions should trigger a print to console or IDLE"
"Entering and leaving the text area, key entry, <Control-Key>,\n" " Shell.\nEntering and leaving the text area, key entry, "
"<Alt-Key-a>, <Control-Key-a>, <Alt-Control-Key-a>, \n" "<Control-Key>,\n<Alt-Key-a>, <Control-Key-a>, "
"<Control-Button-1>, <Alt-Button-1> and focussing out of the window\n" "<Alt-Control-Key-a>, \n<Control-Button-1>, <Alt-Button-1> and "
"are sequences to be tested." "focusing out of the window\nare sequences to be tested."
} }
_multistatus_bar_spec = { _multistatus_bar_spec = {
...@@ -146,18 +164,38 @@ _object_browser_spec = { ...@@ -146,18 +164,38 @@ _object_browser_spec = {
_path_browser_spec = { _path_browser_spec = {
'file': 'PathBrowser', 'file': 'PathBrowser',
'kwds': {}, 'kwds': {},
'msg': "Test for correct display of all paths in sys.path." 'msg': "Test for correct display of all paths in sys.path.\n"
"\nToggle nested items upto the lowest level." "Toggle nested items upto the lowest level.\n"
"\nN.S: Double click on items does not work." "Double clicking on an item prints a traceback\n"
"for an exception that is ignored."
}
_percolator_spec = {
'file': 'Percolator',
'kwds': {},
'msg': "There are two tracers which can be toggled using a checkbox.\n"
"Toggling a tracer 'on' by checking it should print tracer"
"output to the console or to the IDLE shell.\n"
"If both the tracers are 'on', the output from the tracer which "
"was switched 'on' later, should be printed first\n"
"Test for actions like text entry, and removal."
} }
_scrolled_list_spec = { _scrolled_list_spec = {
'file': 'ScrolledList', 'file': 'ScrolledList',
'kwds': {}, 'kwds': {},
'msg': "You should see a scrollable list of items\n" 'msg': "You should see a scrollable list of items\n"
"Selecting an item will print it to console.\n" "Selecting (clicking) or double clicking an item "
"Double clicking an item will print it to console\n" "prints the name to the console or Idle shell.\n"
"Right click on an item will display a popup." "Right clicking an item will display a popup."
}
_stack_viewer_spec = {
'file': 'StackViewer',
'kwds': {},
'msg': "A stacktrace for a NameError exception.\n"
"Expand 'idlelib ...' and '<locals>'.\n"
"Check that exc_value, exc_tb, and exc_type are correct.\n"
} }
_tabbed_pages_spec = { _tabbed_pages_spec = {
...@@ -189,7 +227,7 @@ _tooltip_spec = { ...@@ -189,7 +227,7 @@ _tooltip_spec = {
_tree_widget_spec = { _tree_widget_spec = {
'file': 'TreeWidget', 'file': 'TreeWidget',
'kwds': {}, 'kwds': {},
'msg': "You should see two canvas' side-by-side.\n" 'msg': "You should see two canvases side-by-side.\n"
"The left canvas is scrollable.\n" "The left canvas is scrollable.\n"
"The right canvas is not scrollable.\n" "The right canvas is not scrollable.\n"
"Click on folders upto to the lowest level." "Click on folders upto to the lowest level."
...@@ -198,29 +236,27 @@ _tree_widget_spec = { ...@@ -198,29 +236,27 @@ _tree_widget_spec = {
_widget_redirector_spec = { _widget_redirector_spec = {
'file': 'WidgetRedirector', 'file': 'WidgetRedirector',
'kwds': {}, 'kwds': {},
'msg': "Every text insert should be printed to console." 'msg': "Every text insert should be printed to the console."
"or the IDLE shell."
} }
def run(test=None): def run(*tests):
root = tk.Tk() root = tk.Tk()
test_list = [] # List of tuples of the form (spec, kwds, callable widget) test_list = [] # List of tuples of the form (spec, callable widget)
if test: if tests:
for test in tests:
test_spec = globals()[test.__name__ + '_spec'] test_spec = globals()[test.__name__ + '_spec']
test_spec['name'] = test.__name__ test_spec['name'] = test.__name__
test_kwds = test_spec['kwds'] test_list.append((test_spec, test))
test_kwds['parent'] = root
test_list.append((test_spec, test_kwds, test))
else: else:
for k, d in globals().items(): for k, d in globals().items():
if k.endswith('_spec'): if k.endswith('_spec'):
test_name = k[:-5] test_name = k[:-5]
test_spec = d test_spec = d
test_spec['name'] = test_name test_spec['name'] = test_name
test_kwds = test_spec['kwds']
test_kwds['parent'] = root
mod = import_module('idlelib.' + test_spec['file']) mod = import_module('idlelib.' + test_spec['file'])
test = getattr(mod, test_name) test = getattr(mod, test_name)
test_list.append((test_spec, test_kwds, test)) test_list.append((test_spec, test))
help_string = [tk.StringVar('')] help_string = [tk.StringVar('')]
test_name = [tk.StringVar('')] test_name = [tk.StringVar('')]
...@@ -231,11 +267,11 @@ def run(test=None): ...@@ -231,11 +267,11 @@ def run(test=None):
def next(): def next():
if len(test_list) == 1: if len(test_list) == 1:
next_button.pack_forget() next_button.pack_forget()
test_spec, test_kwds[0], test = test_list.pop() test_spec, callable_object[0] = test_list.pop()
test_kwds[0] = test_spec['kwds']
test_kwds[0]['parent'] = root
help_string[0].set(test_spec['msg']) help_string[0].set(test_spec['msg'])
test_name[0].set('test ' + test_spec['name']) test_name[0].set('test ' + test_spec['name'])
callable_object[0] = test
def run_test(): def run_test():
widget = callable_object[0](**test_kwds[0]) widget = callable_object[0](**test_kwds[0])
......
...@@ -7,12 +7,13 @@ import string ...@@ -7,12 +7,13 @@ import string
import sys import sys
class GetKeysDialog(Toplevel): class GetKeysDialog(Toplevel):
def __init__(self,parent,title,action,currentKeySequences): def __init__(self,parent,title,action,currentKeySequences,_htest=False):
""" """
action - string, the name of the virtual event these keys will be action - string, the name of the virtual event these keys will be
mapped to mapped to
currentKeys - list, a list of all key sequence lists currently mapped currentKeys - list, a list of all key sequence lists currently mapped
to virtual events, for overlap checking to virtual events, for overlap checking
_htest - bool, change box location when running htest
""" """
Toplevel.__init__(self, parent) Toplevel.__init__(self, parent)
self.configure(borderwidth=5) self.configure(borderwidth=5)
...@@ -38,11 +39,14 @@ class GetKeysDialog(Toplevel): ...@@ -38,11 +39,14 @@ class GetKeysDialog(Toplevel):
self.LoadFinalKeyList() self.LoadFinalKeyList()
self.withdraw() #hide while setting geometry self.withdraw() #hide while setting geometry
self.update_idletasks() self.update_idletasks()
self.geometry("+%d+%d" % self.geometry(
((parent.winfo_rootx()+((parent.winfo_width()/2) "+%d+%d" % (
-(self.winfo_reqwidth()/2)), parent.winfo_rootx() +
parent.winfo_rooty()+((parent.winfo_height()/2) (parent.winfo_width()/2 - self.winfo_reqwidth()/2),
-(self.winfo_reqheight()/2)) )) ) #centre dialog over parent parent.winfo_rooty() +
((parent.winfo_height()/2 - self.winfo_reqheight()/2)
if not _htest else 150)
) ) #centre dialog over parent (or below htest box)
self.deiconify() #geometry set, unhide self.deiconify() #geometry set, unhide
self.wait_window() self.wait_window()
...@@ -258,11 +262,5 @@ class GetKeysDialog(Toplevel): ...@@ -258,11 +262,5 @@ class GetKeysDialog(Toplevel):
return keysOK return keysOK
if __name__ == '__main__': if __name__ == '__main__':
#test the dialog from idlelib.idle_test.htest import run
root=Tk() run(GetKeysDialog)
def run():
keySeq=''
dlg=GetKeysDialog(root,'Get Keys','find-again',[])
print dlg.result
Button(root,text='Dialog',command=run).pack()
root.mainloop()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment