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

Side by Side Diff: Lib/test/test_imghdr.py

Issue 19990: Add unittests for imghdr module
Patch Set: Created 5 years, 9 months ago
Left:
Right:
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 unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/test_sundry.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 import unittest
2 from test.support import TESTFN, unlink
3 import imghdr
4
5 FORMATS = {
6 'png': (b'\211PNG\r\n\032\n', ),
7 'rgb': (b'\001\332', ),
8 'rast': (b'\x59\xA6\x6A\x95', ),
9 'xbm': (b'#define ', ),
10 'bmp': (b'BM', ),
11 'jpeg': (b'000000JFIF', b'000000Exif'),
12 'gif': (b'GIF87a', b'GIF89a'),
13 'tiff': (b'MM', b'II'),
14 'pbm': (b'P1\t', b'P1\n', b'P1\r',
15 b'P4\t', b'P4\n', b'P4\r'),
16 'pgm': (b'P2\t', b'P2\n', b'P2\r',
17 b'P5\t', b'P5\n', b'P5\r'),
18 'ppm': (b'P3\t', b'P6\n', b'P6\r',
19 b'P6\t', b'P6\n', b'P6\r')
20 }
21
vajrasky 2013/12/16 04:37:48 2 blank lines, please.
22 class TestImghdr(unittest.TestCase):
23 def tearDown(self):
24 unlink(TESTFN)
25
26 def test_formats_without_file(self):
27 for format, parts in FORMATS.items():
28 for part in parts:
29 self.assertEqual(imghdr.what(None, part),
30 format)
31
32 def test_format_with_files(self):
33 for format, parts in FORMATS.items():
34 for part in parts:
35 with open(TESTFN, 'wb') as stream:
36 stream.write(part)
37 self.assertEqual(imghdr.what(TESTFN),
vajrasky 2013/12/16 04:37:48 We need one kind of test that tests the file objec
38 format)
39
40 def test_register_test(self):
41 def test_jumbo(h, file):
42 if h.startswith(b'eggs'):
43 return 'ham'
44 imghdr.tests.append(test_jumbo)
45 self.addCleanup(imghdr.tests.pop)
46
47 self.assertEqual(imghdr.what(None, b'eggs'), 'ham')
48
49 if __name__ == '__main__':
50 unittest.main()
OLDNEW
« 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+