mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 17:24:31 +03:00
Changed Python version checks in tests to use helper
This commit is contained in:
parent
48c8f1f219
commit
b560f5b417
|
@ -2,10 +2,11 @@
|
|||
# Run from anywhere that PIL is importable.
|
||||
|
||||
from PIL import Image
|
||||
from helper import py3
|
||||
from io import BytesIO
|
||||
|
||||
if bytes is str:
|
||||
Image.open(BytesIO(bytes('icns\x00\x00\x00\x10hang\x00\x00\x00\x00')))
|
||||
else:
|
||||
if py3:
|
||||
Image.open(BytesIO(bytes('icns\x00\x00\x00\x10hang\x00\x00\x00\x00',
|
||||
'latin-1')))
|
||||
else:
|
||||
Image.open(BytesIO(bytes('icns\x00\x00\x00\x10hang\x00\x00\x00\x00')))
|
||||
|
|
|
@ -2,12 +2,14 @@
|
|||
# Run from anywhere that PIL is importable.
|
||||
|
||||
from PIL import Image
|
||||
from helper import py3
|
||||
from io import BytesIO
|
||||
|
||||
if bytes is str:
|
||||
Image.open(BytesIO(bytes(
|
||||
'\x00\x00\x00\x0cjP\x20\x20\x0d\x0a\x87\x0a\x00\x00\x00\x00hang')))
|
||||
else:
|
||||
if py3:
|
||||
Image.open(BytesIO(bytes(
|
||||
'\x00\x00\x00\x0cjP\x20\x20\x0d\x0a\x87\x0a\x00\x00\x00\x00hang',
|
||||
'latin-1')))
|
||||
|
||||
else:
|
||||
Image.open(BytesIO(bytes(
|
||||
'\x00\x00\x00\x0cjP\x20\x20\x0d\x0a\x87\x0a\x00\x00\x00\x00hang')))
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from helper import unittest, PillowTestCase, hopper
|
||||
from helper import unittest, PillowTestCase, hopper, py3
|
||||
|
||||
from PIL import Image, EpsImagePlugin
|
||||
import io
|
||||
|
@ -206,19 +206,19 @@ class TestFileEps(PillowTestCase):
|
|||
self._test_readline(t, ending)
|
||||
|
||||
def _test_readline_io(self, test_string, ending):
|
||||
if str is bytes:
|
||||
t = io.StringIO(unicode(test_string))
|
||||
else:
|
||||
if py3:
|
||||
t = io.StringIO(test_string)
|
||||
else:
|
||||
t = io.StringIO(unicode(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:
|
||||
if py3:
|
||||
w.write(test_string.encode('UTF-8'))
|
||||
else:
|
||||
w.write(test_string)
|
||||
|
||||
with open(f, 'rU') as t:
|
||||
self._test_readline(t, ending)
|
||||
|
@ -226,10 +226,10 @@ class TestFileEps(PillowTestCase):
|
|||
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:
|
||||
if py3:
|
||||
w.write(test_string.encode('UTF-8'))
|
||||
else:
|
||||
w.write(test_string)
|
||||
|
||||
with open(f, 'rb') as r:
|
||||
t = EpsImagePlugin.PSFile(r)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from helper import unittest, PillowTestCase, PillowLeakTestCase, hopper
|
||||
from helper import unittest, PillowTestCase, PillowLeakTestCase, hopper, py3
|
||||
from PIL import Image, ImageFile, PngImagePlugin
|
||||
|
||||
from io import BytesIO
|
||||
|
@ -419,7 +419,7 @@ class TestFilePng(PillowTestCase):
|
|||
im = roundtrip(im, pnginfo=info)
|
||||
self.assertEqual(im.info, {"Text": value})
|
||||
|
||||
if str is not bytes:
|
||||
if py3:
|
||||
rt_text(" Aa" + chr(0xa0) + chr(0xc4) + chr(0xff)) # Latin1
|
||||
rt_text(chr(0x400) + chr(0x472) + chr(0x4ff)) # Cyrillic
|
||||
rt_text(chr(0x4e00) + chr(0x66f0) + # CJK
|
||||
|
|
|
@ -2,6 +2,7 @@ from helper import unittest, PillowTestCase
|
|||
|
||||
from PIL import Image, FontFile, PcfFontFile
|
||||
from PIL import ImageFont, ImageDraw
|
||||
from helper import py3
|
||||
|
||||
codecs = dir(Image.core)
|
||||
|
||||
|
@ -76,7 +77,7 @@ class TestFontPcf(PillowTestCase):
|
|||
message = "".join(chr(i+1) for i in range(140, 232))
|
||||
self._test_high_characters(message)
|
||||
# accept bytes instances in Py3.
|
||||
if bytes is not str:
|
||||
if py3:
|
||||
self._test_high_characters(message.encode('latin1'))
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from helper import unittest, PillowTestCase, hopper
|
||||
from helper import unittest, PillowTestCase, hopper, py3
|
||||
|
||||
from PIL import Image
|
||||
|
||||
|
@ -57,10 +57,10 @@ class TestFormatHSV(PillowTestCase):
|
|||
|
||||
(r, g, b) = im.split()
|
||||
|
||||
if bytes is str:
|
||||
conv_func = self.str_to_float
|
||||
else:
|
||||
if py3:
|
||||
conv_func = self.int_to_float
|
||||
else:
|
||||
conv_func = self.str_to_float
|
||||
|
||||
if hasattr(itertools, 'izip'):
|
||||
iter_helper = itertools.izip
|
||||
|
@ -72,11 +72,11 @@ class TestFormatHSV(PillowTestCase):
|
|||
for (_r, _g, _b) in iter_helper(r.tobytes(), g.tobytes(),
|
||||
b.tobytes())]
|
||||
|
||||
if str is bytes:
|
||||
new_bytes = b''.join(chr(h)+chr(s)+chr(v) for (
|
||||
if py3:
|
||||
new_bytes = b''.join(bytes(chr(h)+chr(s)+chr(v), 'latin-1') for (
|
||||
h, s, v) in converted)
|
||||
else:
|
||||
new_bytes = b''.join(bytes(chr(h)+chr(s)+chr(v), 'latin-1') for (
|
||||
new_bytes = b''.join(chr(h)+chr(s)+chr(v) for (
|
||||
h, s, v) in converted)
|
||||
|
||||
hsv = Image.frombytes(mode, r.size, new_bytes)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from helper import unittest, PillowTestCase, hopper
|
||||
from helper import unittest, PillowTestCase, hopper, py3
|
||||
|
||||
from PIL import Image
|
||||
import os
|
||||
|
@ -60,12 +60,12 @@ class TestImage(PillowTestCase):
|
|||
self.assertEqual(im.height, 4)
|
||||
|
||||
def test_invalid_image(self):
|
||||
if str is bytes:
|
||||
import StringIO
|
||||
im = StringIO.StringIO('')
|
||||
else:
|
||||
if py3:
|
||||
import io
|
||||
im = io.BytesIO(b'')
|
||||
else:
|
||||
import StringIO
|
||||
im = StringIO.StringIO('')
|
||||
self.assertRaises(IOError, Image.open, im)
|
||||
|
||||
def test_bad_mode(self):
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
from helper import unittest, PillowTestCase, py3
|
||||
|
||||
from PIL import ImagePath, Image
|
||||
|
||||
|
@ -77,10 +77,10 @@ class TestImagePath(PillowTestCase):
|
|||
# This fails due to the invalid malloc above,
|
||||
# and segfaults
|
||||
for i in range(200000):
|
||||
if str is bytes:
|
||||
x[i] = "0"*16
|
||||
else:
|
||||
if py3:
|
||||
x[i] = b'0'*16
|
||||
else:
|
||||
x[i] = "0"*16
|
||||
|
||||
|
||||
class evil:
|
||||
|
|
Loading…
Reference in New Issue
Block a user