Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(53816)

Unified Diff: Lib/test/test_imghdr.py

Issue 19990: Add unittests for imghdr module
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Lib/test/test_sundry.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/test/test_imghdr.py Mon Dec 16 00:22:15 2013 +0200
@@ -0,0 +1,50 @@
+import unittest
+from test.support import TESTFN, unlink
+import imghdr
+
+FORMATS = {
+ 'png': (b'\211PNG\r\n\032\n', ),
+ 'rgb': (b'\001\332', ),
+ 'rast': (b'\x59\xA6\x6A\x95', ),
+ 'xbm': (b'#define ', ),
+ 'bmp': (b'BM', ),
+ 'jpeg': (b'000000JFIF', b'000000Exif'),
+ 'gif': (b'GIF87a', b'GIF89a'),
+ 'tiff': (b'MM', b'II'),
+ 'pbm': (b'P1\t', b'P1\n', b'P1\r',
+ b'P4\t', b'P4\n', b'P4\r'),
+ 'pgm': (b'P2\t', b'P2\n', b'P2\r',
+ b'P5\t', b'P5\n', b'P5\r'),
+ 'ppm': (b'P3\t', b'P6\n', b'P6\r',
+ b'P6\t', b'P6\n', b'P6\r')
+}
+
vajrasky 2013/12/16 04:37:48 2 blank lines, please.
+class TestImghdr(unittest.TestCase):
+ def tearDown(self):
+ unlink(TESTFN)
+
+ def test_formats_without_file(self):
+ for format, parts in FORMATS.items():
+ for part in parts:
+ self.assertEqual(imghdr.what(None, part),
+ format)
+
+ def test_format_with_files(self):
+ for format, parts in FORMATS.items():
+ for part in parts:
+ with open(TESTFN, 'wb') as stream:
+ stream.write(part)
+ self.assertEqual(imghdr.what(TESTFN),
vajrasky 2013/12/16 04:37:48 We need one kind of test that tests the file objec
+ format)
+
+ def test_register_test(self):
+ def test_jumbo(h, file):
+ if h.startswith(b'eggs'):
+ return 'ham'
+ imghdr.tests.append(test_jumbo)
+ self.addCleanup(imghdr.tests.pop)
+
+ self.assertEqual(imghdr.what(None, b'eggs'), 'ham')
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « no previous file | Lib/test/test_sundry.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+