classification
Title: IDLE Unit test for SearchEngine.py
Type: enhancement Stage: resolved
Components: IDLE Versions: Python 3.4, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: JayKrish, Todd.Rovito, philwebster, python-dev, terry.reedy
Priority: normal Keywords: patch

Created on 2013-07-18 03:30 by philwebster, last changed 2013-08-31 20:32 by terry.reedy. This issue is now closed.

Files
File name Uploaded Description Edit
test_searchengine.patch philwebster, 2013-07-18 03:30
test_searchengine2.patch philwebster, 2013-07-24 19:42 review
18489-test_searchengine4.diff terry.reedy, 2013-08-19 06:19 review
18489-test_searchengine5.diff terry.reedy, 2013-08-25 02:11 review
18489-test_searchengine6.diff terry.reedy, 2013-08-30 02:52 review
Messages (9)
msg193266 - (view) Author: Phil Webster (philwebster) * Date: 2013-07-18 03:30
This test uses the mock text widget to search forwards and backwards, with and without wrapping. It also tests for empty matches with the 'ok' flag set in search_text(). The patch relies on the mock text tag_add function implemented in #18226.
msg193671 - (view) Author: Phil Webster (philwebster) * Date: 2013-07-24 19:42
Added tests for the rest of the SearchEngine module. I used the mock tkMessageBox for testing the error display, but used the tkinter Text widget for other tests because mark_set and tag_add/remove haven't been added to the mock yet.
msg195601 - (view) Author: Roundup Robot (python-dev) Date: 2013-08-19 05:06
New changeset 310d187020e3 by Terry Jan Reedy in branch '2.7':
Issue #18489: idlelib.SearchEngine - add docstrings
http://hg.python.org/cpython/rev/310d187020e3

New changeset cfb510884a13 by Terry Jan Reedy in branch '3.3':
Issue #18489: idlelib.SearchEngine - add docstrings
http://hg.python.org/cpython/rev/cfb510884a13
msg195603 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-08-19 06:19
As with searchdialogbase tests, I get the following in the console every time I run the test file within idle.
'''
can't invoke "event" command:  application has been destroyed
    while executing
"event generate $w <<ThemeChanged>>"
    (procedure "ttk::ThemeChanged" line 6)
    invoked from within
"ttk::ThemeChanged"
'''
This seems like a bug somewhere, but where? Why is ttk involved?

When I applied the patch, the tests ran, but left two tk windows. I added the missing root.destroy() calls. I plan to separate the class methods that search a text widget into a separate test case (or more).

10 lines are not yet covered. 6 should be easy.
msg196111 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-08-25 02:11
Big changes: monkey-patched module so tests of functions not using Text are non-gui; split search tests from other class tests as part of this. Several other little changes.

The four lines still not covered are the bodies of
if ok: start = last
if wrapped and line > startline: break
if wrapped and line < startline: break
if i == j: j = j+1 
I will look at these when I review the search tests, but they are not commit blockers.
msg196505 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-08-30 02:52
The attached patch works on 3.3 and just need a small addition for 100$ coverage. After that, I intend to commit after porting to 2.7 (only two lines to change, I think) and testing it there.

I split the search test case into three, one for each method. The tests for search_text repeated the tests for search_forward/backward. Simple mocks for the latter two allow to test for what search_text actually does: pick the right function to call and right starting point.

The effect of the ok parameter is complicated because it has different effects in search_text and the other two (and less effect in search_backward than in search_forward because they are not symmetric).

'\w+' never matches an empty string; so there was no test of 'ok=true' in search_forward. '\w*' can have empty matches and there now is a test. I discovered what seems to me a bug. If an initial null match is ignored, the search skips the rest of the line and skips to the next. This seems wrong but I am not sure what the proper behavior should be. I want to investigate the use of ok in the dialogs, especially the replace dialog before deciding

The test of search_forward uses the mock Text. The remaining gui uses here (and many in other tests) could be eliminated with just a partial implementation of marks and selections, one that kept them fixed rather than moving them with insert and delete. So far we have been inserting text just once and then setting and getting things on a fixed text.
msg196506 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-08-30 03:11
Adding
        engine.patvar.set(None)
        Equal(search(text), None)

to test_search completed the coverage.
msg196669 - (view) Author: Roundup Robot (python-dev) Date: 2013-08-31 20:29
New changeset 4179e2312089 by Terry Jan Reedy in branch '2.7':
Issue #18489: Add complete, gui-free tests for idlelib.SearchEngine.
http://hg.python.org/cpython/rev/4179e2312089

New changeset dfbf0f9034cc by Terry Jan Reedy in branch '3.3':
Issue #18489: Add complete, gui-free tests for idlelib.SearchEngine.
http://hg.python.org/cpython/rev/dfbf0f9034cc

New changeset 7605847c15a4 by Terry Jan Reedy in branch 'default':
Merge from 3.3 #18489 Search Engine tests
http://hg.python.org/cpython/rev/7605847c15a4
msg196670 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-08-31 20:32
By masking mock Text.index with instance functions, I removed the need for tk.Text and hence the tests are gui free.
History
Date User Action Args
2013-08-31 20:32:03terry.reedysetstatus: open -> closed
resolution: fixed
messages: + msg196670

stage: commit review -> resolved
2013-08-31 20:29:20python-devsetmessages: + msg196669
2013-08-30 03:11:21terry.reedysetmessages: + msg196506
2013-08-30 02:52:14terry.reedysetfiles: + 18489-test_searchengine6.diff

messages: + msg196505
stage: patch review -> commit review
2013-08-25 02:11:04terry.reedysetfiles: + 18489-test_searchengine5.diff

messages: + msg196111
2013-08-19 06:19:42terry.reedysetfiles: + 18489-test_searchengine4.diff
2013-08-19 06:19:27terry.reedysetassignee: terry.reedy
messages: + msg195603
stage: patch review
2013-08-19 05:06:00python-devsetnosy: + python-dev
messages: + msg195601
2013-07-24 19:42:20philwebstersetfiles: + test_searchengine2.patch

messages: + msg193671
2013-07-18 03:30:19philwebstercreate