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

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
« no previous file with comments | « 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 27 matching lines...) Expand all
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)
45 with open(filename, 'rb') as stream: 46 with open(filename, 'rb') as stream:
46 self.assertEqual(imghdr.what(stream), expected) 47 self.assertEqual(imghdr.what(stream), expected)
47 with open(filename, 'rb') as stream: 48 with open(filename, 'rb') as stream:
48 data = stream.read() 49 data = stream.read()
49 self.assertEqual(imghdr.what(None, data), expected) 50 self.assertEqual(imghdr.what(None, data), expected)
50 self.assertEqual(imghdr.what(None, bytearray(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:
55 with self.subTest(filename=filename):
56 filename = findfile(filename, subdir='imghdrdata')
57 self.assertEqual(imghdr.what(pathlib.Path(filename)), expected)
51 58
52 def test_register_test(self): 59 def test_register_test(self):
53 def test_jumbo(h, file): 60 def test_jumbo(h, file):
54 if h.startswith(b'eggs'): 61 if h.startswith(b'eggs'):
55 return 'ham' 62 return 'ham'
56 imghdr.tests.append(test_jumbo) 63 imghdr.tests.append(test_jumbo)
57 self.addCleanup(imghdr.tests.pop) 64 self.addCleanup(imghdr.tests.pop)
58 self.assertEqual(imghdr.what(None, b'eggs'), 'ham') 65 self.assertEqual(imghdr.what(None, b'eggs'), 'ham')
59 66
60 def test_file_pos(self): 67 def test_file_pos(self):
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 131
125 def test_output_stream(self): 132 def test_output_stream(self):
126 with open(TESTFN, 'wb') as stream: 133 with open(TESTFN, 'wb') as stream:
127 stream.write(self.testdata) 134 stream.write(self.testdata)
128 stream.seek(0) 135 stream.seek(0)
129 with self.assertRaises(OSError) as cm: 136 with self.assertRaises(OSError) as cm:
130 imghdr.what(stream) 137 imghdr.what(stream)
131 138
132 if __name__ == '__main__': 139 if __name__ == '__main__':
133 unittest.main() 140 unittest.main()
OLDNEW
« no previous file with comments | « Lib/imghdr.py ('k') | no next file » | no next file with comments »

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