mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-05-05 00:13:42 +03:00
test for all the different line ending characters
This commit is contained in:
parent
ee46f45b96
commit
6dc276599e
|
@ -148,6 +148,71 @@ class TestFileEps(PillowTestCase):
|
||||||
# open image with binary preview
|
# open image with binary preview
|
||||||
Image.open(file3)
|
Image.open(file3)
|
||||||
|
|
||||||
|
def _test_readline(self,t, ending):
|
||||||
|
ending = "Failure with line ending: %s" %("".join("%s" %ord(s) for s in ending))
|
||||||
|
self.assertEqual(t.readline().strip('\r\n'), 'something', ending)
|
||||||
|
self.assertEqual(t.readline().strip('\r\n'), 'else', ending)
|
||||||
|
self.assertEqual(t.readline().strip('\r\n'), 'baz', ending)
|
||||||
|
self.assertEqual(t.readline().strip('\r\n'), 'bif', ending)
|
||||||
|
|
||||||
|
def _test_readline_stringio(self, test_string, ending):
|
||||||
|
# check all the freaking line endings possible
|
||||||
|
try:
|
||||||
|
import StringIO
|
||||||
|
except:
|
||||||
|
# don't skip, it skips everything in the parent test
|
||||||
|
return
|
||||||
|
t = StringIO.StringIO(test_string)
|
||||||
|
self._test_readline(t, ending)
|
||||||
|
|
||||||
|
def _test_readline_io(self, test_string, ending):
|
||||||
|
import io
|
||||||
|
t = io.StringIO(test_string)
|
||||||
|
self._test_readline(t, ending)
|
||||||
|
|
||||||
|
def _test_readline_file_universal(self, test_string, ending):
|
||||||
|
f = self.tempfile('temp.txt')
|
||||||
|
with open(f,'wb') as w:
|
||||||
|
if str is bytes:
|
||||||
|
w.write(test_string)
|
||||||
|
else:
|
||||||
|
w.write(test_string.encode('UTF-8'))
|
||||||
|
|
||||||
|
with open(f,'rU') as t:
|
||||||
|
self._test_readline(t, ending)
|
||||||
|
|
||||||
|
def _test_readline_file_psfile(self, test_string, ending):
|
||||||
|
f = self.tempfile('temp.txt')
|
||||||
|
with open(f,'wb') as w:
|
||||||
|
if str is bytes:
|
||||||
|
w.write(test_string)
|
||||||
|
else:
|
||||||
|
w.write(test_string.encode('UTF-8'))
|
||||||
|
|
||||||
|
with open(f,'rb') as r:
|
||||||
|
t = EpsImagePlugin.PSFile(r)
|
||||||
|
self._test_readline(t, ending)
|
||||||
|
|
||||||
|
def test_readline(self):
|
||||||
|
# check all the freaking line endings possible from the spec
|
||||||
|
#test_string = u'something\r\nelse\n\rbaz\rbif\n'
|
||||||
|
line_endings = [u'\r\n', u'\n']
|
||||||
|
not_working_endings = [u'\n\r', u'\r']
|
||||||
|
strings = [u'something', u'else', u'baz', u'bif']
|
||||||
|
|
||||||
|
for ending in line_endings:
|
||||||
|
s = ending.join(strings)
|
||||||
|
self._test_readline_stringio(s, ending)
|
||||||
|
self._test_readline_io(s, ending)
|
||||||
|
self._test_readline_file_universal(s, ending)
|
||||||
|
|
||||||
|
for ending in not_working_endings:
|
||||||
|
# these only work with the PSFile, while they're in spec,
|
||||||
|
# they're not likely to be used
|
||||||
|
s = ending.join(strings)
|
||||||
|
self._test_readline_file_psfile(s, ending)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user