[Python-checkins] cpython (2.7): Issue #21477: Idle htest: modify run; add more tests.

terry.reedy python-checkins at python.org
Tue May 27 08:47:57 CEST 2014


http://hg.python.org/cpython/rev/72a8a107eed1
changeset:   90867:72a8a107eed1
branch:      2.7
parent:      90864:be77b213ace0
user:        Terry Jan Reedy <tjreedy at udel.edu>
date:        Tue May 27 02:47:38 2014 -0400
summary:
  Issue #21477: Idle htest: modify run; add more tests.
Patch by Saimadhav Heblikar. 2.7  backport of 90829, d7eea8f608c2.

files:
  Lib/idlelib/ClassBrowser.py     |    2 +-
  Lib/idlelib/ColorDelegator.py   |    8 +-
  Lib/idlelib/EditorWindow.py     |   10 +-
  Lib/idlelib/PathBrowser.py      |    2 +-
  Lib/idlelib/Percolator.py       |   50 ++++++--
  Lib/idlelib/StackViewer.py      |   39 ++++--
  Lib/idlelib/ToolTip.py          |    5 +-
  Lib/idlelib/idle_test/htest.py  |  112 +++++++++++++------
  Lib/idlelib/keybindingDialog.py |   26 ++--
  9 files changed, 158 insertions(+), 96 deletions(-)


diff --git a/Lib/idlelib/ClassBrowser.py b/Lib/idlelib/ClassBrowser.py
--- a/Lib/idlelib/ClassBrowser.py
+++ b/Lib/idlelib/ClassBrowser.py
@@ -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 --git a/Lib/idlelib/ColorDelegator.py b/Lib/idlelib/ColorDelegator.py
--- a/Lib/idlelib/ColorDelegator.py
+++ b/Lib/idlelib/ColorDelegator.py
@@ -261,13 +261,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"
+    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[:690])
+    text.insert("insert", source)
     text.pack(expand=1, fill="both")
     p = Percolator(text)
     d = ColorDelegator()
diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py
--- a/Lib/idlelib/EditorWindow.py
+++ b/Lib/idlelib/EditorWindow.py
@@ -1714,18 +1714,16 @@
 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("<<close-all-windows>>", edit.close_event)
+    edit.text.bind("<<close-all-windows>>", 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 --git a/Lib/idlelib/PathBrowser.py b/Lib/idlelib/PathBrowser.py
--- a/Lib/idlelib/PathBrowser.py
+++ b/Lib/idlelib/PathBrowser.py
@@ -1,6 +1,5 @@
 import os
 import sys
-import re
 import imp
 
 from idlelib.TreeWidget import TreeItem
@@ -95,6 +94,7 @@
 def _path_browser(parent):
     flist = PyShellFileList(parent)
     PathBrowser(flist, _htest=True)
+    parent.mainloop()
 
 if __name__ == "__main__":
     from unittest import main
diff --git a/Lib/idlelib/Percolator.py b/Lib/idlelib/Percolator.py
--- a/Lib/idlelib/Percolator.py
+++ b/Lib/idlelib/Percolator.py
@@ -52,7 +52,9 @@
             filter.setdelegate(None)
 
 
-def main():
+def _percolator(parent):
+    import Tkinter as tk
+    import re
     class Tracer(Delegator):
         def __init__(self, name):
             self.name = name
@@ -63,23 +65,39 @@
         def delete(self, *args):
             print self.name, ": delete", args
             self.delegate.delete(*args)
-    root = Tk()
-    root.wm_protocol("WM_DELETE_WINDOW", root.quit)
-    text = 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()
-    p.removefilter(t2)
-    root.mainloop()
-    p.insertfilter(t2)
-    p.removefilter(t1)
-    root.mainloop()
+
+    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()
 
 if __name__ == "__main__":
-    from Tkinter import *
-    main()
+    from idlelib.idle_test.htest import run
+    run(_percolator)
diff --git a/Lib/idlelib/StackViewer.py b/Lib/idlelib/StackViewer.py
--- a/Lib/idlelib/StackViewer.py
+++ b/Lib/idlelib/StackViewer.py
@@ -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:
@@ -121,17 +124,29 @@
             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()
 
-def _test():
-    try:
-        import testcode
-        reload(testcode)
-    except:
-        sys.last_type, sys.last_value, sys.last_traceback = sys.exc_info()
-    from Tkinter import Tk
-    root = Tk()
-    StackBrowser(None, top=root)
-    root.mainloop()
+    # inject stack trace to sys
+    sys.last_type = exc_type
+    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)
diff --git a/Lib/idlelib/ToolTip.py b/Lib/idlelib/ToolTip.py
--- a/Lib/idlelib/ToolTip.py
+++ b/Lib/idlelib/ToolTip.py
@@ -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 --git a/Lib/idlelib/idle_test/htest.py b/Lib/idlelib/idle_test/htest.py
--- a/Lib/idlelib/idle_test/htest.py
+++ b/Lib/idlelib/idle_test/htest.py
@@ -40,7 +40,7 @@
              },
     'msg': "Test every button. Ensure Python, TK and IDLE versions "
            "are correctly displayed.\n [Close] to exit.",
-     }
+    }
 
 _calltip_window_spec = {
     'file': 'CallTipWindow',
@@ -53,9 +53,10 @@
     'file': 'ClassBrowser',
     '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",
-     }
+           "applicable), methods and functions.\nToggle nested items.\n"
+           "Double clicking on items prints a traceback for an exception "
+           "that is ignored."
+    }
 
 _color_delegator_spec = {
     'file': 'ColorDelegator',
@@ -74,11 +75,11 @@
            "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"
+    }
 
 GetCfgSectionNameDialog_spec = {
     'file': 'configSectionNameDialog',
@@ -91,6 +92,7 @@
            "Close 'Get Name' with a valid entry (printed to Shell), "
            "[Cancel], or [X]",
     }
+
 GetHelpSourceDialog_spec = {
     'file': 'configHelpSourceEdit',
     'kwds': {'title': 'Get helpsource',
@@ -103,10 +105,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"
+           "<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 = {
     '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 = {
@@ -115,17 +134,16 @@
     'msg': "Test the following bindings\n"
            "<Control-o> to display open window from file dialog.\n"
            "<Control-s> to save the file\n"
-
     }
 
 _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, <Control-Key>,\n"
-           "<Alt-Key-a>, <Control-Key-a>, <Alt-Control-Key-a>, \n"
-           "<Control-Button-1>, <Alt-Button-1> 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, "
+           "<Control-Key>,\n<Alt-Key-a>, <Control-Key-a>, "
+           "<Alt-Control-Key-a>, \n<Control-Button-1>, <Alt-Button-1> and "
+           "focusing out of the window\nare sequences to be tested."
     }
 
 _multistatus_bar_spec = {
@@ -146,18 +164,38 @@
 _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."
+    'msg': "Test for correct display of all paths in sys.path.\n"
+           "Toggle nested items upto the lowest level.\n"
+           "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 = {
     '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"
+           "Expand 'idlelib ...' and '<locals>'.\n"
+           "Check that exc_value, exc_tb, and exc_type are correct.\n"
     }
 
 _tabbed_pages_spec = {
@@ -189,7 +227,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 +236,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('')]
@@ -231,11 +267,11 @@
     def next():
         if len(test_list) == 1:
             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'])
         test_name[0].set('test ' + test_spec['name'])
-        callable_object[0] = test
-
 
     def run_test():
         widget = callable_object[0](**test_kwds[0])
diff --git a/Lib/idlelib/keybindingDialog.py b/Lib/idlelib/keybindingDialog.py
--- a/Lib/idlelib/keybindingDialog.py
+++ b/Lib/idlelib/keybindingDialog.py
@@ -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)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list