cpython: d90905960803 (original) (raw)
Mercurial > cpython
changeset 90892:d90905960803 3.4
Issue #21477: Add htests for GrepDialog, UndoDelegator, and configDialog. Put instructions in a fixed size scrollable Text. Patch by Saimadhav Heblikar. [#21477]
Terry Jan Reedy tjreedy@udel.edu | |
---|---|
date | Thu, 29 May 2014 01:46:26 -0400 |
parents | 16f399588b2a |
children | 0eedac3d0b0a baa7b5555656 |
files | Lib/idlelib/GrepDialog.py Lib/idlelib/ObjectBrowser.py Lib/idlelib/UndoDelegator.py Lib/idlelib/configDialog.py Lib/idlelib/idle_test/htest.py |
diffstat | 5 files changed, 108 insertions(+), 21 deletions(-)[+] [-] Lib/idlelib/GrepDialog.py 23 Lib/idlelib/ObjectBrowser.py 3 Lib/idlelib/UndoDelegator.py 21 Lib/idlelib/configDialog.py 17 Lib/idlelib/idle_test/htest.py 65 |
line wrap: on
line diff
--- a/Lib/idlelib/GrepDialog.py +++ b/Lib/idlelib/GrepDialog.py @@ -120,8 +120,31 @@ class GrepDialog(SearchDialogBase): 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))
- def show_grep_dialog():
text.tag_add(SEL, "1.0", END)[](#l1.19)
grep(text, flist=flist)[](#l1.20)
text.tag_remove(SEL, "1.0", END)[](#l1.21)
- 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) +
--- a/Lib/idlelib/ObjectBrowser.py +++ b/Lib/idlelib/ObjectBrowser.py @@ -126,8 +126,9 @@ def _object_browser(parent): 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 + 150)) root.configure(bd=0, bg="yellow") root.focus_set() sc = ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)
--- a/Lib/idlelib/UndoDelegator.py +++ b/Lib/idlelib/UndoDelegator.py @@ -336,17 +336,30 @@ class CommandSequence(Command): self.depth = self.depth + incr return self.depth -def main(): +def _undo_delegator(parent): from idlelib.Percolator import Percolator root = Tk()
- 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":
--- a/Lib/idlelib/configDialog.py +++ b/Lib/idlelib/configDialog.py @@ -25,14 +25,19 @@ from idlelib import macosxSupport class ConfigDialog(Toplevel):
- def init(self,parent,title,_htest=False):
"""[](#l4.9)
_htest - bool, change box location when running htest[](#l4.10)
"""[](#l4.11) Toplevel.__init__(self, parent)[](#l4.12) self.wm_withdraw()[](#l4.13)
self.configure(borderwidth=5) self.title('IDLE Preferences')
if _htest:[](#l4.17)
parent.instance_dict = {}[](#l4.18) self.geometry("+%d+%d" % (parent.winfo_rootx()+20,[](#l4.19)
parent.winfo_rooty()+30))[](#l4.20)
parent.winfo_rooty()+(30 if not _htest else 150)))[](#l4.21) #Theme Elements. Each theme element key is its display name.[](#l4.22) #The first value of the tuple is the sample area tag name.[](#l4.23) #The second value is the display name list sort index.[](#l4.24)
@@ -1140,9 +1145,5 @@ class ConfigDialog(Toplevel): pass if name == 'main':
- #test the dialog
- root=Tk()
- Button(root,text='Dialog',
command=lambda:ConfigDialog(root,'Settings')).pack()[](#l4.32)
- root.instance_dict={}
- root.mainloop()
--- a/Lib/idlelib/idle_test/htest.py +++ b/Lib/idlelib/idle_test/htest.py @@ -31,6 +31,7 @@ msg: displayed in a master window. Hints 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 @@ AboutDialog_spec = { "The default color scheme is in idlelib/config-highlight.def" } +ConfigDialog_spec = {
- 'file': 'configDialog',
- 'kwds': {'title': 'Settings',
'_htest': True,},[](#l5.18)
- 'msg': "IDLE preferences dialog.\n"
"In the 'Fonts/Tabs' tab, changing font face, should update the "[](#l5.20)
"font face of the text in the area below it.\nIn the "[](#l5.21)
"'Highlighting' tab, try different color schemes. Clicking "[](#l5.22)
"items in the sample program should update the choices above it."[](#l5.23)
"\nIn the 'Keys' and 'General' tab, test settings of interest."[](#l5.24)
"\n[Ok] to close the dialog.[Apply] to apply the settings and "[](#l5.25)
"and [Cancel] to revert all changes.\nRe-run the test to ensure "[](#l5.26)
"changes made have persisted."[](#l5.27)
- }
+ _dyn_option_menu_spec = { 'file': 'dynOptionMenuWidget', 'kwds': {}, @@ -121,6 +137,16 @@ GetKeysDialog_spec = { "entry is used." } +_grep_dialog_spec = {
- 'file': 'GrepDialog',
- 'kwds': {},
- 'msg': "Click the 'Show GrepDialog' button.\n"
"Test the various 'Find-in-files' functions.\n"[](#l5.41)
"The results should be displayed in a new '*Output*' window.\n"[](#l5.42)
"'Right-click'->'Goto file/line' anywhere in the search results "[](#l5.43)
"should open that file \nin a new EditorWindow."[](#l5.44)
- }
+ _help_dialog_spec = { 'file': 'EditorWindow', 'kwds': {}, @@ -186,7 +212,7 @@ GetKeysDialog_spec = { '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'."[](#l5.54)
} _search_dialog_spec = { @@ -194,7 +220,7 @@ GetKeysDialog_spec = { 'kwds': {}, 'msg': "Click the 'Search' button.\n" "Test various search options in the 'Search dialog'.\n""Click [Close] or [X] to close 'Replace Dialog'."[](#l5.55)
"Click [Close] or [X] to close to the 'Search Dialog'."[](#l5.63)
} _scrolled_list_spec = { @@ -247,6 +273,15 @@ TextViewer_spec = { "Click on folders upto to the lowest level." } +_undo_delegator_spec = {"Click [Close] or [X] to close 'Search Dialog'."[](#l5.64)
- 'file': 'UndoDelegator',
- 'kwds': {},
- 'msg': "Click [Undo] to undo any action.\n"
"Click [Redo] to redo any action.\n"[](#l5.76)
"Click [Dump] to dump the current state "[](#l5.77)
"by printing to the console or the IDLE shell.\n"[](#l5.78)
- }
+ _widget_redirector_spec = { 'file': 'WidgetRedirector', 'kwds': {}, @@ -256,6 +291,20 @@ TextViewer_spec = { def run(*tests): root = tk.Tk()
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,22 +321,24 @@ def run(*tests): test = getattr(mod, test_name) test_list.append((test_spec, test))
nonlocal test_name, callable_object, test_kwds[](#l5.118) if len(test_list) == 1:[](#l5.119) next_button.pack_forget()[](#l5.120) test_spec, callable_object = test_list.pop()[](#l5.121) test_kwds = test_spec['kwds'][](#l5.122) test_kwds['parent'] = root[](#l5.123)
help_string.set(test_spec['msg'])[](#l5.124) test_name.set('Test ' + test_spec['name'])[](#l5.125)
text.configure(state='normal') # enable text editing[](#l5.127)
text.delete('1.0','end')[](#l5.128)
text.insert("1.0",test_spec['msg'])[](#l5.129)
text.configure(state='disabled') # preserve read-only property[](#l5.130)
def run_test(): widget = callable_object(**test_kwds) @@ -296,8 +347,6 @@ def run(*tests): except AttributeError: pass