mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Remove unittest regex deprecation warnings
This commit is contained in:
parent
b01ba0f50c
commit
ecc4c7fecc
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user