|
1 | 1 | '''Run human tests of Idle's window, dialog, and popup widgets. |
2 | 2 |
|
3 | 3 | run(*tests) |
4 | | -Run each callable in tests after finding the matching test spec in this file. |
5 | | -If there are none, run an htest for each spec dict in this file after finding |
6 | | -the matching callable in the module named in the spec. |
| 4 | +Create a master Tk window. Within that, run each callable in tests |
| 5 | +after finding the matching test spec in this file. If tests is empty, |
| 6 | +run an htest for each spec dict in this file after finding the matching |
| 7 | +callable in the module named in the spec. Close the window to skip or |
| 8 | +end the test. |
| 9 | +
|
| 10 | +In a tested module, let X be a global name bound to a callable (class |
| 11 | +or function) whose .__name__ attrubute is also X (the usual situation). |
| 12 | +The first parameter of X must be 'parent'. When called, the parent |
| 13 | +argument will be the root window. X must create a child Toplevel |
| 14 | +window (or subclass thereof). The Toplevel may be a test widget or |
| 15 | +dialog, in which case the callable is the corresonding class. Or the |
| 16 | +Toplevel may contain the widget to be tested or set up a context in |
| 17 | +which a test widget is invoked. In this latter case, the callable is a |
| 18 | +wrapper function that sets up the Toplevel and other objects. Wrapper |
| 19 | +function names, such as _editor_window', should start with '_'. |
| 20 | +
|
7 | 21 |
|
8 | | -In a tested module, let X be a global name bound to a widget callable. |
9 | 22 | End the module with |
10 | 23 |
|
11 | 24 | if __name__ == '__main__': |
12 | 25 | <unittest, if there is one> |
13 | 26 | from idlelib.idle_test.htest import run |
14 | 27 | run(X) |
15 | 28 |
|
16 | | -The X object must have a .__name__ attribute and a 'parent' parameter. |
17 | | -X will often be a widget class, but a callable instance with .__name__ |
18 | | -or a wrapper function also work. The name of wrapper functions, like |
19 | | -'_editor_window', should start with '_'. |
| 29 | +To have wrapper functions and test invocation code ignored by coveragepy |
| 30 | +reports, put '# htest #' on the def statement header line. |
| 31 | +
|
| 32 | +def _wrapper(parent): # htest # |
| 33 | +
|
| 34 | +Also make sure that the 'if __name__' line matches the above. Then have |
| 35 | +make sure that .coveragerc includes the following. |
| 36 | +
|
| 37 | +[report] |
| 38 | +exclude_lines = |
| 39 | + .*# htest # |
| 40 | + if __name__ == .__main__.: |
20 | 41 |
|
21 | | -This file must contain a matching instance of the following template, |
22 | | -with X.__name__ prepended, as in '_editor_window_spec ...'. |
| 42 | +(The "." instead of "'" is intentional and necessary.) |
| 43 | +
|
| 44 | +
|
| 45 | +To run any X, this file must contain a matching instance of the |
| 46 | +following template, with X.__name__ prepended to '_spec'. |
| 47 | +When all tests are run, the prefix is use to get X. |
23 | 48 |
|
24 | 49 | _spec = { |
25 | 50 | 'file': '', |
26 | 51 | 'kwds': {'title': ''}, |
27 | 52 | 'msg': "" |
28 | 53 | } |
29 | 54 |
|
30 | | -file (no .py): used in run() to import the file and get X. |
31 | | -kwds: passed to X (**kwds), after 'parent' is added, to initialize X. |
32 | | -title: an example; used for some widgets, delete if not. |
33 | | -msg: displayed in a master window. Hints as to how the user might |
34 | | - test the widget. Close the window to skip or end the test. |
| 55 | +file (no .py): run() imports file.py. |
| 56 | +kwds: augmented with {'parent':root} and passed to X as **kwds. |
| 57 | +title: an example kwd; some widgets need this, delete if not. |
| 58 | +msg: master window hints about testing the widget. |
35 | 59 |
|
36 | | -Modules not being tested at the moment: |
| 60 | +
|
| 61 | +Modules and classes not being tested at the moment: |
37 | 62 | PyShell.PyShellEditorWindow |
38 | 63 | Debugger.Debugger |
39 | 64 | AutoCompleteWindow.AutoCompleteWindow |
40 | 65 | OutputWindow.OutputWindow (indirectly being tested with grep test) |
41 | 66 | ''' |
| 67 | + |
42 | 68 | from importlib import import_module |
43 | 69 | from idlelib.macosxSupport import _initializeTkVariantTests |
44 | 70 | import tkinter as tk |
|
79 | 105 |
|
80 | 106 | ConfigDialog_spec = { |
81 | 107 | 'file': 'configDialog', |
82 | | - 'kwds': {'title': 'Settings', |
| 108 | + 'kwds': {'title': 'ConfigDialogTest', |
83 | 109 | '_htest': True,}, |
84 | 110 | 'msg': "IDLE preferences dialog.\n" |
85 | 111 | "In the 'Fonts/Tabs' tab, changing font face, should update the " |
|
92 | 118 | "changes made have persisted." |
93 | 119 | } |
94 | 120 |
|
| 121 | +# TODO Improve message |
95 | 122 | _dyn_option_menu_spec = { |
96 | 123 | 'file': 'dynOptionMenuWidget', |
97 | 124 | 'kwds': {}, |
|
100 | 127 | "Select one of the many options in the 'new option set'." |
101 | 128 | } |
102 | 129 |
|
| 130 | +# TODO edit wrapper |
103 | 131 | _editor_window_spec = { |
104 | 132 | 'file': 'EditorWindow', |
105 | 133 | 'kwds': {}, |
106 | | - 'msg': "Test editor functions of interest." |
| 134 | + 'msg': "Test editor functions of interest.\n" |
| 135 | + "Best to close editor first." |
107 | 136 | } |
108 | 137 |
|
109 | 138 | GetCfgSectionNameDialog_spec = { |
|
0 commit comments