Title: Add unittests for imghdr module
Type: enhancement Stage: resolved
Components: Tests Versions: Python 3.3, Python 3.4, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: Claudiu.Popa, mvignali, python-dev, serhiy.storchaka, vajrasky
Priority: normal Keywords: patch

Created on 2013-12-15 22:27 by Claudiu.Popa, last changed 2014-02-02 22:01 by python-dev. This issue is now closed.

File name Uploaded Description Edit
test_imghdr.patch Claudiu.Popa, 2013-12-15 22:27 review
test_imghdr.patch Claudiu.Popa, 2013-12-16 07:55 review
test_imghdr_2.patch Claudiu.Popa, 2014-01-19 18:43 review
python.exr mvignali, 2014-01-19 22:04 sample openexr file with zip16 compression
test_imghdr_3.patch Claudiu.Popa, 2014-01-26 16:27 review
test_imghdr_4.patch Claudiu.Popa, 2014-01-26 19:07 review
Messages (15)
msg206262 - (view) Author: Claudiu Popa (Claudiu.Popa) * Date: 2013-12-15 22:27
Hello! The following patch adds unit tests for the previously untested `imghdr` module.
msg206276 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013-12-16 03:38
Beside my review, I think we need one more test that tests the invalid image file, for example file with header b'cutecat'.
msg206278 - (view) Author: Claudiu Popa (Claudiu.Popa) * Date: 2013-12-16 07:55
Thanks for the review, Vajrasky! Here's the updated version.
msg208491 - (view) Author: Claudiu Popa (Claudiu.Popa) * Date: 2014-01-19 18:43
Hello. Here's a new version which uses real image files as testing data.
msg208503 - (view) Author: Martin Vignali (mvignali) Date: 2014-01-19 22:04
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 ,
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.
msg208669 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-01-21 16:44
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.
msg209336 - (view) Author: Claudiu Popa (Claudiu.Popa) * Date: 2014-01-26 16:27
Hello! Here's the new version of the patch, with tests proposed by Serhiy.
msg209341 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-01-26 18:31
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 icon:
msg209343 - (view) Author: Claudiu Popa (Claudiu.Popa) * Date: 2014-01-26 19:07
Here's a smaller patch. Serhiy, what test files are missing?
msg209344 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-01-26 19:24
Last patch contains only pbm and xbm test files, while test_imghdr expects 11 different image files: png, gif, bmp, etc.
msg209345 - (view) Author: Claudiu Popa (Claudiu.Popa) * Date: 2014-01-26 19:30
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.
msg209346 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-01-26 19:46
Oh, yes, my bad. I used the patch utility. Sorry.
msg209354 - (view) Author: Roundup Robot (python-dev) Date: 2014-01-26 21:53
New changeset b28909d501c0 by Serhiy Storchaka in branch '2.7':
Issue #19990: Added tests for the imghdr module.

New changeset fde9e9832749 by Serhiy Storchaka in branch '3.3':
Issue #19990: Added tests for the imghdr module.

New changeset 94813eab5a58 by Serhiy Storchaka in branch 'default':
Issue #19990: Added tests for the imghdr module.
msg209355 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-01-26 21:56
Thank you Claudiu.

I have reorganized tests somewhat and added new test for file position.
msg210027 - (view) Author: Roundup Robot (python-dev) Date: 2014-02-02 22:01
New changeset e2d013e90e88 by Ned Deily in branch '2.7':
Issue #19990: Install test/imghdrdata.

New changeset 5fbe155e62b0 by Ned Deily in branch '3.3':
Issue #19990: Install test/imghdrdata.

New changeset b41ba99a276c by Ned Deily in branch 'default':
Issue #19990: Install test/imghdrdata.
Date User Action Args
2014-02-02 22:01:31python-devsetmessages: + msg210027
2014-01-26 21:56:00serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg209355

stage: patch review -> resolved
2014-01-26 21:53:55python-devsetnosy: + python-dev
messages: + msg209354
2014-01-26 19:46:02serhiy.storchakasetmessages: + msg209346
2014-01-26 19:30:02Claudiu.Popasetmessages: + msg209345
2014-01-26 19:24:02serhiy.storchakasetmessages: + msg209344
2014-01-26 19:08:00Claudiu.Popasetfiles: + test_imghdr_4.patch

messages: + msg209343
2014-01-26 18:31:51serhiy.storchakasetmessages: + msg209341
2014-01-26 16:27:49Claudiu.Popasetfiles: + test_imghdr_3.patch

messages: + msg209336
2014-01-21 16:44:48serhiy.storchakasetversions: + Python 2.7, Python 3.3
nosy: + serhiy.storchaka

messages: + msg208669

assignee: serhiy.storchaka
stage: patch review
2014-01-19 22:04:01mvignalisetfiles: + python.exr
nosy: + mvignali
messages: + msg208503

2014-01-19 18:43:50Claudiu.Popasetfiles: + test_imghdr_2.patch

messages: + msg208491
2013-12-19 16:56:41vstinnerlinkissue19997 dependencies
2013-12-16 07:55:02Claudiu.Popasetfiles: + test_imghdr.patch

messages: + msg206278
2013-12-16 03:38:39vajraskysetnosy: + vajrasky
messages: + msg206276
2013-12-15 22:27:50Claudiu.Popacreate