diff options
author | Larry Hastings <larry@hastings.org> | 2014-05-18 04:05:10 (GMT) |
---|---|---|
committer | Larry Hastings <larry@hastings.org> | 2014-05-18 04:05:10 (GMT) |
commit | 3a260d228b32b04a88d947b887bf81759e8e5f10 (patch) | |
tree | e4a34e9cbbf877cf021ffba743ddbf54e17526b7 /Lib/idlelib | |
parent | 2110603344316d927e6d639275c12f5da78601d5 (diff) | |
parent | b1a1ec3151155a1ae65831793b4a5b7a87d9d09f (diff) | |
download | cpython-3a260d228b32b04a88d947b887bf81759e8e5f10.zip cpython-3a260d228b32b04a88d947b887bf81759e8e5f10.tar.gz cpython-3a260d228b32b04a88d947b887bf81759e8e5f10.tar.bz2 |
Merge.
Diffstat (limited to 'Lib/idlelib')
-rw-r--r-- | Lib/idlelib/EditorWindow.py | 16 | ||||
-rw-r--r-- | Lib/idlelib/aboutDialog.py | 11 | ||||
-rw-r--r-- | Lib/idlelib/configSectionNameDialog.py | 28 | ||||
-rw-r--r-- | Lib/idlelib/idle_test/htest.py | 93 |
4 files changed, 116 insertions, 32 deletions
diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py index cdb6775..06fb137 100644 --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -79,6 +79,8 @@ class HelpDialog(object): self.parent = None helpDialog = HelpDialog() # singleton instance +def _Help_dialog(parent): # wrapper for htest + helpDialog.show_dialog(parent) class EditorWindow(object): @@ -1064,7 +1066,7 @@ class EditorWindow(object): try: try: mod = importlib.import_module('.' + name, package=__package__) - except ImportError: + except (ImportError, TypeError): mod = importlib.import_module(name) except ImportError: print("\nFailed to import extension: ", name) @@ -1700,19 +1702,21 @@ def fixwordbreaks(root): tk.call('set', 'tcl_nonwordchars', '[^a-zA-Z0-9_]') -def test(): - root = Tk() +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) - root.mainloop() - root.destroy() if __name__ == '__main__': - test() + from idlelib.idle_test.htest import run + if len(sys.argv) <= 1: + run(_Help_dialog) + run(_Editor_window) diff --git a/Lib/idlelib/aboutDialog.py b/Lib/idlelib/aboutDialog.py index 7fe1ab8..2b58013 100644 --- a/Lib/idlelib/aboutDialog.py +++ b/Lib/idlelib/aboutDialog.py @@ -12,7 +12,7 @@ class AboutDialog(Toplevel): """Modal about dialog for idle """ - def __init__(self,parent,title): + def __init__(self, parent, title): Toplevel.__init__(self, parent) self.configure(borderwidth=5) self.geometry("+%d+%d" % (parent.winfo_rootx()+30, @@ -136,10 +136,5 @@ class AboutDialog(Toplevel): self.destroy() if __name__ == '__main__': - # test the dialog - root = Tk() - def run(): - from idlelib import aboutDialog - aboutDialog.AboutDialog(root, 'About') - Button(root, text='Dialog', command=run).pack() - root.mainloop() + from idlelib.idle_test.htest import run + run(AboutDialog) diff --git a/Lib/idlelib/configSectionNameDialog.py b/Lib/idlelib/configSectionNameDialog.py index b05e38e..5137836 100644 --- a/Lib/idlelib/configSectionNameDialog.py +++ b/Lib/idlelib/configSectionNameDialog.py @@ -8,10 +8,11 @@ from tkinter import * import tkinter.messagebox as tkMessageBox class GetCfgSectionNameDialog(Toplevel): - def __init__(self, parent, title, message, used_names): + def __init__(self, parent, title, message, used_names, _htest=False): """ message - string, informational message to display used_names - string collection, names already in use for validity check + _htest - bool, change box location when running htest """ Toplevel.__init__(self, parent) self.configure(borderwidth=5) @@ -30,11 +31,12 @@ class GetCfgSectionNameDialog(Toplevel): self.messageInfo.config(width=self.frameMain.winfo_reqwidth()) 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 + 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 100) + ) ) #centre dialog over parent (or below htest box) self.deiconify() #geometry set, unhide self.wait_window() @@ -92,15 +94,5 @@ if __name__ == '__main__': import unittest unittest.main('idlelib.idle_test.test_config_name', verbosity=2, exit=False) - # also human test the dialog - root = Tk() - def run(): - dlg=GetCfgSectionNameDialog(root,'Get Name', - "After the text entered with [Ok] is stripped, <nothing>, " - "'abc', or more that 30 chars are errors. " - "Close with a valid entry (printed), [Cancel], or [X]", - {'abc'}) - print(dlg.result) - Message(root, text='').pack() # will be needed for oher dialog tests - Button(root, text='Click to begin dialog test', command=run).pack() - root.mainloop() + from idlelib.idle_test.htest import run + run(GetCfgSectionNameDialog) diff --git a/Lib/idlelib/idle_test/htest.py b/Lib/idlelib/idle_test/htest.py new file mode 100644 index 0000000..001f7ee --- /dev/null +++ b/Lib/idlelib/idle_test/htest.py @@ -0,0 +1,93 @@ +'''Run human tests of Idle's window, dialog, and popup widgets. + +run(test): run *test*, a callable that causes a widget to be displayed. +runall(): run all tests defined in this file. + +Let X be a global name bound to a widget callable. End the module with + +if __name__ == '__main__': + <unittest, if there is one> + from idlelib.idle_test.htest import run + run(X) + +The X object must have a .__name__ attribute and a 'parent' parameter. +X will often be a widget class, but a callable instance with .__name__ +or a wrapper function also work. The name of wrapper functions, like +'_Editor_Window', should start with '_'. + +This file must contain a matching instance of the folling template, +with X.__name__ prepended, as in '_Editor_window_spec ...'. + +_spec = { + 'file': '', + 'kwds': {'title': ''}, + 'msg': "" + } + +file (no .py): used in runall() to import the file and get X. +kwds: passed to X (**kwds), after 'parent' is added, to initialize X. +title: an example; used for some widgets, delete if not. +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 +import tkinter as tk + + +_Editor_window_spec = { + 'file': 'EditorWindow', + 'kwds': {}, + 'msg': "Test editor functions of interest" + } + +_Help_dialog_spec = { + 'file': 'EditorWindow', + 'kwds': {}, + 'msg': "If the help text displays, this works" + } + +AboutDialog_spec = { + 'file': 'aboutDialog', + 'kwds': {'title': 'About test'}, + 'msg': "Try each button" + } + + +GetCfgSectionNameDialog_spec = { + 'file': 'configSectionNameDialog', + 'kwds': {'title':'Get Name', + 'message':'Enter something', + 'used_names': {'abc'}, + '_htest': True}, + 'msg': "After the text entered with [Ok] is stripped, <nothing>, " + "'abc', or more that 30 chars are errors.\n" + "Close 'Get Name' with a valid entry (printed to Shell), [Cancel], or [X]", + } + +def run(test): + "Display a widget with callable *test* using a _spec dict" + root = tk.Tk() + test_spec = globals()[test.__name__ + '_spec'] + test_kwds = test_spec['kwds'] + test_kwds['parent'] = root + + def run_test(): + widget = test(**test_kwds) + try: + print(widget.result) + except AttributeError: + pass + tk.Label(root, text=test_spec['msg'], justify='left').pack() + tk.Button(root, text='Test ' + test.__name__, command=run_test).pack() + root.mainloop() + +def runall(): + "Run all tests. Quick and dirty version." + for k, d in globals().items(): + if k.endswith('_spec'): + mod = import_module('idlelib.' + d['file']) + test = getattr(mod, k[:-5]) + run(test) + +if __name__ == '__main__': + runall() |