| 1 | n/a | '''Run human tests of Idle's window, dialog, and popup widgets. |
|---|
| 2 | n/a | |
|---|
| 3 | n/a | run(*tests) |
|---|
| 4 | n/a | Create a master Tk window. Within that, run each callable in tests |
|---|
| 5 | n/a | after finding the matching test spec in this file. If tests is empty, |
|---|
| 6 | n/a | run an htest for each spec dict in this file after finding the matching |
|---|
| 7 | n/a | callable in the module named in the spec. Close the window to skip or |
|---|
| 8 | n/a | end the test. |
|---|
| 9 | n/a | |
|---|
| 10 | n/a | In a tested module, let X be a global name bound to a callable (class |
|---|
| 11 | n/a | or function) whose .__name__ attrubute is also X (the usual situation). |
|---|
| 12 | n/a | The first parameter of X must be 'parent'. When called, the parent |
|---|
| 13 | n/a | argument will be the root window. X must create a child Toplevel |
|---|
| 14 | n/a | window (or subclass thereof). The Toplevel may be a test widget or |
|---|
| 15 | n/a | dialog, in which case the callable is the corresonding class. Or the |
|---|
| 16 | n/a | Toplevel may contain the widget to be tested or set up a context in |
|---|
| 17 | n/a | which a test widget is invoked. In this latter case, the callable is a |
|---|
| 18 | n/a | wrapper function that sets up the Toplevel and other objects. Wrapper |
|---|
| 19 | n/a | function names, such as _editor_window', should start with '_'. |
|---|
| 20 | n/a | |
|---|
| 21 | n/a | |
|---|
| 22 | n/a | End the module with |
|---|
| 23 | n/a | |
|---|
| 24 | n/a | if __name__ == '__main__': |
|---|
| 25 | n/a | <unittest, if there is one> |
|---|
| 26 | n/a | from idlelib.idle_test.htest import run |
|---|
| 27 | n/a | run(X) |
|---|
| 28 | n/a | |
|---|
| 29 | n/a | To have wrapper functions and test invocation code ignored by coveragepy |
|---|
| 30 | n/a | reports, put '# htest #' on the def statement header line. |
|---|
| 31 | n/a | |
|---|
| 32 | n/a | def _wrapper(parent): # htest # |
|---|
| 33 | n/a | |
|---|
| 34 | n/a | Also make sure that the 'if __name__' line matches the above. Then have |
|---|
| 35 | n/a | make sure that .coveragerc includes the following. |
|---|
| 36 | n/a | |
|---|
| 37 | n/a | [report] |
|---|
| 38 | n/a | exclude_lines = |
|---|
| 39 | n/a | .*# htest # |
|---|
| 40 | n/a | if __name__ == .__main__.: |
|---|
| 41 | n/a | |
|---|
| 42 | n/a | (The "." instead of "'" is intentional and necessary.) |
|---|
| 43 | n/a | |
|---|
| 44 | n/a | |
|---|
| 45 | n/a | To run any X, this file must contain a matching instance of the |
|---|
| 46 | n/a | following template, with X.__name__ prepended to '_spec'. |
|---|
| 47 | n/a | When all tests are run, the prefix is use to get X. |
|---|
| 48 | n/a | |
|---|
| 49 | n/a | _spec = { |
|---|
| 50 | n/a | 'file': '', |
|---|
| 51 | n/a | 'kwds': {'title': ''}, |
|---|
| 52 | n/a | 'msg': "" |
|---|
| 53 | n/a | } |
|---|
| 54 | n/a | |
|---|
| 55 | n/a | file (no .py): run() imports file.py. |
|---|
| 56 | n/a | kwds: augmented with {'parent':root} and passed to X as **kwds. |
|---|
| 57 | n/a | title: an example kwd; some widgets need this, delete if not. |
|---|
| 58 | n/a | msg: master window hints about testing the widget. |
|---|
| 59 | n/a | |
|---|
| 60 | n/a | |
|---|
| 61 | n/a | Modules and classes not being tested at the moment: |
|---|
| 62 | n/a | pyshell.PyShellEditorWindow |
|---|
| 63 | n/a | debugger.Debugger |
|---|
| 64 | n/a | autocomplete_w.AutoCompleteWindow |
|---|
| 65 | n/a | outwin.OutputWindow (indirectly being tested with grep test) |
|---|
| 66 | n/a | ''' |
|---|
| 67 | n/a | |
|---|
| 68 | n/a | from importlib import import_module |
|---|
| 69 | n/a | import tkinter as tk |
|---|
| 70 | n/a | from tkinter.ttk import Scrollbar |
|---|
| 71 | n/a | tk.NoDefaultRoot() |
|---|
| 72 | n/a | |
|---|
| 73 | n/a | AboutDialog_spec = { |
|---|
| 74 | n/a | 'file': 'help_about', |
|---|
| 75 | n/a | 'kwds': {'title': 'help_about test', |
|---|
| 76 | n/a | '_htest': True, |
|---|
| 77 | n/a | }, |
|---|
| 78 | n/a | 'msg': "Test every button. Ensure Python, TK and IDLE versions " |
|---|
| 79 | n/a | "are correctly displayed.\n [Close] to exit.", |
|---|
| 80 | n/a | } |
|---|
| 81 | n/a | |
|---|
| 82 | n/a | _calltip_window_spec = { |
|---|
| 83 | n/a | 'file': 'calltip_w', |
|---|
| 84 | n/a | 'kwds': {}, |
|---|
| 85 | n/a | 'msg': "Typing '(' should display a calltip.\n" |
|---|
| 86 | n/a | "Typing ') should hide the calltip.\n" |
|---|
| 87 | n/a | } |
|---|
| 88 | n/a | |
|---|
| 89 | n/a | _class_browser_spec = { |
|---|
| 90 | n/a | 'file': 'browser', |
|---|
| 91 | n/a | 'kwds': {}, |
|---|
| 92 | n/a | 'msg': "Inspect names of module, class(with superclass if " |
|---|
| 93 | n/a | "applicable), methods and functions.\nToggle nested items.\n" |
|---|
| 94 | n/a | "Double clicking on items prints a traceback for an exception " |
|---|
| 95 | n/a | "that is ignored." |
|---|
| 96 | n/a | } |
|---|
| 97 | n/a | |
|---|
| 98 | n/a | _color_delegator_spec = { |
|---|
| 99 | n/a | 'file': 'colorizer', |
|---|
| 100 | n/a | 'kwds': {}, |
|---|
| 101 | n/a | 'msg': "The text is sample Python code.\n" |
|---|
| 102 | n/a | "Ensure components like comments, keywords, builtins,\n" |
|---|
| 103 | n/a | "string, definitions, and break are correctly colored.\n" |
|---|
| 104 | n/a | "The default color scheme is in idlelib/config-highlight.def" |
|---|
| 105 | n/a | } |
|---|
| 106 | n/a | |
|---|
| 107 | n/a | ConfigDialog_spec = { |
|---|
| 108 | n/a | 'file': 'configdialog', |
|---|
| 109 | n/a | 'kwds': {'title': 'ConfigDialogTest', |
|---|
| 110 | n/a | '_htest': True,}, |
|---|
| 111 | n/a | 'msg': "IDLE preferences dialog.\n" |
|---|
| 112 | n/a | "In the 'Fonts/Tabs' tab, changing font face, should update the " |
|---|
| 113 | n/a | "font face of the text in the area below it.\nIn the " |
|---|
| 114 | n/a | "'Highlighting' tab, try different color schemes. Clicking " |
|---|
| 115 | n/a | "items in the sample program should update the choices above it." |
|---|
| 116 | n/a | "\nIn the 'Keys', 'General' and 'Extensions' tabs, test settings" |
|---|
| 117 | n/a | "of interest." |
|---|
| 118 | n/a | "\n[Ok] to close the dialog.[Apply] to apply the settings and " |
|---|
| 119 | n/a | "and [Cancel] to revert all changes.\nRe-run the test to ensure " |
|---|
| 120 | n/a | "changes made have persisted." |
|---|
| 121 | n/a | } |
|---|
| 122 | n/a | |
|---|
| 123 | n/a | # TODO Improve message |
|---|
| 124 | n/a | _dyn_option_menu_spec = { |
|---|
| 125 | n/a | 'file': 'dynoption', |
|---|
| 126 | n/a | 'kwds': {}, |
|---|
| 127 | n/a | 'msg': "Select one of the many options in the 'old option set'.\n" |
|---|
| 128 | n/a | "Click the button to change the option set.\n" |
|---|
| 129 | n/a | "Select one of the many options in the 'new option set'." |
|---|
| 130 | n/a | } |
|---|
| 131 | n/a | |
|---|
| 132 | n/a | # TODO edit wrapper |
|---|
| 133 | n/a | _editor_window_spec = { |
|---|
| 134 | n/a | 'file': 'editor', |
|---|
| 135 | n/a | 'kwds': {}, |
|---|
| 136 | n/a | 'msg': "Test editor functions of interest.\n" |
|---|
| 137 | n/a | "Best to close editor first." |
|---|
| 138 | n/a | } |
|---|
| 139 | n/a | |
|---|
| 140 | n/a | # Update once issue21519 is resolved. |
|---|
| 141 | n/a | GetKeysDialog_spec = { |
|---|
| 142 | n/a | 'file': 'config_key', |
|---|
| 143 | n/a | 'kwds': {'title': 'Test keybindings', |
|---|
| 144 | n/a | 'action': 'find-again', |
|---|
| 145 | n/a | 'currentKeySequences': [''] , |
|---|
| 146 | n/a | '_htest': True, |
|---|
| 147 | n/a | }, |
|---|
| 148 | n/a | 'msg': "Test for different key modifier sequences.\n" |
|---|
| 149 | n/a | "<nothing> is invalid.\n" |
|---|
| 150 | n/a | "No modifier key is invalid.\n" |
|---|
| 151 | n/a | "Shift key with [a-z],[0-9], function key, move key, tab, space" |
|---|
| 152 | n/a | "is invalid.\nNo validity checking if advanced key binding " |
|---|
| 153 | n/a | "entry is used." |
|---|
| 154 | n/a | } |
|---|
| 155 | n/a | |
|---|
| 156 | n/a | _grep_dialog_spec = { |
|---|
| 157 | n/a | 'file': 'grep', |
|---|
| 158 | n/a | 'kwds': {}, |
|---|
| 159 | n/a | 'msg': "Click the 'Show GrepDialog' button.\n" |
|---|
| 160 | n/a | "Test the various 'Find-in-files' functions.\n" |
|---|
| 161 | n/a | "The results should be displayed in a new '*Output*' window.\n" |
|---|
| 162 | n/a | "'Right-click'->'Goto file/line' anywhere in the search results " |
|---|
| 163 | n/a | "should open that file \nin a new EditorWindow." |
|---|
| 164 | n/a | } |
|---|
| 165 | n/a | |
|---|
| 166 | n/a | HelpSource_spec = { |
|---|
| 167 | n/a | 'file': 'query', |
|---|
| 168 | n/a | 'kwds': {'title': 'Help name and source', |
|---|
| 169 | n/a | 'menuitem': 'test', |
|---|
| 170 | n/a | 'filepath': __file__, |
|---|
| 171 | n/a | 'used_names': {'abc'}, |
|---|
| 172 | n/a | '_htest': True}, |
|---|
| 173 | n/a | 'msg': "Enter menu item name and help file path\n" |
|---|
| 174 | n/a | "'', > than 30 chars, and 'abc' are invalid menu item names.\n" |
|---|
| 175 | n/a | "'' and file does not exist are invalid path items.\n" |
|---|
| 176 | n/a | "Any url ('www...', 'http...') is accepted.\n" |
|---|
| 177 | n/a | "Test Browse with and without path, as cannot unittest.\n" |
|---|
| 178 | n/a | "[Ok] or <Return> prints valid entry to shell\n" |
|---|
| 179 | n/a | "[Cancel] or <Escape> prints None to shell" |
|---|
| 180 | n/a | } |
|---|
| 181 | n/a | |
|---|
| 182 | n/a | _io_binding_spec = { |
|---|
| 183 | n/a | 'file': 'iomenu', |
|---|
| 184 | n/a | 'kwds': {}, |
|---|
| 185 | n/a | 'msg': "Test the following bindings.\n" |
|---|
| 186 | n/a | "<Control-o> to open file from dialog.\n" |
|---|
| 187 | n/a | "Edit the file.\n" |
|---|
| 188 | n/a | "<Control-p> to print the file.\n" |
|---|
| 189 | n/a | "<Control-s> to save the file.\n" |
|---|
| 190 | n/a | "<Alt-s> to save-as another file.\n" |
|---|
| 191 | n/a | "<Control-c> to save-copy-as another file.\n" |
|---|
| 192 | n/a | "Check that changes were saved by opening the file elsewhere." |
|---|
| 193 | n/a | } |
|---|
| 194 | n/a | |
|---|
| 195 | n/a | _multi_call_spec = { |
|---|
| 196 | n/a | 'file': 'multicall', |
|---|
| 197 | n/a | 'kwds': {}, |
|---|
| 198 | n/a | 'msg': "The following actions should trigger a print to console or IDLE" |
|---|
| 199 | n/a | " Shell.\nEntering and leaving the text area, key entry, " |
|---|
| 200 | n/a | "<Control-Key>,\n<Alt-Key-a>, <Control-Key-a>, " |
|---|
| 201 | n/a | "<Alt-Control-Key-a>, \n<Control-Button-1>, <Alt-Button-1> and " |
|---|
| 202 | n/a | "focusing out of the window\nare sequences to be tested." |
|---|
| 203 | n/a | } |
|---|
| 204 | n/a | |
|---|
| 205 | n/a | _multistatus_bar_spec = { |
|---|
| 206 | n/a | 'file': 'statusbar', |
|---|
| 207 | n/a | 'kwds': {}, |
|---|
| 208 | n/a | 'msg': "Ensure presence of multi-status bar below text area.\n" |
|---|
| 209 | n/a | "Click 'Update Status' to change the multi-status text" |
|---|
| 210 | n/a | } |
|---|
| 211 | n/a | |
|---|
| 212 | n/a | _object_browser_spec = { |
|---|
| 213 | n/a | 'file': 'debugobj', |
|---|
| 214 | n/a | 'kwds': {}, |
|---|
| 215 | n/a | 'msg': "Double click on items upto the lowest level.\n" |
|---|
| 216 | n/a | "Attributes of the objects and related information " |
|---|
| 217 | n/a | "will be displayed side-by-side at each level." |
|---|
| 218 | n/a | } |
|---|
| 219 | n/a | |
|---|
| 220 | n/a | _path_browser_spec = { |
|---|
| 221 | n/a | 'file': 'pathbrowser', |
|---|
| 222 | n/a | 'kwds': {}, |
|---|
| 223 | n/a | 'msg': "Test for correct display of all paths in sys.path.\n" |
|---|
| 224 | n/a | "Toggle nested items upto the lowest level.\n" |
|---|
| 225 | n/a | "Double clicking on an item prints a traceback\n" |
|---|
| 226 | n/a | "for an exception that is ignored." |
|---|
| 227 | n/a | } |
|---|
| 228 | n/a | |
|---|
| 229 | n/a | _percolator_spec = { |
|---|
| 230 | n/a | 'file': 'percolator', |
|---|
| 231 | n/a | 'kwds': {}, |
|---|
| 232 | n/a | 'msg': "There are two tracers which can be toggled using a checkbox.\n" |
|---|
| 233 | n/a | "Toggling a tracer 'on' by checking it should print tracer" |
|---|
| 234 | n/a | "output to the console or to the IDLE shell.\n" |
|---|
| 235 | n/a | "If both the tracers are 'on', the output from the tracer which " |
|---|
| 236 | n/a | "was switched 'on' later, should be printed first\n" |
|---|
| 237 | n/a | "Test for actions like text entry, and removal." |
|---|
| 238 | n/a | } |
|---|
| 239 | n/a | |
|---|
| 240 | n/a | Query_spec = { |
|---|
| 241 | n/a | 'file': 'query', |
|---|
| 242 | n/a | 'kwds': {'title': 'Query', |
|---|
| 243 | n/a | 'message': 'Enter something', |
|---|
| 244 | n/a | 'text0': 'Go', |
|---|
| 245 | n/a | '_htest': True}, |
|---|
| 246 | n/a | 'msg': "Enter with <Return> or [Ok]. Print valid entry to Shell\n" |
|---|
| 247 | n/a | "Blank line, after stripping, is ignored\n" |
|---|
| 248 | n/a | "Close dialog with valid entry, <Escape>, [Cancel], [X]" |
|---|
| 249 | n/a | } |
|---|
| 250 | n/a | |
|---|
| 251 | n/a | |
|---|
| 252 | n/a | _replace_dialog_spec = { |
|---|
| 253 | n/a | 'file': 'replace', |
|---|
| 254 | n/a | 'kwds': {}, |
|---|
| 255 | n/a | 'msg': "Click the 'Replace' button.\n" |
|---|
| 256 | n/a | "Test various replace options in the 'Replace dialog'.\n" |
|---|
| 257 | n/a | "Click [Close] or [X] to close the 'Replace Dialog'." |
|---|
| 258 | n/a | } |
|---|
| 259 | n/a | |
|---|
| 260 | n/a | _search_dialog_spec = { |
|---|
| 261 | n/a | 'file': 'search', |
|---|
| 262 | n/a | 'kwds': {}, |
|---|
| 263 | n/a | 'msg': "Click the 'Search' button.\n" |
|---|
| 264 | n/a | "Test various search options in the 'Search dialog'.\n" |
|---|
| 265 | n/a | "Click [Close] or [X] to close the 'Search Dialog'." |
|---|
| 266 | n/a | } |
|---|
| 267 | n/a | |
|---|
| 268 | n/a | _searchbase_spec = { |
|---|
| 269 | n/a | 'file': 'searchbase', |
|---|
| 270 | n/a | 'kwds': {}, |
|---|
| 271 | n/a | 'msg': "Check the appearance of the base search dialog\n" |
|---|
| 272 | n/a | "Its only action is to close." |
|---|
| 273 | n/a | } |
|---|
| 274 | n/a | |
|---|
| 275 | n/a | _scrolled_list_spec = { |
|---|
| 276 | n/a | 'file': 'scrolledlist', |
|---|
| 277 | n/a | 'kwds': {}, |
|---|
| 278 | n/a | 'msg': "You should see a scrollable list of items\n" |
|---|
| 279 | n/a | "Selecting (clicking) or double clicking an item " |
|---|
| 280 | n/a | "prints the name to the console or Idle shell.\n" |
|---|
| 281 | n/a | "Right clicking an item will display a popup." |
|---|
| 282 | n/a | } |
|---|
| 283 | n/a | |
|---|
| 284 | n/a | show_idlehelp_spec = { |
|---|
| 285 | n/a | 'file': 'help', |
|---|
| 286 | n/a | 'kwds': {}, |
|---|
| 287 | n/a | 'msg': "If the help text displays, this works.\n" |
|---|
| 288 | n/a | "Text is selectable. Window is scrollable." |
|---|
| 289 | n/a | } |
|---|
| 290 | n/a | |
|---|
| 291 | n/a | _stack_viewer_spec = { |
|---|
| 292 | n/a | 'file': 'stackviewer', |
|---|
| 293 | n/a | 'kwds': {}, |
|---|
| 294 | n/a | 'msg': "A stacktrace for a NameError exception.\n" |
|---|
| 295 | n/a | "Expand 'idlelib ...' and '<locals>'.\n" |
|---|
| 296 | n/a | "Check that exc_value, exc_tb, and exc_type are correct.\n" |
|---|
| 297 | n/a | } |
|---|
| 298 | n/a | |
|---|
| 299 | n/a | _tabbed_pages_spec = { |
|---|
| 300 | n/a | 'file': 'tabbedpages', |
|---|
| 301 | n/a | 'kwds': {}, |
|---|
| 302 | n/a | 'msg': "Toggle between the two tabs 'foo' and 'bar'\n" |
|---|
| 303 | n/a | "Add a tab by entering a suitable name for it.\n" |
|---|
| 304 | n/a | "Remove an existing tab by entering its name.\n" |
|---|
| 305 | n/a | "Remove all existing tabs.\n" |
|---|
| 306 | n/a | "<nothing> is an invalid add page and remove page name.\n" |
|---|
| 307 | n/a | } |
|---|
| 308 | n/a | |
|---|
| 309 | n/a | TextViewer_spec = { |
|---|
| 310 | n/a | 'file': 'textview', |
|---|
| 311 | n/a | 'kwds': {'title': 'Test textview', |
|---|
| 312 | n/a | 'text':'The quick brown fox jumps over the lazy dog.\n'*35, |
|---|
| 313 | n/a | '_htest': True}, |
|---|
| 314 | n/a | 'msg': "Test for read-only property of text.\n" |
|---|
| 315 | n/a | "Text is selectable. Window is scrollable.", |
|---|
| 316 | n/a | } |
|---|
| 317 | n/a | |
|---|
| 318 | n/a | _tooltip_spec = { |
|---|
| 319 | n/a | 'file': 'tooltip', |
|---|
| 320 | n/a | 'kwds': {}, |
|---|
| 321 | n/a | 'msg': "Place mouse cursor over both the buttons\n" |
|---|
| 322 | n/a | "A tooltip should appear with some text." |
|---|
| 323 | n/a | } |
|---|
| 324 | n/a | |
|---|
| 325 | n/a | _tree_widget_spec = { |
|---|
| 326 | n/a | 'file': 'tree', |
|---|
| 327 | n/a | 'kwds': {}, |
|---|
| 328 | n/a | 'msg': "The canvas is scrollable.\n" |
|---|
| 329 | n/a | "Click on folders upto to the lowest level." |
|---|
| 330 | n/a | } |
|---|
| 331 | n/a | |
|---|
| 332 | n/a | _undo_delegator_spec = { |
|---|
| 333 | n/a | 'file': 'undo', |
|---|
| 334 | n/a | 'kwds': {}, |
|---|
| 335 | n/a | 'msg': "Click [Undo] to undo any action.\n" |
|---|
| 336 | n/a | "Click [Redo] to redo any action.\n" |
|---|
| 337 | n/a | "Click [Dump] to dump the current state " |
|---|
| 338 | n/a | "by printing to the console or the IDLE shell.\n" |
|---|
| 339 | n/a | } |
|---|
| 340 | n/a | |
|---|
| 341 | n/a | _widget_redirector_spec = { |
|---|
| 342 | n/a | 'file': 'redirector', |
|---|
| 343 | n/a | 'kwds': {}, |
|---|
| 344 | n/a | 'msg': "Every text insert should be printed to the console." |
|---|
| 345 | n/a | "or the IDLE shell." |
|---|
| 346 | n/a | } |
|---|
| 347 | n/a | |
|---|
| 348 | n/a | def run(*tests): |
|---|
| 349 | n/a | root = tk.Tk() |
|---|
| 350 | n/a | root.title('IDLE htest') |
|---|
| 351 | n/a | root.resizable(0, 0) |
|---|
| 352 | n/a | |
|---|
| 353 | n/a | # a scrollable Label like constant width text widget. |
|---|
| 354 | n/a | frameLabel = tk.Frame(root, padx=10) |
|---|
| 355 | n/a | frameLabel.pack() |
|---|
| 356 | n/a | text = tk.Text(frameLabel, wrap='word') |
|---|
| 357 | n/a | text.configure(bg=root.cget('bg'), relief='flat', height=4, width=70) |
|---|
| 358 | n/a | scrollbar = Scrollbar(frameLabel, command=text.yview) |
|---|
| 359 | n/a | text.config(yscrollcommand=scrollbar.set) |
|---|
| 360 | n/a | scrollbar.pack(side='right', fill='y', expand=False) |
|---|
| 361 | n/a | text.pack(side='left', fill='both', expand=True) |
|---|
| 362 | n/a | |
|---|
| 363 | n/a | test_list = [] # List of tuples of the form (spec, callable widget) |
|---|
| 364 | n/a | if tests: |
|---|
| 365 | n/a | for test in tests: |
|---|
| 366 | n/a | test_spec = globals()[test.__name__ + '_spec'] |
|---|
| 367 | n/a | test_spec['name'] = test.__name__ |
|---|
| 368 | n/a | test_list.append((test_spec, test)) |
|---|
| 369 | n/a | else: |
|---|
| 370 | n/a | for k, d in globals().items(): |
|---|
| 371 | n/a | if k.endswith('_spec'): |
|---|
| 372 | n/a | test_name = k[:-5] |
|---|
| 373 | n/a | test_spec = d |
|---|
| 374 | n/a | test_spec['name'] = test_name |
|---|
| 375 | n/a | mod = import_module('idlelib.' + test_spec['file']) |
|---|
| 376 | n/a | test = getattr(mod, test_name) |
|---|
| 377 | n/a | test_list.append((test_spec, test)) |
|---|
| 378 | n/a | |
|---|
| 379 | n/a | test_name = tk.StringVar(root) |
|---|
| 380 | n/a | callable_object = None |
|---|
| 381 | n/a | test_kwds = None |
|---|
| 382 | n/a | |
|---|
| 383 | n/a | def next_test(): |
|---|
| 384 | n/a | |
|---|
| 385 | n/a | nonlocal test_name, callable_object, test_kwds |
|---|
| 386 | n/a | if len(test_list) == 1: |
|---|
| 387 | n/a | next_button.pack_forget() |
|---|
| 388 | n/a | test_spec, callable_object = test_list.pop() |
|---|
| 389 | n/a | test_kwds = test_spec['kwds'] |
|---|
| 390 | n/a | test_kwds['parent'] = root |
|---|
| 391 | n/a | test_name.set('Test ' + test_spec['name']) |
|---|
| 392 | n/a | |
|---|
| 393 | n/a | text.configure(state='normal') # enable text editing |
|---|
| 394 | n/a | text.delete('1.0','end') |
|---|
| 395 | n/a | text.insert("1.0",test_spec['msg']) |
|---|
| 396 | n/a | text.configure(state='disabled') # preserve read-only property |
|---|
| 397 | n/a | |
|---|
| 398 | n/a | def run_test(_=None): |
|---|
| 399 | n/a | widget = callable_object(**test_kwds) |
|---|
| 400 | n/a | try: |
|---|
| 401 | n/a | print(widget.result) |
|---|
| 402 | n/a | except AttributeError: |
|---|
| 403 | n/a | pass |
|---|
| 404 | n/a | |
|---|
| 405 | n/a | def close(_=None): |
|---|
| 406 | n/a | root.destroy() |
|---|
| 407 | n/a | |
|---|
| 408 | n/a | button = tk.Button(root, textvariable=test_name, |
|---|
| 409 | n/a | default='active', command=run_test) |
|---|
| 410 | n/a | next_button = tk.Button(root, text="Next", command=next_test) |
|---|
| 411 | n/a | button.pack() |
|---|
| 412 | n/a | next_button.pack() |
|---|
| 413 | n/a | next_button.focus_set() |
|---|
| 414 | n/a | root.bind('<Key-Return>', run_test) |
|---|
| 415 | n/a | root.bind('<Key-Escape>', close) |
|---|
| 416 | n/a | |
|---|
| 417 | n/a | next_test() |
|---|
| 418 | n/a | root.mainloop() |
|---|
| 419 | n/a | |
|---|
| 420 | n/a | if __name__ == '__main__': |
|---|
| 421 | n/a | run() |
|---|