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

Delta Between Two Patch Sets: Lib/test/test_imghdr.py

Issue 28228: imghdr does not support pathlib
Left Patch Set: Created 3 years, 5 months ago
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/imghdr.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 import imghdr 1 import imghdr
2 import io 2 import io
3 import os 3 import os
4 import pathlib 4 import pathlib
5 import unittest 5 import unittest
6 import warnings 6 import warnings
7 from test.support import findfile, TESTFN, unlink 7 from test.support import findfile, TESTFN, unlink
8 8
9 TEST_FILES = ( 9 TEST_FILES = (
10 ('python.png', 'png'), 10 ('python.png', 'png'),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 filename = findfile(filename, subdir='imghdrdata') 44 filename = findfile(filename, subdir='imghdrdata')
45 self.assertEqual(imghdr.what(filename), expected) 45 self.assertEqual(imghdr.what(filename), expected)
46 with open(filename, 'rb') as stream: 46 with open(filename, 'rb') as stream:
47 self.assertEqual(imghdr.what(stream), expected) 47 self.assertEqual(imghdr.what(stream), expected)
48 with open(filename, 'rb') as stream: 48 with open(filename, 'rb') as stream:
49 data = stream.read() 49 data = stream.read()
50 self.assertEqual(imghdr.what(None, data), expected) 50 self.assertEqual(imghdr.what(None, data), expected)
51 self.assertEqual(imghdr.what(None, bytearray(data)), expected) 51 self.assertEqual(imghdr.what(None, bytearray(data)), expected)
52 52
53 def test_pathlike_filename(self): 53 def test_pathlike_filename(self):
54 for filename, expected in TEST_FILES: 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') 55 with self.subTest(filename=filename):
56 self.assertEqual(imghdr.what(pathlib.Path(filename)), expected) 56 filename = findfile(filename, subdir='imghdrdata')
57 with open(filename, 'rb') as stream: 57 self.assertEqual(imghdr.what(pathlib.Path(filename)), expected)
storchaka 2016/09/21 10:43:04 Following lines just duplicate the above test.
58 self.assertEqual(imghdr.what(stream), expected)
59 with open(filename, 'rb') as stream:
60 data = stream.read()
61 self.assertEqual(imghdr.what(None, data), expected)
62 self.assertEqual(imghdr.what(None, bytearray(data)), expected)
63 58
64 def test_register_test(self): 59 def test_register_test(self):
65 def test_jumbo(h, file): 60 def test_jumbo(h, file):
66 if h.startswith(b'eggs'): 61 if h.startswith(b'eggs'):
67 return 'ham' 62 return 'ham'
68 imghdr.tests.append(test_jumbo) 63 imghdr.tests.append(test_jumbo)
69 self.addCleanup(imghdr.tests.pop) 64 self.addCleanup(imghdr.tests.pop)
70 self.assertEqual(imghdr.what(None, b'eggs'), 'ham') 65 self.assertEqual(imghdr.what(None, b'eggs'), 'ham')
71 66
72 def test_file_pos(self): 67 def test_file_pos(self):
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 131
137 def test_output_stream(self): 132 def test_output_stream(self):
138 with open(TESTFN, 'wb') as stream: 133 with open(TESTFN, 'wb') as stream:
139 stream.write(self.testdata) 134 stream.write(self.testdata)
140 stream.seek(0) 135 stream.seek(0)
141 with self.assertRaises(OSError) as cm: 136 with self.assertRaises(OSError) as cm:
142 imghdr.what(stream) 137 imghdr.what(stream)
143 138
144 if __name__ == '__main__': 139 if __name__ == '__main__':
145 unittest.main() 140 unittest.main()
LEFTRIGHT

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