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

test_argparse.py: use new unittest features #53763

Closed
denversc mannequin opened this issue Aug 10, 2010 · 12 comments
Closed

test_argparse.py: use new unittest features #53763

denversc mannequin opened this issue Aug 10, 2010 · 12 comments
Assignees
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement

Comments

@denversc
Copy link
Mannequin

denversc mannequin commented Aug 10, 2010

BPO 9554
Nosy @ericvsmith, @benjaminp, @ezio-melotti, @merwok, @bitdancer, @sandrotosi, @berkerpeksag, @serhiy-storchaka
Files
  • test_argparse.py.unittest2.patch: Suggested Patch
  • test_argparse.py.take2
  • issue9554_v2.diff
  • issue9554_v3.diff
  • issue9554_v4.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/berkerpeksag'
    closed_at = <Date 2014-07-06.06:34:49.778>
    created_at = <Date 2010-08-10.02:53:45.510>
    labels = ['type-feature', 'tests']
    title = 'test_argparse.py: use new unittest features'
    updated_at = <Date 2014-07-06.06:34:49.777>
    user = 'https://bugs.python.org/denversc'

    bugs.python.org fields:

    activity = <Date 2014-07-06.06:34:49.777>
    actor = 'berker.peksag'
    assignee = 'berker.peksag'
    closed = True
    closed_date = <Date 2014-07-06.06:34:49.778>
    closer = 'berker.peksag'
    components = ['Tests']
    creation = <Date 2010-08-10.02:53:45.510>
    creator = 'denversc'
    dependencies = []
    files = ['18464', '25659', '35809', '35852', '35869']
    hgrepos = []
    issue_num = 9554
    keywords = ['patch']
    message_count = 12.0
    messages = ['113505', '113513', '125314', '161233', '161247', '161249', '179048', '221910', '222002', '222277', '222396', '222397']
    nosy_count = 13.0
    nosy_names = ['bethard', 'eric.smith', 'benjamin.peterson', 'ezio.melotti', 'eric.araujo', 'r.david.murray', 'sandro.tosi', 'BreamoreBoy', 'denversc', 'python-dev', 'berker.peksag', 'serhiy.storchaka', 'raduv']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue9554'
    versions = ['Python 3.5']

    @denversc
    Copy link
    Mannequin Author

    denversc mannequin commented Aug 10, 2010

    Some of the unit testing code in test_argparse.py could be modified to take advantage of the new unittest features in Python 2.7 and 3.x. My suggested changes are attached in the patch file test_argparse.py.unittest2.patch

    One big one is that assertEquals() now prints a "diff" when multi-line strings compare unequal, so the manual "diffing" logic from the unit tests can be removed. Also, assertIsNone() is slightly better than assertEquals(None, x). Finally, there is a tiny fix where parse_args() was expected to throw ArgumentParserError but the test would not fail if it threw no exceptions.

    @denversc denversc mannequin added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Aug 10, 2010
    @bethard
    Copy link
    Mannequin

    bethard mannequin commented Aug 10, 2010

    These all look like good changes to me. (I looked at the patch, but haven't tried applying it though.)

    @sandrotosi
    Copy link
    Contributor

    Hi, I've applied the patch and it goes fine (except for some offsets and the fact it was generated inside Lib/test) and the tests are still all ok. I'd suggest to apply it.

    @raduv
    Copy link
    Mannequin

    raduv mannequin commented May 20, 2012

    The patch is still valid - it applies ok. The only issues as mentioned by sandro.tosi are offsets and that it was generated inside Lib/

    It would be worth having these changes applied.

    @merwok
    Copy link
    Member

    merwok commented May 21, 2012

    Another one:

             except ArgumentParserError:
                 err = sys.exc_info()[1]

    This reeks of single-codebase-for-2.x-and-3.x and could probably be replaced by assertRaises or at least a regular except...as.

    @raduv
    Copy link
    Mannequin

    raduv mannequin commented May 21, 2012

    Hi Eric, Denver's patch should apply correctly from the root. Also, I've made the changes you mention:

    try: except: assert

    has been replaced by:

    with self.assertRaises()

    @serhiy-storchaka
    Copy link
    Member

    See also bpo-16510.

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jun 29, 2014

    Latest patch LGTM so can we have a commit review please.

    @berkerpeksag
    Copy link
    Member

    Updated patch to use assertRaisesRegex in test_invalid_action, test_multiple_dest

    @berkerpeksag
    Copy link
    Member

    Updated patch.

    @berkerpeksag berkerpeksag added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Jul 4, 2014
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 6, 2014

    New changeset f240ca6345c8 by Berker Peksag in branch 'default':
    Issue bpo-9554: Use modern unittest features in test_argparse.
    http://hg.python.org/cpython/rev/f240ca6345c8

    @berkerpeksag
    Copy link
    Member

    Thanks Denver and Radu. And thanks for the review, Ezio.

    @berkerpeksag berkerpeksag self-assigned this Jul 6, 2014
    @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 type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants