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

Make idlelib.macosx self-contained. #71426

Closed
terryjreedy opened this issue Jun 6, 2016 · 6 comments
Closed

Make idlelib.macosx self-contained. #71426

terryjreedy opened this issue Jun 6, 2016 · 6 comments
Assignees
Labels
topic-IDLE type-bug An unexpected behavior, bug, or error

Comments

@terryjreedy
Copy link
Member

BPO 27239
Nosy @terryjreedy
Files
  • macosx-contained.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 2016-06-10.04:18:16.406>
    created_at = <Date 2016-06-06.02:57:34.038>
    labels = ['expert-IDLE', 'type-bug']
    title = 'Make idlelib.macosx self-contained.'
    updated_at = <Date 2019-03-21.18:18:46.164>
    user = 'https://github.com/terryjreedy'

    bugs.python.org fields:

    activity = <Date 2019-03-21.18:18:46.164>
    actor = 'terry.reedy'
    assignee = 'terry.reedy'
    closed = True
    closed_date = <Date 2016-06-10.04:18:16.406>
    closer = 'terry.reedy'
    components = ['IDLE']
    creation = <Date 2016-06-06.02:57:34.038>
    creator = 'terry.reedy'
    dependencies = []
    files = ['43266']
    hgrepos = []
    issue_num = 27239
    keywords = ['patch']
    message_count = 6.0
    messages = ['267513', '267564', '267908', '267911', '268396', '268397']
    nosy_count = 1.0
    nosy_names = ['terry.reedy']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue27239'
    versions = ['Python 3.6']

    @terryjreedy
    Copy link
    Member Author

    Lib/idlelib/macosx.py:8 initializes _tk_type to None. It next defines private function _initializeTkVariantTests, which in called in setupApp and which initializes _tk_type. Then follow 4 isXyzTk functins, which "assert _tk_type is not None". This is fine for IDLE because IDLE call setupApp on startup.

    This is not fine for testing. In general, tests do not and should not call setupApp. If a test happens to exercise one of the 11 (for now) isXyzTk calls occurring outside of macosx, the assert is triggered. The test writer must then discover to import and call the supposedly private _initializeTkVariantTests.

    I would prefer instead that maxosx be more self-contained, and initialize _tk_type as needed. _initializeTkVariantTests needs a Tk instance for this line.
    ws = root.tk.call('tk', 'windowingsystem')
    I would like to wrap that with root = tkinter.Tk() and root.destroy. If that cannot be done on import, then instead of deleting the asserts, replace them with conditional calls to the initialization function.

    @terryjreedy terryjreedy self-assigned this Jun 6, 2016
    @terryjreedy terryjreedy added the type-bug An unexpected behavior, bug, or error label Jun 6, 2016
    @terryjreedy
    Copy link
    Member Author

    Here is a post-import patch with tests.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 8, 2016

    New changeset cc7f63b6847e by Terry Jan Reedy in branch 'default':
    Issue bpo-27239: idlelib.macosx.isXyzTk functions initialize as needed.
    https://hg.python.org/cpython/rev/cc7f63b6847e

    @terryjreedy
    Copy link
    Member Author

    I ran into this issue again with the test I am writing for another issue, so I pushed it as is, after testing.

    Ned, neither of the working OSX buildbots run gui tests. I am presuming that you run the test suite occasionally and will notice if test_idle fails.

    Serhiy, almost ditto, except for Zach Ware's Gentoo bot. What do you think of initializing, using a temporary Tk(), during import? Or best to leave as is?

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 12, 2016

    New changeset d8a2b6efdd4a by Terry Jan Reedy in branch 'default':
    Issue bpo-27239: Continue refactoring idlelib.macosx and adding macosx tests.
    https://hg.python.org/cpython/rev/d8a2b6efdd4a

    @terryjreedy
    Copy link
    Member Author

    Remove the now unneeded call in htest to _init_tk_type. It was tempting to leave the call for the 'efficiency' of the direct call with the available root, but there is a mental efficiency in removing it and making _init_tk_type completely an internal implementation detail of macosx.

    Remove the unneeded call in macosx.setupApp. This makes the _init_tk_type local to its section of the module. It also allows a test to set _tk_type to simulate being on a particular type of Mac and call setupApp without having the setting overwritten by the real value. Test_macosx now calls setupApp with each _tk_type set to each possible non-None value.

    The same objective could have been met by conditioning the call with 'if _tk_type is None:', but removing the call means that _init_tk_type is no longer ever called with a root, so the parameter can be removed and the function simplified. This section of macosx now takes care of initializing itself and the rest of IDLE can simply call the isTypeTk functions without worrying about initialization.

    Have macosx call its test when run as main.

    @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-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant