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

Add test.support.check_disallow_instantiation() #88154

Closed
erlend-aasland opened this issue Apr 30, 2021 · 12 comments
Closed

Add test.support.check_disallow_instantiation() #88154

erlend-aasland opened this issue Apr 30, 2021 · 12 comments
Labels
3.10 only security fixes 3.11 only security fixes tests Tests in the Lib/test dir type-feature A feature request or enhancement

Comments

@erlend-aasland
Copy link
Contributor

BPO 43988
Nosy @vstinner, @miss-islington, @erlend-aasland
PRs
  • bpo-43988: Add test.support.check_disallow_instantiation #25757
  • bpo-43988: Use check disallow instantiation helper #26392
  • bpo-43988: Document test.support.check_disallow_instantiation #26394
  • [3.10] bpo-43988: Add test.support.check_disallow_instantiation() (GH-25757) #26885
  • bpo-43988: Fix test.support.check_disallow_instantiation version added #26889
  • 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 2021-06-24.06:51:05.973>
    created_at = <Date 2021-04-30.14:12:30.488>
    labels = ['type-feature', 'tests', '3.10', '3.11']
    title = 'Add test.support.check_disallow_instantiation()'
    updated_at = <Date 2021-06-24.07:57:30.212>
    user = 'https://github.com/erlend-aasland'

    bugs.python.org fields:

    activity = <Date 2021-06-24.07:57:30.212>
    actor = 'miss-islington'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-06-24.06:51:05.973>
    closer = 'vstinner'
    components = ['Tests']
    creation = <Date 2021-04-30.14:12:30.488>
    creator = 'erlendaasland'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43988
    keywords = ['patch']
    message_count = 12.0
    messages = ['392436', '392518', '392525', '392535', '394436', '394515', '394537', '394538', '394570', '394579', '396448', '396457']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'miss-islington', 'erlendaasland']
    pr_nums = ['25757', '26392', '26394', '26885', '26889']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue43988'
    versions = ['Python 3.10', 'Python 3.11']

    @erlend-aasland
    Copy link
    Contributor Author

    See #25748 (comment):
    "What do you think of adding support.assert_disallow_instanciation(type, *args) function which would check for TypeError but also check the error message? TypeError is quite generic and it might hide a bug."

    Ref. bpo-43916.

    @erlend-aasland erlend-aasland added tests Tests in the Lib/test dir type-feature A feature request or enhancement labels Apr 30, 2021
    @vstinner
    Copy link
    Member

    You can take this issue as an opportunity to fix my typo :-)

    Lib/test/test_hashlib.py: "test_disallow_instanciation" => "test_disallow_instantiation".
    665c774#commitcomment-50235589

    There are now many tests:

    Lib/test/test_array.py: def test_disallow_instantiation(self):
    Lib/test/test_curses.py: def test_disallow_instantiation(self):
    Lib/test/test_dbm_gnu.py: def test_disallow_instantiation(self):
    Lib/test/test_embed.py: def test_disallow_instantiation(self):
    Lib/test/test_functools.py: def test_disallow_instantiation(self):
    Lib/test/test_hashlib.py: def test_disallow_instanciation(self):
    Lib/test/test_hashlib.py: def test_hash_disallow_instanciation(self):
    Lib/test/test_re.py: def test_disallow_instantiation(self):
    Lib/test/test_select.py: def test_disallow_instantiation(self):
    Lib/test/test_threading.py: def test_disallow_instantiation(self):
    Lib/test/test_unicodedata.py: def test_disallow_instantiation(self):
    Lib/test/test_zlib.py: def test_disallow_instantiation(self):

    @erlend-aasland
    Copy link
    Contributor Author

    I'll fix your typo ;) I'll include the rest of the test in the PR. I just pushed it out quickly to get a review of the solution.

    @vstinner
    Copy link
    Member

    You can keep PR 25757 to add the helper function, and then write a second PR to use it in all tests.

    @vstinner
    Copy link
    Member

    New changeset 4f72526 by Erlend Egeberg Aasland in branch 'main':
    bpo-43988: Add test.support.check_disallow_instantiation() (GH-25757)
    4f72526

    @vstinner
    Copy link
    Member

    New changeset fbff538 by Erlend Egeberg Aasland in branch 'main':
    bpo-43988: Use check disallow instantiation helper (GH-26392)
    fbff538

    @vstinner
    Copy link
    Member

    New changeset 8cec740 by Erlend Egeberg Aasland in branch 'main':
    bpo-43988: Document test.support.check_disallow_instantiation() (GH-26394)
    8cec740

    @erlend-aasland
    Copy link
    Contributor Author

    I believe we can close this now, Victor. Please reopen if you disagree :)

    @vstinner
    Copy link
    Member

    I believe we can close this now, Victor. Please reopen if you disagree :)

    I validated that all tests named "test(...)disallow(...)inst(...)" are now using support.check_disallow_instantiation().

    Lib/test/test_tcl.py might use it in:

        @support.cpython_only
        def test_new_tcl_obj(self):
            self.assertRaises(TypeError, _tkinter.Tcl_Obj)
            self.assertRaises(TypeError, _tkinter.TkttType)
            self.assertRaises(TypeError, _tkinter.TkappType)

    Serhiy suggested to write an unit test for curses.ncurses_version:
    https://bugs.python.org/issue43916#msg391936

    This work can be done in bpo-43916.

    @vstinner vstinner added the 3.11 only security fixes label May 27, 2021
    @vstinner vstinner changed the title Add test.support.assert_dissallow_instantiation Add test.support.check_disallow_instantiation() May 27, 2021
    @vstinner vstinner added the 3.11 only security fixes label May 27, 2021
    @vstinner vstinner changed the title Add test.support.assert_dissallow_instantiation Add test.support.check_disallow_instantiation() May 27, 2021
    @erlend-aasland
    Copy link
    Contributor Author

    Lib/test/test_tcl.py might use it [...]

    Absolutely.

    Serhiy suggested to write an unit test for curses.ncurses_version:
    https://bugs.python.org/issue43916#msg391936

    This work can be done in bpo-43916.

    All right.

    @erlend-aasland erlend-aasland added the 3.10 only security fixes label Jun 23, 2021
    @erlend-aasland erlend-aasland added the 3.10 only security fixes label Jun 23, 2021
    @miss-islington
    Copy link
    Contributor

    New changeset 0a3452e by Erlend Egeberg Aasland in branch '3.10':
    [3.10] bpo-43988: Add test.support.check_disallow_instantiation() (GH-25757) (GH-26885)
    0a3452e

    @miss-islington
    Copy link
    Contributor

    New changeset 9049ea5 by Erlend Egeberg Aasland in branch 'main':
    bpo-43988: Fix test.support.check_disallow_instantiation version added (GH-26889)
    9049ea5

    @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
    3.10 only security fixes 3.11 only security fixes tests Tests in the Lib/test dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants