[Python-checkins] cpython (2.7): Issue #21477: Add htests for GrepDialog, UndoDelegator, and configDialog.

terry.reedy python-checkins at python.org
Thu May 29 07:47:13 CEST 2014


http://hg.python.org/cpython/rev/90dab7696e89
changeset:   90891:90dab7696e89
branch:      2.7
parent:      90882:8e5c65719c12
user:        Terry Jan Reedy <tjreedy at udel.edu>
date:        Thu May 29 01:46:16 2014 -0400
summary:
  Issue #21477: Add htests for GrepDialog, UndoDelegator, and configDialog.
Put instructions in a fixed size scrollable Text. Patch by Saimadhav Heblikar.

files:
  Lib/idlelib/GrepDialog.py      |  24 ++++++++
  Lib/idlelib/ObjectBrowser.py   |   3 +-
  Lib/idlelib/UndoDelegator.py   |  21 +++++-
  Lib/idlelib/configDialog.py    |  17 +++--
  Lib/idlelib/idle_test/htest.py |  63 +++++++++++++++++++--
  5 files changed, 109 insertions(+), 19 deletions(-)


diff --git a/Lib/idlelib/GrepDialog.py b/Lib/idlelib/GrepDialog.py
--- a/Lib/idlelib/GrepDialog.py
+++ b/Lib/idlelib/GrepDialog.py
@@ -120,8 +120,32 @@
             self.top.grab_release()
             self.top.withdraw()
 
+def _grep_dialog(parent):
+    from idlelib.PyShell import PyShellFileList
+    root = Tk()
+    root.title("Test GrepDialog")
+    width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
+    root.geometry("+%d+%d"%(x, y + 150))
+
+    flist = PyShellFileList(root)
+    text = Text(root, height=5)
+    text.pack()
+
+    def show_grep_dialog():
+        text.tag_add(SEL, "1.0", END)
+        grep(text, flist=flist)
+        text.tag_remove(SEL, "1.0", END)
+
+    button = Button(root, text="Show GrepDialog", command=show_grep_dialog)
+    button.pack()
+    root.mainloop()
+
+
 if __name__ == "__main__":
     # A human test is a bit tricky since EditorWindow() imports this module.
     # Hence Idle must be restarted after editing this file for a live test.
     import unittest
     unittest.main('idlelib.idle_test.test_grep', verbosity=2, exit=False)
+
+    from idlelib.idle_test.htest import run
+    run(_grep_dialog)
diff --git a/Lib/idlelib/ObjectBrowser.py b/Lib/idlelib/ObjectBrowser.py
--- a/Lib/idlelib/ObjectBrowser.py
+++ b/Lib/idlelib/ObjectBrowser.py
@@ -139,8 +139,9 @@
     import sys
     from Tkinter import Tk
     root = Tk()
+    root.title("Test ObjectBrowser")
     width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
-    root.geometry("+%d+%d"%(x, y + 100))
+    root.geometry("+%d+%d"%(x, y + 150))
     root.configure(bd=0, bg="yellow")
     root.focus_set()
     sc = ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)
diff --git a/Lib/idlelib/UndoDelegator.py b/Lib/idlelib/UndoDelegator.py
--- a/Lib/idlelib/UndoDelegator.py
+++ b/Lib/idlelib/UndoDelegator.py
@@ -336,17 +336,30 @@
         self.depth = self.depth + incr
         return self.depth
 
-def main():
+def _undo_delegator(parent):
     from idlelib.Percolator import Percolator
     root = Tk()
-    root.wm_protocol("WM_DELETE_WINDOW", root.quit)
-    text = Text()
+    root.title("Test UndoDelegator")
+    width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
+    root.geometry("+%d+%d"%(x, y + 150))
+
+    text = Text(root)
+    text.config(height=10)
     text.pack()
     text.focus_set()
     p = Percolator(text)
     d = UndoDelegator()
     p.insertfilter(d)
+
+    undo = Button(root, text="Undo", command=lambda:d.undo_event(None))
+    undo.pack(side='left')
+    redo = Button(root, text="Redo", command=lambda:d.redo_event(None))
+    redo.pack(side='left')
+    dump = Button(root, text="Dump", command=lambda:d.dump_event(None))
+    dump.pack(side='left')
+
     root.mainloop()
 
 if __name__ == "__main__":
-    main()
+    from idlelib.idle_test.htest import run
+    run(_undo_delegator)
diff --git a/Lib/idlelib/configDialog.py b/Lib/idlelib/configDialog.py
--- a/Lib/idlelib/configDialog.py
+++ b/Lib/idlelib/configDialog.py
@@ -23,14 +23,19 @@
 
 class ConfigDialog(Toplevel):
 
-    def __init__(self,parent,title):
+    def __init__(self,parent,title,_htest=False):
+        """
+        _htest - bool, change box location when running htest
+        """
         Toplevel.__init__(self, parent)
         self.wm_withdraw()
 
         self.configure(borderwidth=5)
         self.title('IDLE Preferences')
+        if _htest:
+            parent.instance_dict = {}
         self.geometry("+%d+%d" % (parent.winfo_rootx()+20,
-                parent.winfo_rooty()+30))
+                parent.winfo_rooty()+(30 if not _htest else 150)))
         #Theme Elements. Each theme element key is its display name.
         #The first value of the tuple is the sample area tag name.
         #The second value is the display name list sort index.
@@ -1151,9 +1156,5 @@
         pass
 
 if __name__ == '__main__':
-    #test the dialog
-    root=Tk()
-    Button(root,text='Dialog',
-            command=lambda:ConfigDialog(root,'Settings')).pack()
-    root.instance_dict={}
-    root.mainloop()
+    from idlelib.idle_test.htest import run
+    run(ConfigDialog)
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
@@ -31,6 +31,7 @@
   test the widget. Close the window to skip or end the test.
 '''
 from importlib import import_module
+from idlelib.macosxSupport import _initializeTkVariantTests
 import Tkinter as tk
 
 AboutDialog_spec = {
@@ -67,6 +68,21 @@
            "The default color scheme is in idlelib/config-highlight.def"
     }
 
+ConfigDialog_spec = {
+    'file': 'configDialog',
+    'kwds': {'title': 'Settings',
+             '_htest': True,},
+    'msg': "IDLE preferences dialog.\n"
+           "In the 'Fonts/Tabs' tab, changing font face, should update the "
+           "font face of the text in the area below it.\nIn the "
+           "'Highlighting' tab, try different color schemes. Clicking "
+           "items in the sample program should update the choices above it."
+           "\nIn the 'Keys' and 'General' tab, test settings of interest."
+           "\n[Ok] to close the dialog.[Apply] to apply the settings and "
+           "and [Cancel] to revert all changes.\nRe-run the test to ensure "
+           "changes made have persisted."
+    }
+
 _dyn_option_menu_spec = {
     'file': 'dynOptionMenuWidget',
     'kwds': {},
@@ -121,6 +137,16 @@
            "entry is used."
     }
 
+_grep_dialog_spec = {
+    'file': 'GrepDialog',
+    'kwds': {},
+    'msg': "Click the 'Show GrepDialog' button.\n"
+           "Test the various 'Find-in-files' functions.\n"
+           "The results should be displayed in a new '*Output*' window.\n"
+           "'Right-click'->'Goto file/line' anywhere in the search results "
+           "should open that file \nin a new EditorWindow."
+    }
+
 _help_dialog_spec = {
     'file': 'EditorWindow',
     'kwds': {},
@@ -186,7 +212,7 @@
     'kwds': {},
     'msg': "Click the 'Replace' button.\n"
            "Test various replace options in the 'Replace dialog'.\n"
-           "Click [Close] or [X] to close to the 'Replace Dialog'."
+           "Click [Close] or [X] to close the 'Replace Dialog'."
     }
 
 _search_dialog_spec = {
@@ -194,7 +220,7 @@
     'kwds': {},
     'msg': "Click the 'Search' button.\n"
            "Test various search options in the 'Search dialog'.\n"
-           "Click [Close] or [X] to close to the 'Search Dialog'."
+           "Click [Close] or [X] to close the 'Search Dialog'."
     }
 
 _scrolled_list_spec = {
@@ -247,6 +273,15 @@
            "Click on folders upto to the lowest level."
     }
 
+_undo_delegator_spec = {
+    'file': 'UndoDelegator',
+    'kwds': {},
+    'msg': "Click [Undo] to undo any action.\n"
+           "Click [Redo] to redo any action.\n"
+           "Click [Dump] to dump the current state "
+           "by printing to the console or the IDLE shell.\n"
+    }
+
 _widget_redirector_spec = {
     'file': 'WidgetRedirector',
     'kwds': {},
@@ -256,6 +291,21 @@
 
 def run(*tests):
     root = tk.Tk()
+    root.title('IDLE htest')
+    root.resizable(0, 0)
+    _initializeTkVariantTests(root)
+
+    # a scrollable Label like constant width text widget.
+    frameLabel = tk.Frame(root, padx=10)
+    frameLabel.pack()
+    text = tk.Text(frameLabel, wrap='word')
+    text.configure(bg=root.cget('bg'), relief='flat', height=4, width=70)
+    scrollbar = tk.Scrollbar(frameLabel, command=text.yview)
+    text.config(yscrollcommand=scrollbar.set)
+    scrollbar.pack(side='right', fill='y', expand=False)
+    text.pack(side='left', fill='both', expand=True)
+
+
     test_list = [] # List of tuples of the form (spec, callable widget)
     if tests:
         for test in tests:
@@ -272,7 +322,6 @@
                 test = getattr(mod, test_name)
                 test_list.append((test_spec, test))
 
-    help_string = [tk.StringVar('')]
     test_name = [tk.StringVar('')]
     callable_object = [None]
     test_kwds = [None]
@@ -284,9 +333,13 @@
         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'])
 
+        text.configure(state='normal') # enable text editing
+        text.delete('1.0','end')
+        text.insert("1.0",test_spec['msg'])
+        text.configure(state='disabled') # preserve read-only property
+
     def run_test():
         widget = callable_object[0](**test_kwds[0])
         try:
@@ -294,8 +347,6 @@
         except AttributeError:
             pass
 
-    label = tk.Label(root, textvariable=help_string[0], justify='left')
-    label.pack()
     button = tk.Button(root, textvariable=test_name[0], command=run_test)
     button.pack()
     next_button = tk.Button(root, text="Next", command=next)

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


More information about the Python-checkins mailing list