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 unittests for imghdr module #64189

Closed
PCManticore mannequin opened this issue Dec 15, 2013 · 15 comments
Closed

Add unittests for imghdr module #64189

PCManticore mannequin opened this issue Dec 15, 2013 · 15 comments
Assignees
Labels
tests Tests in the Lib/test dir type-feature A feature request or enhancement

Comments

@PCManticore
Copy link
Mannequin

PCManticore mannequin commented Dec 15, 2013

BPO 19990
Nosy @PCManticore, @serhiy-storchaka, @vajrasky
Files
  • test_imghdr.patch
  • test_imghdr.patch
  • test_imghdr_2.patch
  • python.exr: sample openexr file with zip16 compression
  • test_imghdr_3.patch
  • test_imghdr_4.patch
  • 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/serhiy-storchaka'
    closed_at = <Date 2014-01-26.21:56:00.212>
    created_at = <Date 2013-12-15.22:27:50.545>
    labels = ['type-feature', 'tests']
    title = 'Add unittests for imghdr module'
    updated_at = <Date 2014-02-02.22:01:31.284>
    user = 'https://github.com/PCManticore'

    bugs.python.org fields:

    activity = <Date 2014-02-02.22:01:31.284>
    actor = 'python-dev'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2014-01-26.21:56:00.212>
    closer = 'serhiy.storchaka'
    components = ['Tests']
    creation = <Date 2013-12-15.22:27:50.545>
    creator = 'Claudiu.Popa'
    dependencies = []
    files = ['33155', '33157', '33552', '33555', '33731', '33733']
    hgrepos = []
    issue_num = 19990
    keywords = ['patch']
    message_count = 15.0
    messages = ['206262', '206276', '206278', '208491', '208503', '208669', '209336', '209341', '209343', '209344', '209345', '209346', '209354', '209355', '210027']
    nosy_count = 5.0
    nosy_names = ['Claudiu.Popa', 'python-dev', 'serhiy.storchaka', 'vajrasky', 'mvignali']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue19990'
    versions = ['Python 2.7', 'Python 3.3', 'Python 3.4']

    @PCManticore
    Copy link
    Mannequin Author

    PCManticore mannequin commented Dec 15, 2013

    Hello! The following patch adds unit tests for the previously untested imghdr module.

    @PCManticore PCManticore mannequin added tests Tests in the Lib/test dir type-feature A feature request or enhancement labels Dec 15, 2013
    @vajrasky
    Copy link
    Mannequin

    vajrasky mannequin commented Dec 16, 2013

    Beside my review, I think we need one more test that tests the invalid image file, for example file with header b'cutecat'.

    @PCManticore
    Copy link
    Mannequin Author

    PCManticore mannequin commented Dec 16, 2013

    Thanks for the review, Vajrasky! Here's the updated version.

    @PCManticore
    Copy link
    Mannequin Author

    PCManticore mannequin commented Jan 19, 2014

    Hello. Here's a new version which uses real image files as testing data.

    @mvignali
    Copy link
    Mannequin

    mvignali mannequin commented Jan 19, 2014

    I made a simple exr file with the lib Exr (it's a half float ZIP16 RGBA file), in order to add real exr file to the unit test.
    When use with the patch i made here http://bugs.python.org/issue20295 ,
    this sample file return 'exr'.

    Sorry, i don't know how to create an update version of your patch (i just start to use mercurial), so i just upload the sample.

    @serhiy-storchaka
    Copy link
    Member

    In general the patch LGTM, but additional tests can be added.

    Needed various tests for imghdr.what() arguments:

    • First argument is bytes, int or None.
    • First argument is a name of non-existent file.
    • First argument is text stream.
    • First argument is output stream.
    • First argument is closed stream.
    • First argument is non-seekable stream.
    • Second argument is bytearray.
    • Second argument is str.
    • Second argument is None.

    Try to insert test function which handles one of already supported format at the front of imghdr.test.

    @serhiy-storchaka serhiy-storchaka self-assigned this Jan 21, 2014
    @PCManticore
    Copy link
    Mannequin Author

    PCManticore mannequin commented Jan 26, 2014

    Hello! Here's the new version of the patch, with tests proposed by Serhiy.

    @serhiy-storchaka
    Copy link
    Member

    Looks as you forgot to include some test files in the patch.

    And these files are too large. Much smaller images would be enough. For example you can use python.org icon: http://www.python.org/favicon.ico.

    @PCManticore
    Copy link
    Mannequin Author

    PCManticore mannequin commented Jan 26, 2014

    Here's a smaller patch. Serhiy, what test files are missing?

    @serhiy-storchaka
    Copy link
    Member

    Last patch contains only pbm and xbm test files, while test_imghdr expects 11 different image files: png, gif, bmp, etc.

    @PCManticore
    Copy link
    Mannequin Author

    PCManticore mannequin commented Jan 26, 2014

    Ah, I understand now. Maybe it is related to the fact that I used hg diff --git? Doing the following works for me, both Windows and FreeBsd and all the files are present afterwards:

    1. hg diff --git > patch
    2. hg import --no-commit patch

    Although I'm not sure why it doesn't work in your case.

    @serhiy-storchaka
    Copy link
    Member

    Oh, yes, my bad. I used the patch utility. Sorry.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 26, 2014

    New changeset b28909d501c0 by Serhiy Storchaka in branch '2.7':
    Issue bpo-19990: Added tests for the imghdr module.
    http://hg.python.org/cpython/rev/b28909d501c0

    New changeset fde9e9832749 by Serhiy Storchaka in branch '3.3':
    Issue bpo-19990: Added tests for the imghdr module.
    http://hg.python.org/cpython/rev/fde9e9832749

    New changeset 94813eab5a58 by Serhiy Storchaka in branch 'default':
    Issue bpo-19990: Added tests for the imghdr module.
    http://hg.python.org/cpython/rev/94813eab5a58

    @serhiy-storchaka
    Copy link
    Member

    Thank you Claudiu.

    I have reorganized tests somewhat and added new test for file position.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 2, 2014

    New changeset e2d013e90e88 by Ned Deily in branch '2.7':
    Issue bpo-19990: Install test/imghdrdata.
    http://hg.python.org/cpython/rev/e2d013e90e88

    New changeset 5fbe155e62b0 by Ned Deily in branch '3.3':
    Issue bpo-19990: Install test/imghdrdata.
    http://hg.python.org/cpython/rev/5fbe155e62b0

    New changeset b41ba99a276c by Ned Deily in branch 'default':
    Issue bpo-19990: Install test/imghdrdata.
    http://hg.python.org/cpython/rev/b41ba99a276c

    @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

    1 participant