mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
Merge pull request #3087 from hugovk/rm-deprecationwarnings
Remove deprecation warnings
This commit is contained in:
commit
c013188594
|
@ -267,6 +267,11 @@ class PillowLeakTestCase(PillowTestCase):
|
|||
|
||||
py3 = sys.version_info.major >= 3
|
||||
|
||||
if not py3:
|
||||
# Remove DeprecationWarning in Python 3
|
||||
PillowTestCase.assertRaisesRegex = PillowTestCase.assertRaisesRegexp
|
||||
PillowTestCase.assertRegex = PillowTestCase.assertRegexpMatches
|
||||
|
||||
|
||||
def fromstring(data):
|
||||
from io import BytesIO
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
|
||||
from PIL import Image, ImageOps
|
||||
from PIL import Image, ImageFilter
|
||||
|
||||
|
||||
sample = Image.new("L", (7, 5))
|
||||
|
@ -16,7 +16,7 @@ sample.putdata(sum([
|
|||
class TestBoxBlurApi(PillowTestCase):
|
||||
|
||||
def test_imageops_box_blur(self):
|
||||
i = ImageOps.box_blur(sample, 1)
|
||||
i = sample.filter(ImageFilter.BoxBlur(1))
|
||||
self.assertEqual(i.mode, sample.mode)
|
||||
self.assertEqual(i.size, sample.size)
|
||||
self.assertIsInstance(i, Image.Image)
|
||||
|
|
|
@ -32,39 +32,39 @@ class TestColorLut3DCoreAPI(PillowTestCase):
|
|||
def test_wrong_args(self):
|
||||
im = Image.new('RGB', (10, 10), 0)
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "filter"):
|
||||
with self.assertRaisesRegex(ValueError, "filter"):
|
||||
im.im.color_lut_3d('RGB', Image.CUBIC,
|
||||
*self.generate_identity_table(3, 3))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "image mode"):
|
||||
with self.assertRaisesRegex(ValueError, "image mode"):
|
||||
im.im.color_lut_3d('wrong', Image.LINEAR,
|
||||
*self.generate_identity_table(3, 3))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "table_channels"):
|
||||
with self.assertRaisesRegex(ValueError, "table_channels"):
|
||||
im.im.color_lut_3d('RGB', Image.LINEAR,
|
||||
*self.generate_identity_table(5, 3))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "table_channels"):
|
||||
with self.assertRaisesRegex(ValueError, "table_channels"):
|
||||
im.im.color_lut_3d('RGB', Image.LINEAR,
|
||||
*self.generate_identity_table(1, 3))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "table_channels"):
|
||||
with self.assertRaisesRegex(ValueError, "table_channels"):
|
||||
im.im.color_lut_3d('RGB', Image.LINEAR,
|
||||
*self.generate_identity_table(2, 3))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "Table size"):
|
||||
with self.assertRaisesRegex(ValueError, "Table size"):
|
||||
im.im.color_lut_3d('RGB', Image.LINEAR,
|
||||
*self.generate_identity_table(3, (1, 3, 3)))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "Table size"):
|
||||
with self.assertRaisesRegex(ValueError, "Table size"):
|
||||
im.im.color_lut_3d('RGB', Image.LINEAR,
|
||||
*self.generate_identity_table(3, (66, 3, 3)))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, r"size1D \* size2D \* size3D"):
|
||||
with self.assertRaisesRegex(ValueError, r"size1D \* size2D \* size3D"):
|
||||
im.im.color_lut_3d('RGB', Image.LINEAR,
|
||||
3, 2, 2, 2, [0, 0, 0] * 7)
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, r"size1D \* size2D \* size3D"):
|
||||
with self.assertRaisesRegex(ValueError, r"size1D \* size2D \* size3D"):
|
||||
im.im.color_lut_3d('RGB', Image.LINEAR,
|
||||
3, 2, 2, 2, [0, 0, 0] * 9)
|
||||
|
||||
|
@ -98,27 +98,27 @@ class TestColorLut3DCoreAPI(PillowTestCase):
|
|||
*self.generate_identity_table(3, (3, 3, 65)))
|
||||
|
||||
def test_wrong_mode(self):
|
||||
with self.assertRaisesRegexp(ValueError, "wrong mode"):
|
||||
with self.assertRaisesRegex(ValueError, "wrong mode"):
|
||||
im = Image.new('L', (10, 10), 0)
|
||||
im.im.color_lut_3d('RGB', Image.LINEAR,
|
||||
*self.generate_identity_table(3, 3))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "wrong mode"):
|
||||
with self.assertRaisesRegex(ValueError, "wrong mode"):
|
||||
im = Image.new('RGB', (10, 10), 0)
|
||||
im.im.color_lut_3d('L', Image.LINEAR,
|
||||
*self.generate_identity_table(3, 3))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "wrong mode"):
|
||||
with self.assertRaisesRegex(ValueError, "wrong mode"):
|
||||
im = Image.new('L', (10, 10), 0)
|
||||
im.im.color_lut_3d('L', Image.LINEAR,
|
||||
*self.generate_identity_table(3, 3))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "wrong mode"):
|
||||
with self.assertRaisesRegex(ValueError, "wrong mode"):
|
||||
im = Image.new('RGB', (10, 10), 0)
|
||||
im.im.color_lut_3d('RGBA', Image.LINEAR,
|
||||
*self.generate_identity_table(3, 3))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "wrong mode"):
|
||||
with self.assertRaisesRegex(ValueError, "wrong mode"):
|
||||
im = Image.new('RGB', (10, 10), 0)
|
||||
im.im.color_lut_3d('RGB', Image.LINEAR,
|
||||
*self.generate_identity_table(4, 3))
|
||||
|
@ -238,31 +238,31 @@ class TestColorLut3DCoreAPI(PillowTestCase):
|
|||
|
||||
class TestColorLut3DFilter(PillowTestCase):
|
||||
def test_wrong_args(self):
|
||||
with self.assertRaisesRegexp(ValueError, "should be either an integer"):
|
||||
with self.assertRaisesRegex(ValueError, "should be either an integer"):
|
||||
ImageFilter.Color3DLUT("small", [1])
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "should be either an integer"):
|
||||
with self.assertRaisesRegex(ValueError, "should be either an integer"):
|
||||
ImageFilter.Color3DLUT((11, 11), [1])
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, r"in \[2, 65\] range"):
|
||||
with self.assertRaisesRegex(ValueError, r"in \[2, 65\] range"):
|
||||
ImageFilter.Color3DLUT((11, 11, 1), [1])
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, r"in \[2, 65\] range"):
|
||||
with self.assertRaisesRegex(ValueError, r"in \[2, 65\] range"):
|
||||
ImageFilter.Color3DLUT((11, 11, 66), [1])
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "table should have .+ items"):
|
||||
with self.assertRaisesRegex(ValueError, "table should have .+ items"):
|
||||
ImageFilter.Color3DLUT((3, 3, 3), [1, 1, 1])
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "table should have .+ items"):
|
||||
with self.assertRaisesRegex(ValueError, "table should have .+ items"):
|
||||
ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 2)
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "should have a length of 4"):
|
||||
with self.assertRaisesRegex(ValueError, "should have a length of 4"):
|
||||
ImageFilter.Color3DLUT((3, 3, 3), [[1, 1, 1]] * 27, channels=4)
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "should have a length of 3"):
|
||||
with self.assertRaisesRegex(ValueError, "should have a length of 3"):
|
||||
ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "Only 3 or 4 output"):
|
||||
with self.assertRaisesRegex(ValueError, "Only 3 or 4 output"):
|
||||
ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8, channels=2)
|
||||
|
||||
def test_convert_table(self):
|
||||
|
@ -290,16 +290,17 @@ class TestColorLut3DFilter(PillowTestCase):
|
|||
self.assertEqual(repr(lut),
|
||||
"<Color3DLUT from array size=3x4x5 channels=4 target_mode=YCbCr>")
|
||||
|
||||
|
||||
class TestGenerateColorLut3D(PillowTestCase):
|
||||
def test_wrong_channels_count(self):
|
||||
with self.assertRaisesRegexp(ValueError, "3 or 4 output channels"):
|
||||
with self.assertRaisesRegex(ValueError, "3 or 4 output channels"):
|
||||
ImageFilter.Color3DLUT.generate(5, channels=2,
|
||||
callback=lambda r, g, b: (r, g, b))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "should have either channels"):
|
||||
with self.assertRaisesRegex(ValueError, "should have either channels"):
|
||||
ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b, r))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "should have either channels"):
|
||||
with self.assertRaisesRegex(ValueError, "should have either channels"):
|
||||
ImageFilter.Color3DLUT.generate(5, channels=4,
|
||||
callback=lambda r, g, b: (r, g, b))
|
||||
|
||||
|
@ -333,13 +334,13 @@ class TestTransformColorLut3D(PillowTestCase):
|
|||
def test_wrong_args(self):
|
||||
source = ImageFilter.Color3DLUT.generate(5, lambda r, g, b: (r, g, b))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "Only 3 or 4 output"):
|
||||
with self.assertRaisesRegex(ValueError, "Only 3 or 4 output"):
|
||||
source.transform(lambda r, g, b: (r, g, b), channels=8)
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "should have either channels"):
|
||||
with self.assertRaisesRegex(ValueError, "should have either channels"):
|
||||
source.transform(lambda r, g, b: (r, g, b), channels=4)
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "should have either channels"):
|
||||
with self.assertRaisesRegex(ValueError, "should have either channels"):
|
||||
source.transform(lambda r, g, b: (r, g, b, 1))
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
|
|
|
@ -41,7 +41,7 @@ class TestFileJpeg(PillowTestCase):
|
|||
def test_sanity(self):
|
||||
|
||||
# internal version number
|
||||
self.assertRegexpMatches(Image.core.jpeglib_version, r"\d+\.\d+$")
|
||||
self.assertRegex(Image.core.jpeglib_version, r"\d+\.\d+$")
|
||||
|
||||
im = Image.open(TEST_FILE)
|
||||
im.load()
|
||||
|
|
|
@ -31,7 +31,7 @@ class TestFileJpeg2k(PillowTestCase):
|
|||
|
||||
def test_sanity(self):
|
||||
# Internal version number
|
||||
self.assertRegexpMatches(Image.core.jp2klib_version, r'\d+\.\d+\.\d+$')
|
||||
self.assertRegex(Image.core.jp2klib_version, r'\d+\.\d+\.\d+$')
|
||||
|
||||
im = Image.open('Tests/images/test-card-lossless.jp2')
|
||||
px = im.load()
|
||||
|
|
|
@ -68,8 +68,7 @@ class TestFilePng(PillowTestCase):
|
|||
def test_sanity(self):
|
||||
|
||||
# internal version number
|
||||
self.assertRegexpMatches(
|
||||
Image.core.zlib_version, r"\d+\.\d+\.\d+(\.\d+)?$")
|
||||
self.assertRegex(Image.core.zlib_version, r"\d+\.\d+\.\d+(\.\d+)?$")
|
||||
|
||||
test_file = self.tempfile("temp.png")
|
||||
|
||||
|
|
|
@ -383,24 +383,24 @@ class CoreResampleBoxTest(PillowTestCase):
|
|||
im.resize((32, 32), resample, (20, 20, 20, 100))
|
||||
im.resize((32, 32), resample, (20, 20, 100, 20))
|
||||
|
||||
with self.assertRaisesRegexp(TypeError, "must be sequence of length 4"):
|
||||
with self.assertRaisesRegex(TypeError, "must be sequence of length 4"):
|
||||
im.resize((32, 32), resample, (im.width, im.height))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "can't be negative"):
|
||||
with self.assertRaisesRegex(ValueError, "can't be negative"):
|
||||
im.resize((32, 32), resample, (-20, 20, 100, 100))
|
||||
with self.assertRaisesRegexp(ValueError, "can't be negative"):
|
||||
with self.assertRaisesRegex(ValueError, "can't be negative"):
|
||||
im.resize((32, 32), resample, (20, -20, 100, 100))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "can't be empty"):
|
||||
with self.assertRaisesRegex(ValueError, "can't be empty"):
|
||||
im.resize((32, 32), resample, (20.1, 20, 20, 100))
|
||||
with self.assertRaisesRegexp(ValueError, "can't be empty"):
|
||||
with self.assertRaisesRegex(ValueError, "can't be empty"):
|
||||
im.resize((32, 32), resample, (20, 20.1, 100, 20))
|
||||
with self.assertRaisesRegexp(ValueError, "can't be empty"):
|
||||
with self.assertRaisesRegex(ValueError, "can't be empty"):
|
||||
im.resize((32, 32), resample, (20.1, 20.1, 20, 20))
|
||||
|
||||
with self.assertRaisesRegexp(ValueError, "can't exceed"):
|
||||
with self.assertRaisesRegex(ValueError, "can't exceed"):
|
||||
im.resize((32, 32), resample, (0, 0, im.width + 1, im.height))
|
||||
with self.assertRaisesRegexp(ValueError, "can't exceed"):
|
||||
with self.assertRaisesRegex(ValueError, "can't exceed"):
|
||||
im.resize((32, 32), resample, (0, 0, im.width, im.height + 1))
|
||||
|
||||
def resize_tiled(self, im, dst_size, xtiles, ytiles):
|
||||
|
@ -447,7 +447,7 @@ class CoreResampleBoxTest(PillowTestCase):
|
|||
|
||||
# error with box should be much smaller than without
|
||||
self.assert_image_similar(reference, with_box, 6)
|
||||
with self.assertRaisesRegexp(AssertionError, "difference 29\."):
|
||||
with self.assertRaisesRegex(AssertionError, "difference 29\."):
|
||||
self.assert_image_similar(reference, without_box, 5)
|
||||
|
||||
def test_formats(self):
|
||||
|
@ -490,7 +490,7 @@ class CoreResampleBoxTest(PillowTestCase):
|
|||
try:
|
||||
res = im.resize(size, Image.LANCZOS, box)
|
||||
self.assertEqual(res.size, size)
|
||||
with self.assertRaisesRegexp(AssertionError, "difference \d"):
|
||||
with self.assertRaisesRegex(AssertionError, "difference \d"):
|
||||
# check that the difference at least that much
|
||||
self.assert_image_similar(res, im.crop(box), 20)
|
||||
except AssertionError:
|
||||
|
|
|
@ -43,7 +43,7 @@ class TestImageCms(PillowTestCase):
|
|||
self.assertEqual(list(map(type, v)), [str, str, str, str])
|
||||
|
||||
# internal version number
|
||||
self.assertRegexpMatches(ImageCms.core.littlecms_version, r"\d+\.\d+$")
|
||||
self.assertRegex(ImageCms.core.littlecms_version, r"\d+\.\d+$")
|
||||
|
||||
self.skip_missing()
|
||||
i = ImageCms.profileToProfile(hopper(), SRGB, SRGB)
|
||||
|
|
|
@ -75,8 +75,7 @@ class TestImageFont(PillowTestCase):
|
|||
layout_engine=self.LAYOUT_ENGINE)
|
||||
|
||||
def test_sanity(self):
|
||||
self.assertRegexpMatches(
|
||||
ImageFont.core.freetype2_version, r"\d+\.\d+\.\d+$")
|
||||
self.assertRegex(ImageFont.core.freetype2_version, r"\d+\.\d+\.\d+$")
|
||||
|
||||
def test_font_properties(self):
|
||||
ttf = self.get_font()
|
||||
|
|
|
@ -17,6 +17,11 @@ class TestImageOpsUsm(PillowTestCase):
|
|||
self.assertEqual(i.mode, "RGB")
|
||||
self.assertEqual(i.size, (128, 128))
|
||||
|
||||
i = self.assert_warning(DeprecationWarning,
|
||||
ImageOps.box_blur, im, 1)
|
||||
self.assertEqual(i.mode, "RGB")
|
||||
self.assertEqual(i.size, (128, 128))
|
||||
|
||||
i = self.assert_warning(DeprecationWarning,
|
||||
ImageOps.gblur, im, 2.0)
|
||||
self.assertEqual(i.mode, "RGB")
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
from helper import unittest, PillowTestCase
|
||||
from distutils.version import LooseVersion
|
||||
try:
|
||||
import numpy as np
|
||||
from numpy.testing import assert_equal
|
||||
|
||||
from scipy import misc
|
||||
import scipy
|
||||
HAS_SCIPY = True
|
||||
except ImportError:
|
||||
HAS_SCIPY = False
|
||||
|
||||
|
||||
class Test_scipy_resize(PillowTestCase):
|
||||
""" Tests for scipy regression in Pillow 2.6.0
|
||||
|
||||
Tests from https://github.com/scipy/scipy/blob/master/scipy/misc/pilutil.py
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
if not HAS_SCIPY:
|
||||
self.skipTest("Scipy Required")
|
||||
|
||||
def test_imresize(self):
|
||||
im = np.random.random((10, 20))
|
||||
for T in np.sctypes['float'] + [float]:
|
||||
# 1.1 rounds to below 1.1 for float16, 1.101 works
|
||||
im1 = misc.imresize(im, T(1.101))
|
||||
self.assertEqual(im1.shape, (11, 22))
|
||||
|
||||
# this test fails prior to scipy 0.14.0b1
|
||||
# https://github.com/scipy/scipy/commit/855ff1fff805fb91840cf36b7082d18565fc8352
|
||||
@unittest.skipIf(HAS_SCIPY and
|
||||
(LooseVersion(scipy.__version__) < LooseVersion('0.14.0')),
|
||||
"Test fails on scipy < 0.14.0")
|
||||
def test_imresize4(self):
|
||||
im = np.array([[1, 2],
|
||||
[3, 4]])
|
||||
res = np.array([[1., 1.25, 1.75, 2.],
|
||||
[1.5, 1.75, 2.25, 2.5],
|
||||
[2.5, 2.75, 3.25, 3.5],
|
||||
[3., 3.25, 3.75, 4.]], dtype=np.float32)
|
||||
# Check that resizing by target size, float and int are the same
|
||||
im2 = misc.imresize(im, (4, 4), mode='F') # output size
|
||||
im3 = misc.imresize(im, 2., mode='F') # fraction
|
||||
im4 = misc.imresize(im, 200, mode='F') # percentage
|
||||
assert_equal(im2, res)
|
||||
assert_equal(im3, res)
|
||||
assert_equal(im4, res)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in New Issue
Block a user