From 06313b79d5c0eaeed8f37838b5e9a064eecf0b98 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 11 May 2014 23:32:32 -0400 Subject: Issue #18104: Add idlelib/idle_test/htest.py with a few sample tests to begin consolidating and improving human-validated tests of Idle. Change other files as needed to work with htest. Running the module as __main__ runs all tests. --- Lib/idlelib/idle_test/htest.py | 91 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Lib/idlelib/idle_test/htest.py (limited to 'Lib/idlelib/idle_test/htest.py') diff --git a/Lib/idlelib/idle_test/htest.py b/Lib/idlelib/idle_test/htest.py new file mode 100644 index 00000000000..937da6f1a8c --- /dev/null +++ b/Lib/idlelib/idle_test/htest.py @@ -0,0 +1,91 @@ +'''Run a human test of Idle wndow, dialog, and other widget classes. + +run(klass) runs a test for one class. +runall() runs all the defined tests + +The file wih the widget class should end with +if __name__ == '__main__': + + from idlelib.idle_test.htest import run + run(X) +where X is a global object of the module. X must be a callable with a +.__name__ attribute that accepts a 'parent' attribute. X will usually 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 then contain an instance of this template. +_spec = { + 'file': '', + 'kwds': {'title': ''}, + 'msg': "" + } +with X.__name__ prepended to _spec. +File (no .py) is used in runall() to import the file and get the class. +Kwds is passed to X (**kwds) after 'parent' is added, to initialize X. +Msg. displayed is a window with a start button. hint as to how the user +might test the widget. Closing The box skips or ends the test. +''' +from importlib import import_module +import tkinter as tk + +# Template for class_spec dicts, copy and uncomment + +_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, , " + "'abc', or more that 30 chars are errors.\n" + "Close 'Get Name' with a valid entry (printed to Shell), [Cancel], or [X]", + } + +def run(klas): + "Test the widget class klas using _spec dict" + root = tk.Tk() + klas_spec = globals()[klas.__name__+'_spec'] + klas_kwds = klas_spec['kwds'] + klas_kwds['parent'] = root + # This presumes that Idle consistently uses 'parent' + def run_klas(): + widget = klas(**klas_kwds) + try: + print(widget.result) + except AttributeError: + pass + tk.Label(root, text=klas_spec['msg'], justify='left').pack() + tk.Button(root, text='Test ' + klas.__name__, command=run_klas).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']) + klas = getattr(mod, k[:-5]) + run(klas) + +if __name__ == '__main__': + runall() + -- cgit v1.2.3 From 8386fda15474e4dc1c0bb7d268ea7c12be438dc3 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 11 May 2014 23:35:09 -0400 Subject: whitespace --- Lib/idlelib/idle_test/htest.py | 1 - 1 file changed, 1 deletion(-) (limited to 'Lib/idlelib/idle_test/htest.py') diff --git a/Lib/idlelib/idle_test/htest.py b/Lib/idlelib/idle_test/htest.py index 937da6f1a8c..99f724c3427 100644 --- a/Lib/idlelib/idle_test/htest.py +++ b/Lib/idlelib/idle_test/htest.py @@ -88,4 +88,3 @@ def runall(): if __name__ == '__main__': runall() - -- cgit v1.2.3 From 6936159dcd9b8d24fff9c8825d974dd0e6ae5c87 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Thu, 15 May 2014 20:50:10 -0400 Subject: Issue #18104: revise docstrings, remove obsolete comments. --- Lib/idlelib/idle_test/htest.py | 61 ++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'Lib/idlelib/idle_test/htest.py') diff --git a/Lib/idlelib/idle_test/htest.py b/Lib/idlelib/idle_test/htest.py index 99f724c3427..001f7ee07ee 100644 --- a/Lib/idlelib/idle_test/htest.py +++ b/Lib/idlelib/idle_test/htest.py @@ -1,35 +1,38 @@ -'''Run a human test of Idle wndow, dialog, and other widget classes. +'''Run human tests of Idle's window, dialog, and popup widgets. -run(klass) runs a test for one class. -runall() runs all the defined tests +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 -The file wih the widget class should end with if __name__ == '__main__': from idlelib.idle_test.htest import run run(X) -where X is a global object of the module. X must be a callable with a -.__name__ attribute that accepts a 'parent' attribute. X will usually 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 then contain an instance of this template. +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': "" } -with X.__name__ prepended to _spec. -File (no .py) is used in runall() to import the file and get the class. -Kwds is passed to X (**kwds) after 'parent' is added, to initialize X. -Msg. displayed is a window with a start button. hint as to how the user -might test the widget. Closing The box skips or ends the test. + +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 -# Template for class_spec dicts, copy and uncomment _Editor_window_spec = { 'file': 'EditorWindow', @@ -61,30 +64,30 @@ GetCfgSectionNameDialog_spec = { "Close 'Get Name' with a valid entry (printed to Shell), [Cancel], or [X]", } -def run(klas): - "Test the widget class klas using _spec dict" +def run(test): + "Display a widget with callable *test* using a _spec dict" root = tk.Tk() - klas_spec = globals()[klas.__name__+'_spec'] - klas_kwds = klas_spec['kwds'] - klas_kwds['parent'] = root - # This presumes that Idle consistently uses 'parent' - def run_klas(): - widget = klas(**klas_kwds) + 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=klas_spec['msg'], justify='left').pack() - tk.Button(root, text='Test ' + klas.__name__, command=run_klas).pack() + 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.' + "Run all tests. Quick and dirty version." for k, d in globals().items(): if k.endswith('_spec'): mod = import_module('idlelib.' + d['file']) - klas = getattr(mod, k[:-5]) - run(klas) + test = getattr(mod, k[:-5]) + run(test) if __name__ == '__main__': runall() -- cgit v1.2.3