diff -r 038cbbef4539 Lib/idlelib/ClassBrowser.py --- a/Lib/idlelib/ClassBrowser.py Sat May 24 18:48:18 2014 -0400 +++ b/Lib/idlelib/ClassBrowser.py Sun May 25 21:13:26 2014 +0530 @@ -13,7 +13,6 @@ import os import sys import pyclbr -import re from idlelib import PyShell from idlelib.WindowList import ListedToplevel @@ -223,6 +222,7 @@ name = os.path.splitext(file)[0] flist = PyShell.PyShellFileList(parent) ClassBrowser(flist, name, [dir], _htest=True) + parent.mainloop() if __name__ == "__main__": from idlelib.idle_test.htest import run diff -r 038cbbef4539 Lib/idlelib/ColorDelegator.py --- a/Lib/idlelib/ColorDelegator.py Sat May 24 18:48:18 2014 -0400 +++ b/Lib/idlelib/ColorDelegator.py Sun May 25 21:13:26 2014 +0530 @@ -259,11 +259,9 @@ root.title("Test ColorDelegator") width, height, x, y = list(map(int, re.split('[x+]', parent.geometry()))) root.geometry("+%d+%d"%(x, y + 150)) - with open(__file__, 'r') as f: - source = f.read() + source = "if somename: x = 'abc' # comment\nprint" text = Text(root, background="white") - # insert only a sample portion - text.insert("insert", source[:690]) + text.insert("insert", source) text.pack(expand=1, fill="both") p = Percolator(text) d = ColorDelegator() diff -r 038cbbef4539 Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py Sat May 24 18:48:18 2014 -0400 +++ b/Lib/idlelib/EditorWindow.py Sun May 25 21:13:26 2014 +0530 @@ -1705,18 +1705,15 @@ def _editor_window(parent): root = parent fixwordbreaks(root) -## root.withdraw() if sys.argv[1:]: filename = sys.argv[1] else: filename = None macosxSupport.setupApp(root, None) edit = EditorWindow(root=root, filename=filename) -## edit.set_close_hook(root.quit) -## edit.text.bind("<>", edit.close_event) + edit.text.bind("<>", edit.close_event) + parent.mainloop() if __name__ == '__main__': from idlelib.idle_test.htest import run - if len(sys.argv) <= 1: - run(_help_dialog) - run(_editor_window) + run(_help_dialog, _editor_window) diff -r 038cbbef4539 Lib/idlelib/FormatParagraph.py --- a/Lib/idlelib/FormatParagraph.py Sat May 24 18:48:18 2014 -0400 +++ b/Lib/idlelib/FormatParagraph.py Sun May 25 21:13:26 2014 +0530 @@ -16,6 +16,8 @@ """ import re +import tkinter as tk + from idlelib.configHandler import idleConf class FormatParagraph: @@ -187,8 +189,49 @@ if m is None: return "" return m.group(1) +def _format_paragraph(parent): + root = tk.Tk() + root.title("Test FormatParagraph") + width, height, x, y = list(map(int, re.split('[x+]', parent.geometry()))) + root.geometry("+%d+%d"%(x, y + 150)) + + # Minimally imitate UndoDelegator,UndoDelegator class. + def undo_block_start(*args): + pass + + def undo_block_stop(*args): + pass + + class MyEditwin: + def __init__(self): + self.text = tk.Text(root) + self.text.pack() + self.text.undo_block_start = undo_block_start + self.text.undo_block_stop = undo_block_stop + self.text.insert("insert" ,"text "*14) + self.text.insert("insert", "The newline should begin here.\n") + + def get_selection_indices(self): + try: + first = self.text.index("sel.first") + last = self.text.index("sel.last") + return first, last + except: + return "0.0", "end" + + + editwin = MyEditwin() + formatter = FormatParagraph(editwin) + button = tk.Button(root,text="Format paragraph", + command=lambda:formatter.format_paragraph_event(None)) + button.pack() + root.mainloop() + if __name__ == "__main__": from test import support; support.use_resources = ['gui'] import unittest unittest.main('idlelib.idle_test.test_formatparagraph', verbosity=2, exit=False) + + from idlelib.idle_test.htest import run + run(_format_paragraph) diff -r 038cbbef4539 Lib/idlelib/PathBrowser.py --- a/Lib/idlelib/PathBrowser.py Sat May 24 18:48:18 2014 -0400 +++ b/Lib/idlelib/PathBrowser.py Sun May 25 21:13:26 2014 +0530 @@ -1,6 +1,5 @@ import os import sys -import re import importlib.machinery from idlelib.TreeWidget import TreeItem @@ -97,6 +96,7 @@ def _path_browser(parent): flist = PyShellFileList(parent) PathBrowser(flist, _htest=True) + parent.mainloop() if __name__ == "__main__": from unittest import main diff -r 038cbbef4539 Lib/idlelib/Percolator.py --- a/Lib/idlelib/Percolator.py Sat May 24 18:48:18 2014 -0400 +++ b/Lib/idlelib/Percolator.py Sun May 25 21:13:26 2014 +0530 @@ -51,8 +51,9 @@ f.setdelegate(filter.delegate) filter.setdelegate(None) -def main(): - import tkinter as Tk +def _percolator(parent): + import tkinter as tk + import re class Tracer(Delegator): def __init__(self, name): self.name = name @@ -63,22 +64,41 @@ def delete(self, *args): print(self.name, ": delete", args) self.delegate.delete(*args) - root = Tk.Tk() - root.wm_protocol("WM_DELETE_WINDOW", root.quit) - text = Tk.Text() - text.pack() - text.focus_set() + root = tk.Tk() + root.title("Test Percolator") + width, height, x, y = list(map(int, re.split('[x+]', parent.geometry()))) + root.geometry("+%d+%d"%(x, y + 150)) + text = tk.Text(root) p = Percolator(text) t1 = Tracer("t1") t2 = Tracer("t2") - p.insertfilter(t1) - p.insertfilter(t2) - root.mainloop() # click close widget to continue... - p.removefilter(t2) - root.mainloop() - p.insertfilter(t2) - p.removefilter(t1) + + def toggle1(): + if var1.get() == 0: + var1.set(1) + 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) + elif var2.get() == 1: + var2.set(0) + p.removefilter(t2) + + text.pack() + var1 = tk.IntVar() + 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() + root.mainloop() if __name__ == "__main__": - main() + from idlelib.idle_test.htest import run + run(_percolator) diff -r 038cbbef4539 Lib/idlelib/StackViewer.py --- a/Lib/idlelib/StackViewer.py Sat May 24 18:48:18 2014 -0400 +++ b/Lib/idlelib/StackViewer.py Sun May 25 21:13:26 2014 +0530 @@ -1,9 +1,12 @@ import os import sys import linecache +import re +import tkinter as tk from idlelib.TreeWidget import TreeNode, TreeItem, ScrolledCanvas from idlelib.ObjectBrowser import ObjectTreeItem, make_objecttreeitem +from idlelib.PyShell import PyShellFileList def StackBrowser(root, flist=None, tb=None, top=None): if top is None: @@ -120,3 +123,30 @@ item = make_objecttreeitem(key + " =", value, setfunction) sublist.append(item) return sublist + +def _stack_viewer(parent): + root = tk.Tk() + root.title("Test StackViewer") + width, height, x, y = list(map(int, re.split('[x+]', parent.geometry()))) + root.geometry("+%d+%d"%(x, y + 150)) + flist = PyShellFileList(root) + try: # to obtain a traceback object + a + except: + exc_type, exc_value, exc_tb = sys.exc_info() + + # inject stack trace to sys + sys.last_type = exc_type + sys.last_value = exc_value + sys.last_traceback = exc_tb + + 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) diff -r 038cbbef4539 Lib/idlelib/ToolTip.py --- a/Lib/idlelib/ToolTip.py Sat May 24 18:48:18 2014 -0400 +++ b/Lib/idlelib/ToolTip.py Sun May 25 21:13:26 2014 +0530 @@ -87,8 +87,9 @@ button2 = Button(root, text="Button 2") button1.pack() button2.pack() - ToolTip(button1, "This is calltip text for button1.") - ListboxToolTip(button2, ["This is","calltip text","for button2"]) + ToolTip(button1, "This is tooltip text for button1.") + ListboxToolTip(button2, ["This is","multiple line", + "tooltip text","for button2"]) root.mainloop() if __name__ == '__main__': diff -r 038cbbef4539 Lib/idlelib/idle_test/htest.py --- a/Lib/idlelib/idle_test/htest.py Sat May 24 18:48:18 2014 -0400 +++ b/Lib/idlelib/idle_test/htest.py Sun May 25 21:13:26 2014 +0530 @@ -54,7 +54,7 @@ 'kwds': {}, 'msg': "Inspect names of module, class(with superclass if " "applicable), methods and functions.\nToggle nested items." - "\nN.S: Double click on items does not work", + "\nDouble click on items does not work", } _color_delegator_spec = { @@ -74,11 +74,22 @@ "Select one of the many options in the 'new option set'." } -#_editor_window_spec = { -# 'file': 'EditorWindow', -# 'kwds': {}, -# 'msg': "Test editor functions of interest" -# } +_editor_window_spec = { + 'file': 'EditorWindow', + 'kwds': {}, + 'msg': "Test editor functions of interest." + } + +_format_paragraph_spec = { + 'file': 'FormatParagraph', + 'kwds': {}, + 'msg': "A minimal test for FormatParagraph.\n" + "Clicking 'Format Paragraph' button should " + "format the paragraph. \n" + "Test with and without selecting the text.\n" + "In both tests, the sentence 'The newline should begin here' " + "should be displayed on the second line." + } GetCfgSectionNameDialog_spec = { 'file': 'configSectionNameDialog', @@ -103,10 +114,27 @@ "[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" + " 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 = { 'file': 'EditorWindow', '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 = { @@ -121,11 +149,11 @@ _multi_call_spec = { 'file': 'MultiCall', 'kwds': {}, - 'msg': "The following actions should trigger a print to console.\n" - "Entering and leaving the text area, key entry, ,\n" - ", , , \n" - ", and focussing out of the window\n" - "are sequences to be tested." + 'msg': "The following actions should trigger a print to console or IDLE" + " Shell.\nEntering and leaving the text area, key entry, " + ",\n, , " + ", \n, and " + "focussing out of the window\nare sequences to be tested." } _multistatus_bar_spec = { @@ -143,23 +171,44 @@ "will be displayed side-by-side at each level." } +_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." + } + _path_browser_spec = { 'file': 'PathBrowser', 'kwds': {}, 'msg': "Test for correct display of all paths in sys.path." "\nToggle nested items upto the lowest level." - "\nN.S: Double click on items does not work." + "\n Double click on items does not work." } _scrolled_list_spec = { 'file': 'ScrolledList', 'kwds': {}, 'msg': "You should see a scrollable list of items\n" - "Selecting an item will print it to console.\n" - "Double clicking an item will print it to console\n" - "Right click on an item will display a popup." + "Selecting (clicking) or double clicking an item " + "prints the name to the console or Idle shell.\n" + "Right clicking an item will display a popup." } +_stack_viewer_spec = { + 'file': 'StackViewer', + 'kwds': {}, + 'msg': "A stacktrace for a NameError exception.\n" + "Click down to the lowest level in the tree.\n" + "Ensure that type, value and traceback is correctly displayed " + "in .\nEnsure is generally correct." + } + + _tabbed_pages_spec = { 'file': 'tabbedpages', 'kwds': {}, @@ -189,7 +238,7 @@ _tree_widget_spec = { 'file': 'TreeWidget', '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 right canvas is not scrollable.\n" "Click on folders upto to the lowest level." @@ -198,29 +247,27 @@ _widget_redirector_spec = { 'file': 'WidgetRedirector', '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() - test_list = [] # List of tuples of the form (spec, kwds, callable widget) - if test: - test_spec = globals()[test.__name__ + '_spec'] - test_spec['name'] = test.__name__ - test_kwds = test_spec['kwds'] - test_kwds['parent'] = root - test_list.append((test_spec, test_kwds, test)) + test_list = [] # List of tuples of the form (spec, callable widget) + if tests: + for test in tests: + test_spec = globals()[test.__name__ + '_spec'] + test_spec['name'] = test.__name__ + test_list.append((test_spec, test)) else: for k, d in globals().items(): if k.endswith('_spec'): test_name = k[:-5] test_spec = d test_spec['name'] = test_name - test_kwds = test_spec['kwds'] - test_kwds['parent'] = root mod = import_module('idlelib.' + test_spec['file']) test = getattr(mod, test_name) - test_list.append((test_spec, test_kwds, test)) + test_list.append((test_spec, test)) help_string = tk.StringVar('') test_name = tk.StringVar('') @@ -232,10 +279,11 @@ nonlocal help_string, test_name, callable_object, test_kwds if len(test_list) == 1: next_button.pack_forget() - test_spec, test_kwds, test = test_list.pop() + test_spec, callable_object = test_list.pop() + test_kwds = test_spec['kwds'] + test_kwds['parent'] = root help_string.set(test_spec['msg']) - test_name.set('test ' + test_spec['name']) - callable_object = test + test_name.set('Test ' + test_spec['name']) def run_test(): diff -r 038cbbef4539 Lib/idlelib/keybindingDialog.py --- a/Lib/idlelib/keybindingDialog.py Sat May 24 18:48:18 2014 -0400 +++ b/Lib/idlelib/keybindingDialog.py Sun May 25 21:13:26 2014 +0530 @@ -7,12 +7,13 @@ import sys 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 mapped to currentKeys - list, a list of all key sequence lists currently mapped to virtual events, for overlap checking + _htest - bool, change box location when running htest """ Toplevel.__init__(self, parent) self.configure(borderwidth=5) @@ -38,11 +39,14 @@ self.LoadFinalKeyList() self.withdraw() #hide while setting geometry self.update_idletasks() - self.geometry("+%d+%d" % - ((parent.winfo_rootx()+((parent.winfo_width()/2) - -(self.winfo_reqwidth()/2)), - parent.winfo_rooty()+((parent.winfo_height()/2) - -(self.winfo_reqheight()/2)) )) ) #centre dialog over parent + self.geometry( + "+%d+%d" % ( + parent.winfo_rootx() + + (parent.winfo_width()/2 - self.winfo_reqwidth()/2), + 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.wait_window() @@ -258,11 +262,5 @@ return keysOK if __name__ == '__main__': - #test the dialog - root=Tk() - def run(): - keySeq='' - dlg=GetKeysDialog(root,'Get Keys','find-again',[]) - print(dlg.result) - Button(root,text='Dialog',command=run).pack() - root.mainloop() + from idlelib.idle_test.htest import run + run(GetKeysDialog)