Terry Jan Reedy | 6936159 | 2014-05-15 20:50:10 -0400 | [diff] [blame] | 1 | '''Run human tests of Idle's window, dialog, and popup widgets. |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 2 | |
Terry Jan Reedy | 078b8a8 | 2014-06-01 00:30:34 -0400 | [diff] [blame] | 3 | run(*tests) |
Terry Jan Reedy | cd56736 | 2014-10-17 01:31:35 -0400 | [diff] [blame] | 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. |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 9 | |
Terry Jan Reedy | cd56736 | 2014-10-17 01:31:35 -0400 | [diff] [blame] | 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 | |
| 21 | |
Terry Jan Reedy | 078b8a8 | 2014-06-01 00:30:34 -0400 | [diff] [blame] | 22 | End the module with |
Terry Jan Reedy | 6936159 | 2014-05-15 20:50:10 -0400 | [diff] [blame] | 23 | |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 24 | if __name__ == '__main__': |
| 25 | <unittest, if there is one> |
| 26 | from idlelib.idle_test.htest import run |
| 27 | run(X) |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 28 | |
Terry Jan Reedy | cd56736 | 2014-10-17 01:31:35 -0400 | [diff] [blame] | 29 | To have wrapper functions and test invocation code ignored by coveragepy |
| 30 | reports, put '# htest #' on the def statement header line. |
Terry Jan Reedy | 6936159 | 2014-05-15 20:50:10 -0400 | [diff] [blame] | 31 | |
Terry Jan Reedy | cd56736 | 2014-10-17 01:31:35 -0400 | [diff] [blame] | 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__.: |
| 41 | |
| 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. |
Terry Jan Reedy | 6936159 | 2014-05-15 20:50:10 -0400 | [diff] [blame] | 48 | |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 49 | _spec = { |
| 50 | 'file': '', |
| 51 | 'kwds': {'title': ''}, |
| 52 | 'msg': "" |
| 53 | } |
Terry Jan Reedy | 6936159 | 2014-05-15 20:50:10 -0400 | [diff] [blame] | 54 | |
Terry Jan Reedy | cd56736 | 2014-10-17 01:31:35 -0400 | [diff] [blame] | 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. |
Terry Jan Reedy | 078b8a8 | 2014-06-01 00:30:34 -0400 | [diff] [blame] | 59 | |
Terry Jan Reedy | cd56736 | 2014-10-17 01:31:35 -0400 | [diff] [blame] | 60 | |
| 61 | Modules and classes not being tested at the moment: |
Terry Jan Reedy | 078b8a8 | 2014-06-01 00:30:34 -0400 | [diff] [blame] | 62 | PyShell.PyShellEditorWindow |
| 63 | Debugger.Debugger |
| 64 | AutoCompleteWindow.AutoCompleteWindow |
| 65 | OutputWindow.OutputWindow (indirectly being tested with grep test) |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 66 | ''' |
Terry Jan Reedy | cd56736 | 2014-10-17 01:31:35 -0400 | [diff] [blame] | 67 | |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 68 | from importlib import import_module |
Terry Jan Reedy | 2e8234a | 2014-05-29 01:46:26 -0400 | [diff] [blame] | 69 | from idlelib.macosxSupport import _initializeTkVariantTests |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 70 | import tkinter as tk |
| 71 | |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 72 | AboutDialog_spec = { |
| 73 | 'file': 'aboutDialog', |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 74 | 'kwds': {'title': 'aboutDialog test', |
| 75 | '_htest': True, |
| 76 | }, |
| 77 | 'msg': "Test every button. Ensure Python, TK and IDLE versions " |
| 78 | "are correctly displayed.\n [Close] to exit.", |
Terry Jan Reedy | 078b8a8 | 2014-06-01 00:30:34 -0400 | [diff] [blame] | 79 | } |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 80 | |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 81 | _calltip_window_spec = { |
| 82 | 'file': 'CallTipWindow', |
Terry Jan Reedy | ab4fd44 | 2014-05-19 00:12:10 -0400 | [diff] [blame] | 83 | 'kwds': {}, |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 84 | 'msg': "Typing '(' should display a calltip.\n" |
| 85 | "Typing ') should hide the calltip.\n" |
Terry Jan Reedy | ab4fd44 | 2014-05-19 00:12:10 -0400 | [diff] [blame] | 86 | } |
| 87 | |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 88 | _class_browser_spec = { |
| 89 | 'file': 'ClassBrowser', |
| 90 | 'kwds': {}, |
| 91 | 'msg': "Inspect names of module, class(with superclass if " |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 92 | "applicable), methods and functions.\nToggle nested items.\n" |
Terry Jan Reedy | 0a4d13e | 2014-05-27 03:30:54 -0400 | [diff] [blame] | 93 | "Double clicking on items prints a traceback for an exception " |
| 94 | "that is ignored." |
| 95 | } |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 96 | |
| 97 | _color_delegator_spec = { |
| 98 | 'file': 'ColorDelegator', |
| 99 | 'kwds': {}, |
| 100 | 'msg': "The text is sample Python code.\n" |
| 101 | "Ensure components like comments, keywords, builtins,\n" |
| 102 | "string, definitions, and break are correctly colored.\n" |
| 103 | "The default color scheme is in idlelib/config-highlight.def" |
| 104 | } |
| 105 | |
Terry Jan Reedy | 2e8234a | 2014-05-29 01:46:26 -0400 | [diff] [blame] | 106 | ConfigDialog_spec = { |
| 107 | 'file': 'configDialog', |
Terry Jan Reedy | cd56736 | 2014-10-17 01:31:35 -0400 | [diff] [blame] | 108 | 'kwds': {'title': 'ConfigDialogTest', |
Terry Jan Reedy | 2e8234a | 2014-05-29 01:46:26 -0400 | [diff] [blame] | 109 | '_htest': True,}, |
| 110 | 'msg': "IDLE preferences dialog.\n" |
| 111 | "In the 'Fonts/Tabs' tab, changing font face, should update the " |
| 112 | "font face of the text in the area below it.\nIn the " |
| 113 | "'Highlighting' tab, try different color schemes. Clicking " |
| 114 | "items in the sample program should update the choices above it." |
Terry Jan Reedy | 93f3542 | 2015-10-13 22:03:51 -0400 | [diff] [blame] | 115 | "\nIn the 'Keys', 'General' and 'Extensions' tabs, test settings" |
| 116 | "of interest." |
Terry Jan Reedy | 2e8234a | 2014-05-29 01:46:26 -0400 | [diff] [blame] | 117 | "\n[Ok] to close the dialog.[Apply] to apply the settings and " |
| 118 | "and [Cancel] to revert all changes.\nRe-run the test to ensure " |
| 119 | "changes made have persisted." |
| 120 | } |
| 121 | |
Terry Jan Reedy | cd56736 | 2014-10-17 01:31:35 -0400 | [diff] [blame] | 122 | # TODO Improve message |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 123 | _dyn_option_menu_spec = { |
| 124 | 'file': 'dynOptionMenuWidget', |
| 125 | 'kwds': {}, |
| 126 | 'msg': "Select one of the many options in the 'old option set'.\n" |
| 127 | "Click the button to change the option set.\n" |
| 128 | "Select one of the many options in the 'new option set'." |
| 129 | } |
| 130 | |
Terry Jan Reedy | cd56736 | 2014-10-17 01:31:35 -0400 | [diff] [blame] | 131 | # TODO edit wrapper |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 132 | _editor_window_spec = { |
| 133 | 'file': 'EditorWindow', |
| 134 | 'kwds': {}, |
Terry Jan Reedy | cd56736 | 2014-10-17 01:31:35 -0400 | [diff] [blame] | 135 | 'msg': "Test editor functions of interest.\n" |
| 136 | "Best to close editor first." |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 137 | } |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 138 | |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 139 | GetCfgSectionNameDialog_spec = { |
| 140 | 'file': 'configSectionNameDialog', |
| 141 | 'kwds': {'title':'Get Name', |
Terry Jan Reedy | ab4fd44 | 2014-05-19 00:12:10 -0400 | [diff] [blame] | 142 | 'message':'Enter something', |
| 143 | 'used_names': {'abc'}, |
| 144 | '_htest': True}, |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 145 | 'msg': "After the text entered with [Ok] is stripped, <nothing>, " |
Terry Jan Reedy | ab4fd44 | 2014-05-19 00:12:10 -0400 | [diff] [blame] | 146 | "'abc', or more that 30 chars are errors.\n" |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 147 | "Close 'Get Name' with a valid entry (printed to Shell), " |
| 148 | "[Cancel], or [X]", |
| 149 | } |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 150 | |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 151 | GetHelpSourceDialog_spec = { |
| 152 | 'file': 'configHelpSourceEdit', |
| 153 | 'kwds': {'title': 'Get helpsource', |
| 154 | '_htest': True}, |
| 155 | 'msg': "Enter menu item name and help file path\n " |
| 156 | "<nothing> and more than 30 chars are invalid menu item names.\n" |
| 157 | "<nothing>, file does not exist are invalid path items.\n" |
| 158 | "Test for incomplete web address for help file path.\n" |
| 159 | "A valid entry will be printed to shell with [0k].\n" |
| 160 | "[Cancel] will print None to shell", |
Terry Jan Reedy | ab4fd44 | 2014-05-19 00:12:10 -0400 | [diff] [blame] | 161 | } |
| 162 | |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 163 | # Update once issue21519 is resolved. |
| 164 | GetKeysDialog_spec = { |
| 165 | 'file': 'keybindingDialog', |
| 166 | 'kwds': {'title': 'Test keybindings', |
| 167 | 'action': 'find-again', |
| 168 | 'currentKeySequences': [''] , |
| 169 | '_htest': True, |
| 170 | }, |
| 171 | 'msg': "Test for different key modifier sequences.\n" |
| 172 | "<nothing> is invalid.\n" |
| 173 | "No modifier key is invalid.\n" |
| 174 | "Shift key with [a-z],[0-9], function key, move key, tab, space" |
Berker Peksag | f23530f | 2014-10-19 18:04:38 +0300 | [diff] [blame] | 175 | "is invalid.\nNo validity checking if advanced key binding " |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 176 | "entry is used." |
| 177 | } |
| 178 | |
Terry Jan Reedy | 2e8234a | 2014-05-29 01:46:26 -0400 | [diff] [blame] | 179 | _grep_dialog_spec = { |
| 180 | 'file': 'GrepDialog', |
| 181 | 'kwds': {}, |
| 182 | 'msg': "Click the 'Show GrepDialog' button.\n" |
| 183 | "Test the various 'Find-in-files' functions.\n" |
| 184 | "The results should be displayed in a new '*Output*' window.\n" |
| 185 | "'Right-click'->'Goto file/line' anywhere in the search results " |
| 186 | "should open that file \nin a new EditorWindow." |
| 187 | } |
| 188 | |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 189 | _io_binding_spec = { |
| 190 | 'file': 'IOBinding', |
| 191 | 'kwds': {}, |
Terry Jan Reedy | bbdc065 | 2015-10-30 02:47:06 -0400 | [diff] [blame^] | 192 | 'msg': "Test the following bindings.\n" |
| 193 | "<Control-o> to open file from dialog.\n" |
| 194 | "Edit the file.\n" |
| 195 | "<Control-s> to save the file.\n" |
| 196 | "Check that changes were saved by opening the file elsewhere." |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | _multi_call_spec = { |
| 200 | 'file': 'MultiCall', |
| 201 | 'kwds': {}, |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 202 | 'msg': "The following actions should trigger a print to console or IDLE" |
| 203 | " Shell.\nEntering and leaving the text area, key entry, " |
| 204 | "<Control-Key>,\n<Alt-Key-a>, <Control-Key-a>, " |
| 205 | "<Alt-Control-Key-a>, \n<Control-Button-1>, <Alt-Button-1> and " |
| 206 | "focusing out of the window\nare sequences to be tested." |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | _multistatus_bar_spec = { |
| 210 | 'file': 'MultiStatusBar', |
| 211 | 'kwds': {}, |
| 212 | 'msg': "Ensure presence of multi-status bar below text area.\n" |
| 213 | "Click 'Update Status' to change the multi-status text" |
| 214 | } |
| 215 | |
| 216 | _object_browser_spec = { |
| 217 | 'file': 'ObjectBrowser', |
| 218 | 'kwds': {}, |
| 219 | 'msg': "Double click on items upto the lowest level.\n" |
| 220 | "Attributes of the objects and related information " |
| 221 | "will be displayed side-by-side at each level." |
| 222 | } |
| 223 | |
| 224 | _path_browser_spec = { |
| 225 | 'file': 'PathBrowser', |
| 226 | 'kwds': {}, |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 227 | 'msg': "Test for correct display of all paths in sys.path.\n" |
| 228 | "Toggle nested items upto the lowest level.\n" |
| 229 | "Double clicking on an item prints a traceback\n" |
| 230 | "for an exception that is ignored." |
| 231 | } |
| 232 | |
| 233 | _percolator_spec = { |
| 234 | 'file': 'Percolator', |
| 235 | 'kwds': {}, |
| 236 | 'msg': "There are two tracers which can be toggled using a checkbox.\n" |
| 237 | "Toggling a tracer 'on' by checking it should print tracer" |
| 238 | "output to the console or to the IDLE shell.\n" |
| 239 | "If both the tracers are 'on', the output from the tracer which " |
| 240 | "was switched 'on' later, should be printed first\n" |
| 241 | "Test for actions like text entry, and removal." |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 242 | } |
| 243 | |
Terry Jan Reedy | 0a4d13e | 2014-05-27 03:30:54 -0400 | [diff] [blame] | 244 | _replace_dialog_spec = { |
| 245 | 'file': 'ReplaceDialog', |
| 246 | 'kwds': {}, |
| 247 | 'msg': "Click the 'Replace' button.\n" |
| 248 | "Test various replace options in the 'Replace dialog'.\n" |
Terry Jan Reedy | 078b8a8 | 2014-06-01 00:30:34 -0400 | [diff] [blame] | 249 | "Click [Close] or [X] to close the 'Replace Dialog'." |
Terry Jan Reedy | 0a4d13e | 2014-05-27 03:30:54 -0400 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | _search_dialog_spec = { |
| 253 | 'file': 'SearchDialog', |
| 254 | 'kwds': {}, |
| 255 | 'msg': "Click the 'Search' button.\n" |
| 256 | "Test various search options in the 'Search dialog'.\n" |
Terry Jan Reedy | 078b8a8 | 2014-06-01 00:30:34 -0400 | [diff] [blame] | 257 | "Click [Close] or [X] to close the 'Search Dialog'." |
Terry Jan Reedy | 0a4d13e | 2014-05-27 03:30:54 -0400 | [diff] [blame] | 258 | } |
| 259 | |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 260 | _scrolled_list_spec = { |
| 261 | 'file': 'ScrolledList', |
| 262 | 'kwds': {}, |
| 263 | 'msg': "You should see a scrollable list of items\n" |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 264 | "Selecting (clicking) or double clicking an item " |
| 265 | "prints the name to the console or Idle shell.\n" |
| 266 | "Right clicking an item will display a popup." |
| 267 | } |
| 268 | |
Terry Jan Reedy | 5d46ab1 | 2015-09-20 19:57:13 -0400 | [diff] [blame] | 269 | show_idlehelp_spec = { |
| 270 | 'file': 'help', |
| 271 | 'kwds': {}, |
| 272 | 'msg': "If the help text displays, this works.\n" |
| 273 | "Text is selectable. Window is scrollable." |
| 274 | } |
| 275 | |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 276 | _stack_viewer_spec = { |
| 277 | 'file': 'StackViewer', |
| 278 | 'kwds': {}, |
| 279 | 'msg': "A stacktrace for a NameError exception.\n" |
| 280 | "Expand 'idlelib ...' and '<locals>'.\n" |
| 281 | "Check that exc_value, exc_tb, and exc_type are correct.\n" |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | _tabbed_pages_spec = { |
| 285 | 'file': 'tabbedpages', |
| 286 | 'kwds': {}, |
| 287 | 'msg': "Toggle between the two tabs 'foo' and 'bar'\n" |
| 288 | "Add a tab by entering a suitable name for it.\n" |
| 289 | "Remove an existing tab by entering its name.\n" |
| 290 | "Remove all existing tabs.\n" |
| 291 | "<nothing> is an invalid add page and remove page name.\n" |
| 292 | } |
| 293 | |
| 294 | TextViewer_spec = { |
| 295 | 'file': 'textView', |
| 296 | 'kwds': {'title': 'Test textView', |
| 297 | 'text':'The quick brown fox jumps over the lazy dog.\n'*35, |
| 298 | '_htest': True}, |
| 299 | 'msg': "Test for read-only property of text.\n" |
| 300 | "Text is selectable. Window is scrollable.", |
| 301 | } |
| 302 | |
| 303 | _tooltip_spec = { |
| 304 | 'file': 'ToolTip', |
| 305 | 'kwds': {}, |
| 306 | 'msg': "Place mouse cursor over both the buttons\n" |
| 307 | "A tooltip should appear with some text." |
| 308 | } |
| 309 | |
| 310 | _tree_widget_spec = { |
| 311 | 'file': 'TreeWidget', |
| 312 | 'kwds': {}, |
Terry Jan Reedy | 0a4d13e | 2014-05-27 03:30:54 -0400 | [diff] [blame] | 313 | 'msg': "The canvas is scrollable.\n" |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 314 | "Click on folders upto to the lowest level." |
| 315 | } |
| 316 | |
Terry Jan Reedy | 2e8234a | 2014-05-29 01:46:26 -0400 | [diff] [blame] | 317 | _undo_delegator_spec = { |
| 318 | 'file': 'UndoDelegator', |
| 319 | 'kwds': {}, |
| 320 | 'msg': "Click [Undo] to undo any action.\n" |
| 321 | "Click [Redo] to redo any action.\n" |
| 322 | "Click [Dump] to dump the current state " |
| 323 | "by printing to the console or the IDLE shell.\n" |
| 324 | } |
| 325 | |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 326 | _widget_redirector_spec = { |
| 327 | 'file': 'WidgetRedirector', |
| 328 | 'kwds': {}, |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 329 | 'msg': "Every text insert should be printed to the console." |
| 330 | "or the IDLE shell." |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 331 | } |
| 332 | |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 333 | def run(*tests): |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 334 | root = tk.Tk() |
Terry Jan Reedy | 2e8234a | 2014-05-29 01:46:26 -0400 | [diff] [blame] | 335 | root.title('IDLE htest') |
| 336 | root.resizable(0, 0) |
| 337 | _initializeTkVariantTests(root) |
| 338 | |
| 339 | # a scrollable Label like constant width text widget. |
| 340 | frameLabel = tk.Frame(root, padx=10) |
| 341 | frameLabel.pack() |
| 342 | text = tk.Text(frameLabel, wrap='word') |
| 343 | text.configure(bg=root.cget('bg'), relief='flat', height=4, width=70) |
| 344 | scrollbar = tk.Scrollbar(frameLabel, command=text.yview) |
| 345 | text.config(yscrollcommand=scrollbar.set) |
| 346 | scrollbar.pack(side='right', fill='y', expand=False) |
| 347 | text.pack(side='left', fill='both', expand=True) |
| 348 | |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 349 | test_list = [] # List of tuples of the form (spec, callable widget) |
| 350 | if tests: |
| 351 | for test in tests: |
| 352 | test_spec = globals()[test.__name__ + '_spec'] |
| 353 | test_spec['name'] = test.__name__ |
| 354 | test_list.append((test_spec, test)) |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 355 | else: |
| 356 | for k, d in globals().items(): |
| 357 | if k.endswith('_spec'): |
| 358 | test_name = k[:-5] |
| 359 | test_spec = d |
| 360 | test_spec['name'] = test_name |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 361 | mod = import_module('idlelib.' + test_spec['file']) |
| 362 | test = getattr(mod, test_name) |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 363 | test_list.append((test_spec, test)) |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 364 | |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 365 | test_name = tk.StringVar('') |
| 366 | callable_object = None |
| 367 | test_kwds = None |
| 368 | |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 369 | def next(): |
Terry Jan Reedy | 2e8234a | 2014-05-29 01:46:26 -0400 | [diff] [blame] | 370 | |
| 371 | nonlocal test_name, callable_object, test_kwds |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 372 | if len(test_list) == 1: |
| 373 | next_button.pack_forget() |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 374 | test_spec, callable_object = test_list.pop() |
| 375 | test_kwds = test_spec['kwds'] |
| 376 | test_kwds['parent'] = root |
Terry Jan Reedy | a2fc99e | 2014-05-25 18:44:05 -0400 | [diff] [blame] | 377 | test_name.set('Test ' + test_spec['name']) |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 378 | |
Terry Jan Reedy | 2e8234a | 2014-05-29 01:46:26 -0400 | [diff] [blame] | 379 | text.configure(state='normal') # enable text editing |
| 380 | text.delete('1.0','end') |
| 381 | text.insert("1.0",test_spec['msg']) |
| 382 | text.configure(state='disabled') # preserve read-only property |
Terry Jan Reedy | 6936159 | 2014-05-15 20:50:10 -0400 | [diff] [blame] | 383 | |
| 384 | def run_test(): |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 385 | widget = callable_object(**test_kwds) |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 386 | try: |
| 387 | print(widget.result) |
| 388 | except AttributeError: |
| 389 | pass |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 390 | |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 391 | button = tk.Button(root, textvariable=test_name, command=run_test) |
| 392 | button.pack() |
| 393 | next_button = tk.Button(root, text="Next", command=next) |
| 394 | next_button.pack() |
| 395 | |
| 396 | next() |
| 397 | |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 398 | root.mainloop() |
| 399 | |
Terry Jan Reedy | 06313b7 | 2014-05-11 23:32:32 -0400 | [diff] [blame] | 400 | if __name__ == '__main__': |
Terry Jan Reedy | 1b392ff | 2014-05-24 18:48:18 -0400 | [diff] [blame] | 401 | run() |