diff options
author | Terry Jan Reedy <tjreedy@udel.edu> | 2014-05-29 05:46:26 (GMT) |
---|---|---|
committer | Terry Jan Reedy <tjreedy@udel.edu> | 2014-05-29 05:46:26 (GMT) |
commit | 2e8234a5975a79773584220a8f4d61f5fc5cf8e9 (patch) | |
tree | 8437423a36234e530e2eee40d7c8a6e5846a1a40 | |
parent | a5b257af22976b9fdeb1907f8d0c50ef9b97facb (diff) | |
download | cpython-2e8234a5975a79773584220a8f4d61f5fc5cf8e9.zip cpython-2e8234a5975a79773584220a8f4d61f5fc5cf8e9.tar.gz cpython-2e8234a5975a79773584220a8f4d61f5fc5cf8e9.tar.bz2 |
Issue #21477: Add htests for GrepDialog, UndoDelegator, and configDialog.
Put instructions in a fixed size scrollable Text. Patch by Saimadhav Heblikar.
-rw-r--r-- | Lib/idlelib/GrepDialog.py | 23 | ||||
-rw-r--r-- | Lib/idlelib/ObjectBrowser.py | 3 | ||||
-rw-r--r-- | Lib/idlelib/UndoDelegator.py | 21 | ||||
-rw-r--r-- | Lib/idlelib/configDialog.py | 17 | ||||
-rw-r--r-- | Lib/idlelib/idle_test/htest.py | 65 |
5 files changed, 108 insertions, 21 deletions
diff --git a/Lib/idlelib/GrepDialog.py b/Lib/idlelib/GrepDialog.py index f73d70a..324c1a7f 100644 --- 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)) + + 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 index 0f3c1bc..7b57aa4 100644 --- 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 + 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 index d2ef638..04c1cf5 100644 --- 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.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 index fefe42b..30238af 100644 --- 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): + 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. @@ -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() - 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 index af9cb3d..2406c63 100644 --- 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 as to how the user might 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 @@ _color_delegator_spec = { "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 @@ 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" + "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 @@ _replace_dialog_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'." + "Click [Close] or [X] to close 'Replace Dialog'." } _search_dialog_spec = { @@ -194,7 +220,7 @@ _search_dialog_spec = { '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 'Search Dialog'." } _scrolled_list_spec = { @@ -247,6 +273,15 @@ _tree_widget_spec = { "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,20 @@ _widget_redirector_spec = { 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,22 +321,24 @@ def run(*tests): 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 - def next(): - nonlocal help_string, test_name, callable_object, test_kwds + + nonlocal test_name, callable_object, test_kwds if len(test_list) == 1: next_button.pack_forget() 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']) + 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(**test_kwds) @@ -296,8 +347,6 @@ def run(*tests): except AttributeError: pass - label = tk.Label(root, textvariable=help_string, justify='left') - label.pack() button = tk.Button(root, textvariable=test_name, command=run_test) button.pack() next_button = tk.Button(root, text="Next", command=next) |