Skip to content

Create a unittest framework for IDLE #59597

Closed

Description

@terryjreedy
BPO 15392
Nosy @terryjreedy, @ncoghlan, @ned-deily, @ezio-melotti, @serwy, @bitdancer, @rovitotv
Files
  • 15392_idletestframework_1.patch: Initiating Idle TestFrameWork
  • idletest2.diff: replaces previous patch
  • idletest3.diff.txt
  • idletest3u.diff: 'unix/osx format'
  • idletest4u.diff
  • frametest.py: Tests the test framework
  • 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-05-30.21:35:53.717>
    created_at = <Date 2012-07-19.04:44:40.180>
    labels = ['expert-IDLE', 'type-feature', 'tests']
    title = 'Create a unittest framework for IDLE'
    updated_at = <Date 2013-11-04.04:10:21.176>
    user = 'https://github.com/terryjreedy'

    bugs.python.org fields:

    activity = <Date 2013-11-04.04:10:21.176>
    actor = 'python-dev'
    assignee = 'terry.reedy'
    closed = True
    closed_date = <Date 2013-05-30.21:35:53.717>
    closer = 'terry.reedy'
    components = ['IDLE', 'Tests']
    creation = <Date 2012-07-19.04:44:40.180>
    creator = 'terry.reedy'
    dependencies = []
    files = ['29973', '30276', '30326', '30330', '30334', '30335']
    hgrepos = []
    issue_num = 15392
    keywords = ['patch']
    message_count = 60.0
    messages = ['165825', '165833', '165889', '166072', '173304', '173797', '184927', '185024', '187393', '187539', '187545', '187562', '187569', '187587', '187616', '187621', '187697', '188481', '188649', '189258', '189261', '189262', '189264', '189267', '189268', '189269', '189270', '189271', '189274', '189275', '189276', '189284', '189290', '189313', '189339', '189564', '189565', '189627', '189712', '189713', '189717', '189723', '189733', '189775', '189787', '189790', '190129', '190144', '190165', '190166', '190174', '190189', '190266', '190376', '190384', '190385', '190386', '190387', '190390', '202083']
    nosy_count = 14.0
    nosy_names = ['terry.reedy', 'ncoghlan', 'ned.deily', 'ezio.melotti', 'roger.serwy', 'r.david.murray', 'Todd.Rovito', 'tshepang', 'python-dev', 'francismb', 'Guilherme.Sim\xc3\xb5es', 'JayKrish', 'Tomoki.Imai', 'alex.rodas']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue15392'
    versions = ['Python 2.7', 'Python 3.3', 'Python 3.4']

    Activity

    1. terryjreedy commented on Jul 19, 2012

      @terryjreedy
      MemberAuthor

      Idle needs a unittest framework for module test modules. This means a test directory with at least one test module, a runtest module that successfully runs that test module, any new support functions needed for that test module, and inclusion of test_idle in Lib/test.

      I am thinking of something like Lib/tkinter/test, but without subdirectories. I presume there should be something like tkinter/test/runtests, but I do not know if it reflects current best practice, nor whether it should be in idlelib or in idlelib/test.

      One feature of runtests and the tkinter framework is separation of tests that do and do not require a gui. This requires cooperation of writers of each test module. Buildbots can only run tests that do not require a gui and nearly everyone else wants the same. On the other hand, we need automated gui tests too. A complete test of idlelib/runtest requires a test module with both kinds of tests.

      List/test has test_tk. It runs tests with enable_gui=false unless run directly (and intentionally) as the main module. (Testing test_idle would also require tests in both modes.) It checks that tkinter is available. Should test_idle also check that idle is available? (On Windows, one can install both or neither. I don't know the situation on other systems.)

      This issue was inspired by bpo-12510 and is interdependent with it. As part of that issue, I would like to convert the expanded test set to run under unittest. bpo-12510 needs a place to put a test_calltips module. On the other hand, this issue needs a test_x module to test runtests and test_idle.

      tkinter/test/support has functions that can be used in idle tests, in particular, simulate_mouse_click(). I believe a needed addition is simulate_text_entry. That is needed to really finish the calltips tests. Currently, complete testing of tooltips requires non-automated hand tests.

      Would simulate_mouse_click include selecting menu items, or would that be a separate function?

      With such a test framework established, we could start adding tests as part of other issues, as is normal practice.

      (Note: tkinter/test is pretty skeletal, and probably could use expansion, but except for support functions immediately needed for test_calltips, that is another issue.)

    2. self-assigned this
      on Jul 19, 2012
    3. added
      tests
      type-feature
      on Jul 19, 2012
    4. bitdancer commented on Jul 19, 2012

      @bitdancer
      Member

      All the tests should run from the standard test runner tool (currently regrtest), with the GUI tests guarded by the GUI resource, which is how it works for TK. I always run the test suite with -uall before non-trivial commits, so I do in fact run the TK gui tests on a regular basis. I would do the same with idle. I hope there are at least a few other developers that run with -uall on a regular basis :)

      Whether or not there is value in a separate runner is a separate question. If there is value in having one to you and the other people working on idle, then make one. But for those of us who touch it only occasionally, the separate runner is not likely to get used. I wasn't even aware there was one for tkinter.

      There was a push a while back suggesting that best practice would be to have all tests be in the 'test' subdirectory. I moved email/test into test/test_email, and I prefer having it there. On the other hand, Michael prefers having unittest/test, and has kept the unittest unit tests there. So that part is up to you, but I encourage you to consider putting them in the test subdirectory, and if you want to do that I would help out with moving the existing tkinter tests to the 'test' dir.

      And yes, either way the tests should test for the presence of idle and skip if idle is not available.

    5. terryjreedy commented on Jul 19, 2012

      @terryjreedy
      MemberAuthor

      I have not really used unittest, so I only know to blindly copy what has been done. Hence I need help to do better.

      Do you actually get gui tests for test_tk? When I run test/test_tk from Idle editor, and hence as __main__, I only get non-gui tests in spite of enable_gui being set True. Or maybe I just did not see them. (This is actually an improvement over the normal failure of test_tk on Windows. See bpo-10652)

      Is tkinter/test/runtktests properly called a test runner?
      test/test_tk uses it to gather the tests to run:
      support.run_unittest(
      *runtktests.get_tests(text=False, packages=['test_tkinter']))
      It is used within the ttk tests also. As I suggested above, I do not really know if we really need the equivalent.

      I strongly prefer idlelib/test since it will make developing **much** easier for me on Windows. Also, it would be part of the optional install of idlelib, as tkinter/test is for tkinter.

      Adding test/test_idle will not be too much use until issue bpo-10652 is resolved so it would actually run with -m test.

    6. bitdancer commented on Jul 21, 2012

      @bitdancer
      Member

      The screen flickers a bunch, so something involving my display is certainly happening.

      As for runtktests...test suites that live in the package as opposed to the test directory require support files to gather the tests to be run. This can be done by the test_xxxx.py file in the test directory (which is what regrtest runs), or it can be done in a function imported from the packages test directory. For tkinter it looks like the test gathering is done in runtktests. Most Python test_xxxx file can be run directly to run the relevant tests, and runtktests works the same way. So yes it is a runner, but that appears to be a convenience just like for other test_xxxx files, and not anything special.

    7. ned-deily commented on Oct 19, 2012

      @ned-deily
      Member

      There is now one test available to be applied from bpo-16226; see http://bugs.python.org/file27613/issue16226_test.patch. It may need to be modified depending on where the tests are ultimately put in the source tree.

    8. serwy commented on Oct 25, 2012

      serwymannequin
      Mannequin

      bpo-7883 also has a test.

    9. terryjreedy commented on Mar 21, 2013

      @terryjreedy
      MemberAuthor

      Since writing this, I ran test_ttk_guionly by itself, so it would run, and saw the flickering windows. I have thought about using unitest.mock and Nick has offered to help particlarly with that.

    10. ncoghlan commented on Mar 23, 2013

      @ncoghlan
      Contributor

      I'll start with a bit of philosophical guidance :)

      1. As much as possible, push logic testing down into the non-GUI tests. Where unittest.mock can help here is when you have a piece of code to test that is *almost* independent of the GUI, but needs to call an API to either get input from the user or to send something to the screen. unittest.mock can then be set up to intercept that call, either to check that it happened as expected (display operations) or to provide a predetermined answer (input operations).

      2. For the GUI tests, unittest.mock is likely to be most useful in providing predetermined input. There's only so much you can do with this, it's ultimately about ensuring that the code tested against mocked out APIs in the lower level tests at least doesn't throw exceptions when tested against the real APIs. Proper GUI testing is actually a much harder test automation problem, so it probably makes sense to focus on the non-GUI tests for now.

    11. TomokiImai commented on Apr 20, 2013

      TomokiImaimannequin
      Mannequin

      I'm a student thinking of participating in Google Summer of Code.
      And want to work to create a unittest for IDLE.

      Using unittest.mock seemed to be good way to test GUI.
      But there is a problem.
      There is no unittest.mock in Python2.
      http://docs.python.org/2/library/unittest.html

      I think using third party mock seemed to be ok, but not best way.
      https://pypi.python.org/pypi/mock
      Because, IDLE is a part of official python.
      I think relying on third party module is not good.

      Of cource, I would forcus on non-GUI unittest.
      But GUI-test would be needed.

    12. JayKrish commented on Apr 21, 2013

      JayKrishmannequin
      Mannequin

      The aimed versions for this unit test frame work is python 3.3, 3.4. So as Nick said, unittest.mock may have no issues on this.
      As you said 3rd party modules seems not a better way.But the link you provided ( https://pypi.python.org/pypi/mock ) says .. "mock is now part of the Python standard library, available as unittest.mock in Python 3.3 onwards."
      And yes, GUI testings
      While I was writting my proposal on this project Todd.Rovito mentioned me " .. you should still complete some GUI tests so future developers will have a model. "

    13. JayKrish commented on Apr 22, 2013

      JayKrishmannequin
      Mannequin

      There is a need of a proper design in whether to put tests in test sub directory or to create idlelib/test directory.

      For my GSoc proposal initial draft, I suggested to start with
      Put tests in test/test_idle directory (like test/test_email would be the best practice).
      Test for the presence of idle and skip if idle is not available.
      Move the existing,pending tests for idle ( http://bugs.python.org/file27613/issue16226_test.patch , http://bugs.python.org/file24075/test_idlelib.py,....) into this directory.
      (which my patch 15392_idletestframework_1.patch did for me)

      Considering the point terry.reedy mentioned, "Adding test/test_idle will not be too much use until issue bpo-10652 is resolved so it would actually run with -m test", my view is, the issue bpo-10652 on this message is on a healthy patch review, so it would actually run with -m test in near-future
      Expecting your suggestions on this design decisions.

    14. 36 remaining items

    15. bitdancer commented on May 27, 2013

      @bitdancer
      Member

      Heh. Yeah, I use patch because I don't just work with mercurial/python, and I find the patch command simpler to use for applying patches in general, since I never want an autocommit. (The exception would be if I'm applying a patch that involves extended diff stuff that patch doesn't recognize.) It makes sense that the devguide talks about import, though, since the patches here always ought to be things generated by hg and thus handleable by import. I'm not sure why this one would have failed for you.

    16. python-dev commented on May 28, 2013

      python-devmannequin
      Mannequin

      New changeset 24c3e7e08168 by Terry Jan Reedy in branch '3.3':
      Issue bpo-15392: Create a unittest framework for IDLE.
      http://hg.python.org/cpython/rev/24c3e7e08168

    17. terryjreedy commented on May 28, 2013

      @terryjreedy
      MemberAuthor

      Before committing, I experimented with disabling test/test_idle. The simple and safe method is to comment out the 'load_tests' line. With no tests discovered, all pass ;-). Without verbosity, there is no indication that there were none. A little harder, and needing to be tested for typos before committing, is to add this line before that line:
      import unittest; raise unittest.SkipTest('skip for buildbots')
      Regrtest (py -m test test_idle) registers the unexpected skip. Unittest (py -m test.test_idle) exits with a traceback. This is recorded in an updated README, which also incorporates Todd's suggestion. I also touched up test/test_idle.py.

      If buildbots do not break, I will work on 2.7.

    18. terryjreedy commented on May 28, 2013

      @terryjreedy
      MemberAuthor

      Last I checked, test_idle passes on the stable buildbots.

      But it fails on a machine without threads, such as http://buildbot.python.org/all/builders /AMD64%20Fedora%20without%20threads%203.3/builds/752/steps/test/logs/stdio
      On this machine, thread-related tests are skipped: some seem expected, some not.

      The chain of imports is test_pathbrowser <- PathBrowser <- ClassBrowser <- PyShell <- threading <- _thread. Since a PyShell import is required to run Idle (PyShell.main), even with just the editor, I will put the _thread import check in test_idle itself rather than sprinkling it throughout the test suite as dependencies are discovered.

      (Besides the bother of the latter, the dependency could go away if PyShell only uses threading to runs user code in the same process, or delayed if it is used for other features that might not be used.)

    19. ncoghlan commented on May 28, 2013

      @ncoghlan
      Contributor

      Building without threads is generally going to be for embedded systems without a GUI anyway, so I think it's fine to just skip the entire IDLE test suite when real threads aren't available.

    20. python-dev commented on May 29, 2013

      python-devmannequin
      Mannequin

      New changeset 968f6094788b by Terry Jan Reedy in branch '3.3':
      Issue bpo-15392: Do not run tests if threading/_thread not available. Otherwise
      http://hg.python.org/cpython/rev/968f6094788b

    21. python-dev commented on May 30, 2013

      python-devmannequin
      Mannequin

      New changeset 93eb15779050 by Terry Jan Reedy in branch '2.7':
      Issue bpo-15392: Create a unittest framework for IDLE, 2.7 version.
      http://hg.python.org/cpython/rev/93eb15779050

    22. terryjreedy commented on May 30, 2013

      @terryjreedy
      MemberAuthor

      Biggest change is no support module in 2.7, so in test_idle.py import inside try:except to skip if dependencies not present. Minor changes in CallTips.py and test_calltips.py. Buildbots are fine. This meets my initial goal; issue done.

      I opened bpo-18103 for consideration of gui tests. But except for improving the existing no-buildbot, human-needed tests, I consider that a lower priority right now.

    23. ned-deily commented on May 30, 2013

      @ned-deily
      Member

      The test.support module was renamed in Python 3 from test.test_support in Python 2. While the 3x support has expanded and diverged somewhat, with a bit of try hacking it should be possible to minimize the source differences between the 2.7 and 3.x tests.

    24. ezio-melotti commented on May 30, 2013

      @ezio-melotti
      Member

      For the other modules we just use test.test_support on 2.x and test.support in 3.x, without using try/except and without trying to maintain source compatibility with both. You might get a merge conflict every once in a while, but I don't think that's a big deal.

    25. python-dev commented on May 30, 2013

      python-devmannequin
      Mannequin

      New changeset 6159916c712e by Terry Jan Reedy in branch '2.7':
      Issue bpo-15392: Use test.test_support, as used test.support in 3.x.
      http://hg.python.org/cpython/rev/6159916c712e

    26. python-dev commented on May 31, 2013

      python-devmannequin
      Mannequin

      New changeset 16fea8b0f8c4 by Terry Jan Reedy in branch '3.3':
      Issue bpo-15392: Finish news entry.
      http://hg.python.org/cpython/rev/16fea8b0f8c4

    27. python-dev commented on Nov 4, 2013

      python-devmannequin
      Mannequin

      New changeset dac6aea39814 by Ned Deily in branch '2.7':
      Issue bpo-15392: Install idlelib/idle_test.
      http://hg.python.org/cpython/rev/dac6aea39814

      New changeset e52dad892521 by Ned Deily in branch '3.3':
      Issue bpo-15392: Install idlelib/idle_test.
      http://hg.python.org/cpython/rev/e52dad892521

      New changeset 06239fe781fe by Ned Deily in branch 'default':
      Issue bpo-15392: merge from 3.3
      http://hg.python.org/cpython/rev/06239fe781fe

    28. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    teststopic-IDLEtype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions