Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDLE Unit test for SearchEngine.py #62689

Closed
philwebster mannequin opened this issue Jul 18, 2013 · 9 comments
Closed

IDLE Unit test for SearchEngine.py #62689

philwebster mannequin opened this issue Jul 18, 2013 · 9 comments
Assignees
Labels
topic-IDLE type-feature A feature request or enhancement

Comments

@philwebster
Copy link
Mannequin

philwebster mannequin commented Jul 18, 2013

BPO 18489
Nosy @terryjreedy, @rovitotv
Files
  • test_searchengine.patch
  • test_searchengine2.patch
  • 18489-test_searchengine4.diff
  • 18489-test_searchengine5.diff
  • 18489-test_searchengine6.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/terryjreedy'
    closed_at = <Date 2013-08-31.20:32:03.369>
    created_at = <Date 2013-07-18.03:30:19.781>
    labels = ['expert-IDLE', 'type-feature']
    title = 'IDLE Unit test for SearchEngine.py'
    updated_at = <Date 2013-08-31.20:32:03.368>
    user = 'https://bugs.python.org/philwebster'

    bugs.python.org fields:

    activity = <Date 2013-08-31.20:32:03.368>
    actor = 'terry.reedy'
    assignee = 'terry.reedy'
    closed = True
    closed_date = <Date 2013-08-31.20:32:03.369>
    closer = 'terry.reedy'
    components = ['IDLE']
    creation = <Date 2013-07-18.03:30:19.781>
    creator = 'philwebster'
    dependencies = []
    files = ['30961', '31030', '31369', '31456', '31516']
    hgrepos = []
    issue_num = 18489
    keywords = ['patch']
    message_count = 9.0
    messages = ['193266', '193671', '195601', '195603', '196111', '196505', '196506', '196669', '196670']
    nosy_count = 5.0
    nosy_names = ['terry.reedy', 'Todd.Rovito', 'python-dev', 'JayKrish', 'philwebster']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue18489'
    versions = ['Python 2.7', 'Python 3.3', 'Python 3.4']

    @philwebster
    Copy link
    Mannequin Author

    philwebster mannequin commented Jul 18, 2013

    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 bpo-18226.

    @philwebster philwebster mannequin added topic-IDLE type-feature A feature request or enhancement labels Jul 18, 2013
    @philwebster
    Copy link
    Mannequin Author

    philwebster mannequin commented Jul 24, 2013

    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.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 19, 2013

    New changeset 310d187020e3 by Terry Jan Reedy in branch '2.7':
    Issue bpo-18489: idlelib.SearchEngine - add docstrings
    http://hg.python.org/cpython/rev/310d187020e3

    New changeset cfb510884a13 by Terry Jan Reedy in branch '3.3':
    Issue bpo-18489: idlelib.SearchEngine - add docstrings
    http://hg.python.org/cpython/rev/cfb510884a13

    @terryjreedy
    Copy link
    Member

    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.

    @terryjreedy terryjreedy self-assigned this Aug 19, 2013
    @terryjreedy
    Copy link
    Member

    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.

    @terryjreedy
    Copy link
    Member

    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.

    @terryjreedy
    Copy link
    Member

    Adding
    engine.patvar.set(None)
    Equal(search(text), None)

    to test_search completed the coverage.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 31, 2013

    New changeset 4179e2312089 by Terry Jan Reedy in branch '2.7':
    Issue bpo-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 bpo-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 bpo-18489 Search Engine tests
    http://hg.python.org/cpython/rev/7605847c15a4

    @terryjreedy
    Copy link
    Member

    By masking mock Text.index with instance functions, I removed the need for tk.Text and hence the tests are gui free.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-IDLE type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant