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: test AutoExpand.py #62492

Closed
JayKrish mannequin opened this issue Jun 24, 2013 · 11 comments
Closed

Idle: test AutoExpand.py #62492

JayKrish mannequin opened this issue Jun 24, 2013 · 11 comments
Labels
tests Tests in the Lib/test dir topic-IDLE type-feature A feature request or enhancement

Comments

@JayKrish
Copy link
Mannequin

JayKrish mannequin commented Jun 24, 2013

BPO 18292
Nosy @terryjreedy, @rovitotv, @zware
Files
  • test-autoexpand.diff
  • test-autoexpand1.diff: Patch in response to msg219549
  • test-autoexp-18292.diff
  • test-autoexpand2.diff
  • test-autoexpand3.diff: Restructured the tests from test-autoexpand2.diff. Additional test for state reset
  • 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 = None
    closed_at = <Date 2014-06-05.05:44:17.161>
    created_at = <Date 2013-06-24.18:29:14.877>
    labels = ['expert-IDLE', 'type-feature', 'tests']
    title = 'Idle: test AutoExpand.py'
    updated_at = <Date 2014-06-05.23:44:01.651>
    user = 'https://bugs.python.org/JayKrish'

    bugs.python.org fields:

    activity = <Date 2014-06-05.23:44:01.651>
    actor = 'zach.ware'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-06-05.05:44:17.161>
    closer = 'terry.reedy'
    components = ['IDLE', 'Tests']
    creation = <Date 2013-06-24.18:29:14.877>
    creator = 'JayKrish'
    dependencies = []
    files = ['35436', '35458', '35464', '35470', '35477']
    hgrepos = []
    issue_num = 18292
    keywords = ['patch']
    message_count = 11.0
    messages = ['191795', '193359', '219504', '219549', '219661', '219684', '219777', '219780', '219846', '219853', '219857']
    nosy_count = 8.0
    nosy_names = ['terry.reedy', 'jesstess', 'Todd.Rovito', 'python-dev', 'zach.ware', 'JayKrish', 'philwebster', 'Saimadhav.Heblikar']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue18292'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @JayKrish
    Copy link
    Mannequin Author

    JayKrish mannequin commented Jun 24, 2013

    Continuing the IDLE unittest framework initiated in bpo-15392. Writing test for AutoExpand.py

    @JayKrish JayKrish mannequin added topic-IDLE tests Tests in the Lib/test dir type-feature A feature request or enhancement labels Jun 24, 2013
    @JayKrish
    Copy link
    Mannequin Author

    JayKrish mannequin commented Jul 19, 2013

    I am trying to improve the _decode function of mock Text class because most of the Idletests needs the mock text and requires some more features to handle indexes.
    Created an issue IDLE:Improvements- Improving Mock_Text
    http://bugs.python.org/issue18504

    @SaimadhavHeblikar
    Copy link
    Mannequin

    SaimadhavHeblikar mannequin commented Jun 1, 2014

    Attached patch adds unittest for idlelib`s AutoExpand.

    Depends on bpo-18504 for Text's mocking abilities.

    @terryjreedy terryjreedy changed the title IDLE Improvements: Unit test for AutoExpand.py Idle: test AutoExpand.py Jun 2, 2014
    @terryjreedy
    Copy link
    Member

    For tests that use a Text widget, I want the first version to be a gui test using tkinter.Text. This removes mock Text as an issue in writing the tests. I will not commit without running the test 'live' at least once.

    Once the file (or at least a TestCase) is complete, we can then consider replacing the real Text with the mock. The gui code is commented out, rather than deleted, in case there is ever a need to switch back. See test_searchengine.py (bpo-18489), where this was done, (Even partial conversions are worthwhile if complete conversion is not possible.) Did I forget to say this in idle_test/README.txt? (I know I forget to mention this directly before now, Sorry ;-).

    Some modules import tkinter and instantiate widgets either upon import or during testing, (This is different from taking a widget instance as an argument in .__init__.) If so a gui-free test requires that the module be monkey-patched with mocks. For SearchEngine, the only widgets are XyzVars and TkMessageBox, for which we do have mocks. AutoExpand does not import tkinter, so it is fine as is.

    In your patch, comment out "from idlelib.idle_test.mock_tk import Text" and add the needed gui code. See the commented out code in
    test_searchengine.

    @terryjreedy
    Copy link
    Member

    Great start. The initial coveraqe is 90%, only missing the 5 lines in getwords in the bodies of
    if dict.get(w):
    continue
    ,,,
    for w in wafter:
    if dict.get(w):
    continue
    words.append(w)
    dict[w] = w

    I would like to cover those because I would like to later replace the dict instance dict (bad name!) with a set, 'seen'. 'dict.get(w)' would become 'w in seen'; 'dict[w] = w' would become 'seen.add(w)'

    Two comments: 1. Using 'previous' to detect the action of 'expand' is really clever.

    1. As is typical, you wrote both too much and too little. Too much because some of the subtests are redundant, testing the same code paths repeatedly. Every subtest should have a reason. Too little because some code paths are skipped. To cover with both before and after, with repeats and missed: insert 'aa ab xy aa ac\n ad ae xy ae ab\n', Then insert 'a' at the beginning of the second line ((2,0) as I remember). Words should be ['ac', 'aa', 'ab', 'ad' 'ae' 'a']. Expand/previous should produce those in that order. Also do a test with no before and some after. You have already done some before and no after.

    I uploaded my version. See Rietveld diff for changes. Some notes:

    Leave out '-' after 'test-' in file name. Makes coverage call easier.
    Todays test.support patch made a line is each file obsolete.
    Must keep reference to root to destroy it properly.
    I added conditionals so we can easily switch between gui and mock.
    These should be added to previous tests that run both ways.
    test_get_words had a bug; assertCountEqual instead of assertEqual.

    getprevword only sees ascii chars when finding the word prefix. On the other hand, for 3.x, \w in getwords matches unicode chars for suffixes. If possible, getprevword should use \w to determine the prefix. Then 2.7 and 3.x should work on ascii and unicode respectively, with the same code. In a second stage, we should fix this and add tests with non-ascii chars (using \unnnn in literals).
    --------

    self.bell() makes no sound for me. How about you?

    A different non-critical nuisance. I start Idle in the debug interpreter with 'import idlelib.idle'. When root is destroyed, then the following is printed in the console interpreter after unittest is done.

    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"

    I determined the timing by changing to 'exit=False' in unittest.main and adding 'time.sleep(2); print('done') after the u.main() call. Do you see anything like this? (Deleting the class attributes does not fix this.) tkinter.ttk in not in sys.modules, but perhaps something in one of the other modules directly accesses ttk at the tcl level when shutting down.

    @SaimadhavHeblikar
    Copy link
    Mannequin

    SaimadhavHeblikar mannequin commented Jun 3, 2014

    Attached a patch incorporating changes from msg219661 and test-autoexp-18292.diff

    >"I would like to cover those because ...."
    Done

    >Point 2
    Done

    >"self.bell() makes no sound for me. How about you?"
    No sound for me as well.

    >Do you see anything like this?
    Yes. Reproducing your action prints this message. I had previously seen it(when writing htest), it was random. I was unable to reproduce it then.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 5, 2014

    New changeset bdbcd0ae0bde by Terry Jan Reedy in branch '2.7':
    Issue bpo-18292: Idle - test AutoExpand. Patch by Saihadhav Heblikar.
    http://hg.python.org/cpython/rev/bdbcd0ae0bde

    New changeset bbdcf09e3097 by Terry Jan Reedy in branch '3.4':
    Issue bpo-18292: Idle - test AutoExpand. Patch by Saihadhav Heblikar.
    http://hg.python.org/cpython/rev/bbdcf09e3097

    @terryjreedy
    Copy link
    Member

    Coverage 100%. 2.7 version was easy, so committed after a few minor changes. We can revisit using the mock later.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 5, 2014

    New changeset 2567c68fb300 by Zachary Ware in branch '2.7':
    Issue bpo-18292: s/tkinter/Tkinter/
    http://hg.python.org/cpython/rev/2567c68fb300

    @terryjreedy
    Copy link
    Member

    Whoops. Zach, did you catch that by reading the checkin, running the test, or seeing a buildbot problem. Is not the first, what symptom on what system revealed the omission?

    @zware
    Copy link
    Member

    zware commented Jun 5, 2014

    Terry J. Reedy added the comment:

    Whoops. Zach, did you catch that by reading the checkin, running the test,
    or seeing a buildbot problem. Is not the first, what symptom on what system
    revealed the omission?

    Buildbots; there were several red 2.7 bots and I got curious :). See
    http://buildbot.python.org/all/builders/AMD64%20Ubuntu%20LTS%202.7/builds/1091/steps/test/logs/stdio
    for example, it basically looked like there was no resource guard.

    @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
    tests Tests in the Lib/test dir topic-IDLE type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants