Title: Idle: improve idle_test.htest
Type: enhancement Stage: resolved
Components: Versions: Python 3.5, Python 3.4, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder: Idle: polish htests
View: 21624
Assigned To: terry.reedy Nosy List: jesstess, ned.deily, python-dev, sahutd, terry.reedy
Priority: normal Keywords: patch

Created on 2014-05-12 04:08 by terry.reedy, last changed 2014-06-01 23:36 by ned.deily. This issue is now closed.

File name Uploaded Description Edit
21477-htest.txt terry.reedy, 2014-05-12 04:16 renamed and copied from 18104
week1.diff sahutd, 2014-05-24 04:34 review
run-runall.diff sahutd, 2014-05-24 04:36 review
run-runall-34.diff terry.reedy, 2014-05-24 21:09 review
run-runall-27.diff terry.reedy, 2014-05-24 22:41 review
htest-25052014.diff sahutd, 2014-05-25 15:47 review
htest-25052014-34.diff terry.reedy, 2014-05-25 22:47 review
htest-25052014-27.diff sahutd, 2014-05-26 04:24 Corresponding patch for 2.7 for test-25052014-34.diff review
htest-26052014-34.diff sahutd, 2014-05-26 14:53 review
htest-26052014-27.diff sahutd, 2014-05-26 14:54
htest-28052014-34.diff sahutd, 2014-05-28 16:27 review
htest-28052014-27.diff sahutd, 2014-05-28 16:28 review
htest-docstring-34.diff sahutd, 2014-05-30 14:59 Docstring change to reflect change in code. review
htest-docstring-27.diff sahutd, 2014-05-30 15:00 Docstring change to reflect change in code. review
Messages (24)
msg218312 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-05-12 04:08
#18104 created idle_test/ Besides adding more tests in other issues, some possible improvements to htest itself follow. Many depend on not reusing run, as it now it, in the runall loop. What is left in common to both might be factored out.

* For runall, reuse the same master box so the user does not have to click away each master box to see another (which also appears in a different position). Instead, rewrite the message and if still used, the button.

* Make sure tested widgets do not cover the master box. For configSectionNameDialog, an htest parameter was added to the class to change the usual positioning (which was intentionally centered over the parent).

* For most tests, eliminate the button and simply display the widget. The button is needed for testing message boxes when one wants to test different entries (the section name dialog). 'button=True' could be added to the spec where needed.

* If there is no button to restart a test, then closing the widget should, if possible, close the master. The editor window does this, but that would have to be changed if runall ran in one root.

* The pre-existing editor window test hides (withdraws) the master (root) window. This is not necessary and should be changed.
msg218830 - (view) Author: Roundup Robot (python-dev) Date: 2014-05-20 02:56
New changeset 33a39dfc239e by Terry Jan Reedy in branch '2.7':
Issue #21477: idle htests - lower case function names, other cleanups.

New changeset 7c70198ec48e by Terry Jan Reedy in branch '3.4':
Issue #21477: idle htests - lower case function names, other cleanups.
msg218839 - (view) Author: Saimadhav Heblikar (sahutd) * Date: 2014-05-20 09:09
Adds spec dicts for aboutDialog, ClassBrowser, PathBrowser, textView and configHelpSourceEdit and modifies the related modules appropriately.
The spec dicts(and the tests relating to) for editorwindow and help dialog have not been modified in this patch.

The tests work OK when run individually from respective modules. The widgets are placed below parent. Some widgets close the parent when they are closed, some do not.(I feel the parent should be manually closed by the user, because the user might want to re-run a test. This would also help in reusing root, when running all the tests together).

The runall() seems shaky at the moment. For eg, as mentioned above, some widgets close the parent when they are closed, some do not. This is causes build-up of parent dialogs. I did not try to fix it, because things will change once we agree upon factoring out run() and runall(), about reusing the same root window for runall(). If things dont change, I will work on fixing the buildup of dialogs.

If this patch seems "incomplete" because of the above issue, please provide feedback about the tests itself, when run individually.
msg219021 - (view) Author: Saimadhav Heblikar (sahutd) * Date: 2014-05-24 04:34
Posting a cumulative patch of all htest written so far.

They include IOBinding, Tooltips, MultiStatusbar, tabbedpages, objectbrowser,
scrolledlist, dynOptionWidget, treewidget, widgetredirector,
colordelegator, calltip and multicall, besides aboutDialog, ClassBrowser, PathBrowser, textView and configHelpSourceEdit already posted before.
This patch is named week1.diff

*Improving run/runall - (run-runall.diff)
This patch concerns more with the way run/runall are executed. The only modification for this occurs in the file
I have streamlined run/runall into a single function. The behavior is same as the current, except for the reuse of a single root window and the addition of a "next" button.

The logic behind it is contained in line 206 to line 223 of when run-runall.diff is applied.
In short, a list of tuple containing(spec, kwds and callable object) is used to store the required information. Global variables maintain the above information only for the current test. Once a user finishes a test, the values of the global variables are updated to reflect the values for the next test. The "next" button is disabled for the case when a) it is the last test 2) when run() is called from a module

If this approach is desired, please say so. I will work on improving the responsiveness of the root window(Constant size of root dialog, ensuring buttons, labels etc stay in the "same place" and dont "jump" around).
msg219055 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-05-24 21:09
run-runall.diff import cleanly to 3.4. Running all the tests works well enough that I am applying this, with minor changes, to be a base for further patches. Good job.

The few problems I fixed:
1. had \n added at the beginning. I just deleted it.
2. 2 files had an unused 'import tkinter'. I deleted those lines. (Any new imports, that are used, should be 'import tkinter as tk' so that is the only place where the Tkinter/tkinter change shows up in the Idle file.)
3. patchcheck found 7 files with extra whitespace to be deleted.

Things to do starting from this.

1. See review comments on 

2. See review comments on text changes.

3. See review comments on individual tests.  There will be more of these, but run changes and 4) below are the most important now.

4. Many wrappers create a separate root=Tk() (and mainloop) ins4tead of reusing the parent arg. The result is that clicking [Next] does not delete the test window, as it is not a child of the main window. The test window has to be closed separately. So unless the test *requires* a new root and mainloop, please delete them. (Modal dialogs have to be closed explicitly - message should say so.)

5. When I changed root = tk.Tk() to root = parent in _editor_window, the test seemed to continue to work fine. Why did you comment it out? Please restore it and make any change necessary to _editor_window to work with the revised run().
msg219060 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-05-24 22:41
Since I wanted to get this large patch applied as a basis for further work, I went ahead with the 2.7 backport. I am listing the issues in converting run-runall-34.diff to run-runall-27.diff to help Saimadhav do this in the future.

1. /tkinter/Tkinter/ 7 places (easy).

2. /print(xxx)/print xxx/ 3 places in 2 idlelib files,
but leave print(widget.result) alone in htest

3. /importlib.machinery/imp/ in

4. In, the 2.7 line
    text = file(filename, 'r').read()
was changed in 3.x to two lines:
    with open(filename, 'r') as f:
        text =
Since inserting or deleting a line in a diff file (as opposed to the within-line edits above) is tricky, and since this line is part of a chunk being deleted, I left this alone in the -27.diff resulting from the changes above. The diff uploaded included the handpatch changes.

(Note: some time ago, I converted all open statements to 'with open' in 2.7 and 3.x. I did not think of 'file(' as a synonym for 'open('. Any other uses of 'file(' should be converted also.)

5. The surprise I had forgotten about. 'nonlocal', used in the new version of run(), is new in 3.0! Fortunately, I remember the ugly hack we used in 2.x. It does mean, however, that the run code is different in 2.7. Future patches to run should only patch run().

6. ColorDelegator: the code in the 3.x test is displayed for me as
I replaced source with a string literal. I think we should use a revised version of this, with everything that should be colored, in 3.x also and skip the file read.
msg219061 - (view) Author: Roundup Robot (python-dev) Date: 2014-05-24 22:49
New changeset ece24bcd1a6f by Terry Jan Reedy in branch '2.7':
Issue #21477: Idle htest: merge and modify run and runall; add many tests.

New changeset 038cbbef4539 by Terry Jan Reedy in branch '3.4':
Issue #21477: Idle htest: merge and modify run and runall; add many tests.
msg219066 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-05-24 23:44
I just discovered today that Rietveld can do diffs between diffs, so to speak. For example,
showed the changes between patched htest in 3.4 and 2.7.
msg219096 - (view) Author: Saimadhav Heblikar (sahutd) * Date: 2014-05-25 15:47
Modifications in htest-25052014.diff

1. ClassBrowser, PathBrowser, EditorWindow no longer close parent when closed

2. Sample code in _color_delegator changed to string, instead of reading from file.

3. String text change for Tooltip.

4.  Adds htest for FormatParagraph, Percolator, EditorWindow(rather uncomment's spec),  StackViewer, KeyBinding

5. Modification to run based on review comments at

6. Other cosmetic changes to spec string 'msg' text.

When this diff(subject to passing review and feedback) is pushed, I will make a corresponding patch for 2.7
msg219107 - (view) Author: Roundup Robot (python-dev) Date: 2014-05-25 22:44
New changeset d7eea8f608c2 by Terry Jan Reedy in branch '3.4':
Issue #21477: Idle htest: modify run; add more tests.
msg219108 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-05-25 22:47
0. I pushed a slight revision of the patch. See 2) for the main change. In htest, I also did 3), corrected some line spacing issues, and changed 'focussing' to the US spelling 'focusing'. A tested 2.7 version of the attached,, is top priority.

1. parent.mainloop() - ClassBrower, EditorWindow, PathBrowser: since mainloop is already running, this should have no effect. I had no problem with closing of child window closing parent. Perhaps there is an OS difference, perhaps related to the focus difference. Or this might even be a tk or tkinter bug in not masking OS differences. If the line is necessary for #nix, it seems harmless on Windows.

2. Let us remember that the purpose of htest is to test what cannot be sensibly tested with automated unittests. That includes the visual look of widgets and some behaviors that either cannot be automatically tested or that we currently do not know how to test.

The format paragragh methods and functions are well tested, better than a human will, in the current test_formatgraph unittest. I removed this part of the patch. (But see 5. below about moving it.)

When I wrote the notes that became htest.txt, a year ago, I had not written any tests other than for calltips. I listed almost all the files that had existig tests.  So don't add new tests not mentioned in htest.txt without discussion. And question the existing and proposed tests listed there.

For instance, I presume we can use the Text.tag_methods to write an automated ColorDelegator test that checks that tagged words are as expected and that colors match the configured values. We can leave the current test (with patch), until replaced.

3. Class/PathBrowser: not only does double clicking 'not work', it causes an exception to be printed to console or shell, but which seems to be ignored as test continues. The exception is either like this

Exception in Tkinter callback
Traceback (most recent call last):
  File "F:\Python\dev\4\py34\lib\idlelib\", line 121, in main
    seq, request = rpc.request_queue.get(block=True, timeout=0.05)
  File "F:\Python\dev\4\py34\lib\", line 175, in get
    raise Empty

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "F:\Python\dev\4\py34\lib\tkinter\", line 1487, in __call__
    return self.func(*args)
  File "F:\Python\dev\4\py34\lib\idlelib\", line 122, in flip
  File "F:\Python\dev\4\py34\Lib\idlelib\", line 174, in OnDoubleClick
    edit =
AttributeError: 'module' object has no attribute 'flist'

or with just the AttributeError. Unless and until we can suppress the traceback, the message should be changed from 'not work' to 'will print a traceback for an exception that is ignored'. [done]

4. Please comment on point 4 in msg219055.

5. Possible followup idea: By reviewing and running tests for classes I have not previously paid attention to, I learned something about them.  After htest is done, polish the test explanations as appropriate to explain each class to someone not familiar with it. Revise run() to start as follows: 

def run(*tests, *, test_list=None):
    if test_list is None: test_list = []

Add (for instance) with a callable and spec for non-htested classes (and behaviors). It could begin like this
from idlelib.idle_test.htest import run

def _format_paragraph(parent): ...(such as in current patch)

_format_paragraph_spec = ...(such as in current patch)

tour_list = [(_format_paragraph, _format_paragraph_spec),]
# automate by scanning globals for callables and grabbing matching specs

This should be a separate issue that follows on this one. If you feel like expanding the above to a preliminary patch, go ahead.

6. For me, many of the htest geometry increments are too small. Example:
root.geometry("+%d+%d"%(x, y + 150) # percolator
msg219109 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-05-25 22:51
Yes, remove unscrollable (test2) tree widget (review response).
msg219161 - (view) Author: Saimadhav Heblikar (sahutd) * Date: 2014-05-26 14:53
Summary for htest-26052014-34.diff and htest-26052014-27.diff
1. Adds htest for ReplaceDialog and SearchDialog
2. Removes the two canvases in TreeWidget as per code review comment. Now there is only a single ScrollableCanvas
3. Some text changes in spec dict messages

The corresponding 27 patch is to be applied on top of htest-25052014-27.diff.


1. Wrt point 4 in msg219055, I think wrapper functions are required along with creating a new root.
It ensures the parent dialog is not destroyed, even 'accidently' and across different OS.
About the concern that clicking '[Next]' does not destroy the child:
We could have the following line in wrapper function(which creates a new root)-
    parent.child = root

and, in the "next()" in run():
    except AttributeError:

To make things more readable, we could perhaps change the 'root' in run() to 'parent' and ensure consistency.
With this, clicking '[Next]' destroys the child, before moving onto the next htest.
A drawback with this approach would be that, we would need to create a wrapper function for those tests which currently dont have one(See: configNameDialog, configHelpSource, GetKeysDialog etc.)

2. Htest's for GrepDialog, outputwindow, configDialog and Filelist are not progressing because of assert statements in
I do not know the reasoning behind the assert statement either. Neither do I know how to 'ignore' it.
One way I found out is using the -O flag, but it is not pragmatic.
Another way is to have a macosxsupport._tk_type = "other" in the respective wrapper function.
But I do not know the effect of such a statement in a OSX environment.
If someone with a OSX environment wants to volunteer, please try running Lib/idlelib/ with and without the insertion
macosxsupport._tk_type = "other". With the insertion, the configDialog works on a Linux gnome environment and doesn't without it.
Funnily enough, the configDialog works as-is in Win7 which I tried on a VM.
One way would be to insert the above statment only if its a *nix environment.
msg219190 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2014-05-27 01:27
"2. Htest's for GrepDialog, outputwindow, configDialog and Filelist are not progressing because of assert statements in"

The asserts are to ensure that none of the Tk-variant tests (isCarbonTk(), isCocoaTk(), et al) are called before _initializeTkVariantTests(root) has been called.  And _initializeTkVariantTests can only be called after the initial calls to Tk have been made to create an initial window environment; it's only at that point that we can call Tk to enquire what variant of Tk we are running under ( and 33).  _initializeTkVariantTests is called from macosxSupport.setupApp which is called from PyShell.main.  This is fine for normal IDLE startup but it doesn't take into account the module level tests.  Ideally, you do want to have run _initializeTkVariantTests before running GUI tests so that the behavior is properly conditioned on Tk variant type, so stubbing out the Tk type with macosxsupport._tk_type = "other' is not desirable.  Perhaps the best way to deal with it is to create a common GUI test initialization function that is called by all of the GUI tests; the initialization function would be responsible for creating the Tk() root, calling _initializeTkVariantTests, and any other common steps that might arise.
msg219205 - (view) Author: Roundup Robot (python-dev) Date: 2014-05-27 06:47
New changeset 72a8a107eed1 by Terry Jan Reedy in branch '2.7':
Issue #21477: Idle htest: modify run; add more tests.
msg219207 - (view) Author: Roundup Robot (python-dev) Date: 2014-05-27 07:31
New changeset e770d8c4291c by Terry Jan Reedy in branch '2.7':
Issue #21477: Add htests for Search and Replace dialogs.

New changeset b8e4bb1e1090 by Terry Jan Reedy in branch '3.4':
Issue #21477: Add htests for Search and Replace dialogs.
msg219209 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-05-27 07:52
I think it time to make running through all or just some of the tests more pleasant. If we reversed the order [next], [test name], test instruction, then [next] would not just up and down. If the window were set to a constant width, then it would not jump back and forth either. The width should be just wide enough for the longest lines we use in, or can we just allow them to wrap?

To select just a one or a few tests (like just Search, Replace, and Tree for the 2605.. patch), a drop down list box would be nice. It could be beside the next box. With a constant width, there would be room.

Doing the test reminded me that Search (find) and Replace have a severe bug on Windows of not highlighting the the found text while the box is still open. There was an issue where this was supposedly fixed, but it is not. Find is usable by closing the box and using cntl-G for find next. But this does not work for replace, making replace useless on windows unless one is really sure about replace all.
msg219210 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-05-27 07:56
Ned, I recently saw that some of the builtin extensions call macosxsupport. I though then that it would be better if such calls were somehow handled automatically. I have no idea how and when to make them and so I don't know if the existing calls are needed or if other calls should be added. So I like your idea. It seems like it should be a separate issue.
msg219292 - (view) Author: Saimadhav Heblikar (sahutd) * Date: 2014-05-28 16:27
Summary for 
htest-28052014-34.diff and htest-28052014-27.diff

1. Add htest for GrepDialog,UndoDelegator and configDialog
2. Makes changes to the way the help string is displayed. The label has been replaced by a text widget made to look like a label, and also scrollable. The result is that the htest root dialog stays in the same place and same size throughout.(See the code for more information).
3. Some minor change to spec dict strings and in ObjectBrowser for child dialog placement.

With this, it leaves AutoCompleteWindow, TkMessageBoxes, Debugger(from 21477-htest.txt) to be tested. 

OutputWindow - already being tested from GrepDialog. There is nothing extra to be tested separately.

FileList - Is it already being tested through EditorWindow?
In case there is a need to test them, please say so. The code is ready.

RemoteDebugger and RemoteObjectBrowser - I need some input on how to begin with them.

Next: Apart from the above htest, a way to destroy the child when user clicks 'next', for certain modules like ClassBrowser, which don't work by the method of
msg219335 - (view) Author: Roundup Robot (python-dev) Date: 2014-05-29 05:47
New changeset 90dab7696e89 by Terry Jan Reedy in branch '2.7':
Issue #21477: Add htests for GrepDialog, UndoDelegator, and configDialog.

New changeset d90905960803 by Terry Jan Reedy in branch '3.4':
Issue #21477: Add htests for GrepDialog, UndoDelegator, and configDialog.
msg219336 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-05-29 05:57
Ned, this patch includes a call to macosxSupport. _initializeTkVariantTests(root) in Does this work on mac or is something else needed (like doing the same for individual tests that create another root)?
msg219484 - (view) Author: Roundup Robot (python-dev) Date: 2014-06-01 04:31
New changeset 334b6725b2f7 by Terry Jan Reedy in branch '2.7':
Issue #21477: Update htest docstring and remove extraneous differences between

New changeset e56c3585ea80 by Terry Jan Reedy in branch '3.4':
Issue #21477: Update htest docstring and remove extraneous differences between
msg219487 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-06-01 04:44
I regard the goal of this issue as having been accomplished. I opened #21624 for any further work on htests.
msg219535 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2014-06-01 23:36
"this patch includes a call to macosxSupport. _initializeTkVariantTests(root) in Does this work on mac or is something else needed (like doing the same for individual tests that create another root)?"

That looks good and, in a quick spot check running a few tests, seems to work fine.
Date User Action Args
2014-06-01 23:36:32ned.deilysetmessages: + msg219535
2014-06-01 04:44:08terry.reedysetstatus: open -> closed
superseder: Idle: polish htests
messages: + msg219487

resolution: fixed
stage: needs patch -> resolved
2014-06-01 04:31:24python-devsetmessages: + msg219484
2014-05-30 15:00:50sahutdsetfiles: + htest-docstring-27.diff
2014-05-30 14:59:38sahutdsetfiles: + htest-docstring-34.diff
2014-05-29 05:57:35terry.reedysetmessages: + msg219336
2014-05-29 05:47:14python-devsetmessages: + msg219335
2014-05-28 16:28:02sahutdsetfiles: + htest-28052014-27.diff
2014-05-28 16:27:05sahutdsetfiles: + htest-28052014-34.diff

messages: + msg219292
2014-05-27 07:56:07terry.reedysetmessages: + msg219210
2014-05-27 07:52:24terry.reedysetmessages: + msg219209
2014-05-27 07:31:54python-devsetmessages: + msg219207
2014-05-27 06:47:56python-devsetmessages: + msg219205
2014-05-27 01:28:00ned.deilysetnosy: + ned.deily
messages: + msg219190
2014-05-26 14:54:02sahutdsetfiles: + htest-26052014-27.diff
2014-05-26 14:53:28sahutdsetfiles: + htest-26052014-34.diff

messages: + msg219161
2014-05-26 04:24:31sahutdsetfiles: + htest-25052014-27.diff
2014-05-25 22:51:14terry.reedysetmessages: + msg219109
2014-05-25 22:47:33terry.reedysetfiles: + htest-25052014-34.diff

messages: + msg219108
2014-05-25 22:44:45python-devsetmessages: + msg219107
2014-05-25 15:47:06sahutdsetfiles: + htest-25052014.diff

messages: + msg219096
2014-05-24 23:44:28terry.reedysetmessages: + msg219066
2014-05-24 22:49:27python-devsetmessages: + msg219061
2014-05-24 22:41:04terry.reedysetfiles: + run-runall-27.diff

messages: + msg219060
2014-05-24 21:10:11terry.reedysetfiles: + run-runall-34.diff

messages: + msg219055
2014-05-24 04:36:57sahutdsetfiles: - about+classbrowser+cfghelpsrcedit+pathbrowser+textview.diff
2014-05-24 04:36:28sahutdsetfiles: + run-runall.diff
2014-05-24 04:34:42sahutdsetfiles: + week1.diff

messages: + msg219021
2014-05-23 17:43:29terry.reedysetnosy: + jesstess
2014-05-20 09:31:00sahutdsetfiles: + about+classbrowser+cfghelpsrcedit+pathbrowser+textview.diff
2014-05-20 09:29:32sahutdsetfiles: - about+classbrowser+cfghelpsrcedit+pathbrowser+textview.diff
2014-05-20 09:09:19sahutdsetfiles: + about+classbrowser+cfghelpsrcedit+pathbrowser+textview.diff
keywords: + patch
messages: + msg218839
2014-05-20 02:56:54python-devsetnosy: + python-dev
messages: + msg218830
2014-05-16 18:56:20terry.reedysettitle: Idle: improve idle_test,htest -> Idle: improve idle_test.htest
2014-05-12 04:16:37terry.reedysetfiles: + 21477-htest.txt
assignee: terry.reedy
stage: needs patch
type: enhancement
versions: + Python 2.7, Python 3.4, Python 3.5
2014-05-12 04:08:37terry.reedycreate