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

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

Issue 28228: imghdr does not support pathlib
Patch Set: Created 3 years, 5 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
« Lib/imghdr.py ('K') | « Lib/imghdr.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import imghdr 1 import imghdr
2 import io 2 import io
3 import os 3 import os
4 import pathlib
4 import unittest 5 import unittest
5 import warnings 6 import warnings
6 from test.support import findfile, TESTFN, unlink 7 from test.support import findfile, TESTFN, unlink
7 8
8 TEST_FILES = ( 9 TEST_FILES = (
9 ('python.png', 'png'), 10 ('python.png', 'png'),
10 ('python.gif', 'gif'), 11 ('python.gif', 'gif'),
11 ('python.bmp', 'bmp'), 12 ('python.bmp', 'bmp'),
12 ('python.ppm', 'ppm'), 13 ('python.ppm', 'ppm'),
13 ('python.pgm', 'pgm'), 14 ('python.pgm', 'pgm'),
(...skipping 21 matching lines...) Expand all
35 with open(cls.testfile, 'rb') as stream: 36 with open(cls.testfile, 'rb') as stream:
36 cls.testdata = stream.read() 37 cls.testdata = stream.read()
37 38
38 def tearDown(self): 39 def tearDown(self):
39 unlink(TESTFN) 40 unlink(TESTFN)
40 41
41 def test_data(self): 42 def test_data(self):
42 for filename, expected in TEST_FILES: 43 for filename, expected in TEST_FILES:
43 filename = findfile(filename, subdir='imghdrdata') 44 filename = findfile(filename, subdir='imghdrdata')
44 self.assertEqual(imghdr.what(filename), expected) 45 self.assertEqual(imghdr.what(filename), expected)
46 with open(filename, 'rb') as stream:
47 self.assertEqual(imghdr.what(stream), expected)
48 with open(filename, 'rb') as stream:
49 data = stream.read()
50 self.assertEqual(imghdr.what(None, data), expected)
51 self.assertEqual(imghdr.what(None, bytearray(data)), expected)
52
53 def test_pathlike_filename(self):
54 for filename, expected in TEST_FILES:
berkerpeksag 2016/09/30 02:10:38 Since this is a new test we can, it would nice to
55 filename = findfile(filename, subdir='imghdrdata')
56 self.assertEqual(imghdr.what(pathlib.Path(filename)), expected)
45 with open(filename, 'rb') as stream: 57 with open(filename, 'rb') as stream:
storchaka 2016/09/21 10:43:04 Following lines just duplicate the above test.
46 self.assertEqual(imghdr.what(stream), expected) 58 self.assertEqual(imghdr.what(stream), expected)
47 with open(filename, 'rb') as stream: 59 with open(filename, 'rb') as stream:
48 data = stream.read() 60 data = stream.read()
49 self.assertEqual(imghdr.what(None, data), expected) 61 self.assertEqual(imghdr.what(None, data), expected)
50 self.assertEqual(imghdr.what(None, bytearray(data)), expected) 62 self.assertEqual(imghdr.what(None, bytearray(data)), expected)
51 63
52 def test_register_test(self): 64 def test_register_test(self):
53 def test_jumbo(h, file): 65 def test_jumbo(h, file):
54 if h.startswith(b'eggs'): 66 if h.startswith(b'eggs'):
55 return 'ham' 67 return 'ham'
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 136
125 def test_output_stream(self): 137 def test_output_stream(self):
126 with open(TESTFN, 'wb') as stream: 138 with open(TESTFN, 'wb') as stream:
127 stream.write(self.testdata) 139 stream.write(self.testdata)
128 stream.seek(0) 140 stream.seek(0)
129 with self.assertRaises(OSError) as cm: 141 with self.assertRaises(OSError) as cm:
130 imghdr.what(stream) 142 imghdr.what(stream)
131 143
132 if __name__ == '__main__': 144 if __name__ == '__main__':
133 unittest.main() 145 unittest.main()
OLDNEW
« Lib/imghdr.py ('K') | « Lib/imghdr.py ('k') | no next file » | no next file with comments »

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