mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-14 11:26:27 +03:00
Merge pull request #1799 from radarhere/warning
Added warning for deprecated as_dict method
This commit is contained in:
commit
66e937875c
|
@ -448,11 +448,10 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
"""Return a dictionary of the image's tags.
|
"""Return a dictionary of the image's tags.
|
||||||
|
|
||||||
use `dict(ifd)` instead.
|
|
||||||
|
|
||||||
.. deprecated:: 3.0.0
|
.. deprecated:: 3.0.0
|
||||||
"""
|
"""
|
||||||
# FIXME Deprecate: use dict(self)
|
warnings.warn("as_dict() is deprecated. " +
|
||||||
|
"Please use dict(ifd) instead.", DeprecationWarning)
|
||||||
return dict(self)
|
return dict(self)
|
||||||
|
|
||||||
def named(self):
|
def named(self):
|
||||||
|
|
|
@ -244,31 +244,40 @@ class TestFileTiff(PillowTestCase):
|
||||||
# Assert
|
# Assert
|
||||||
self.assertIsInstance(ret, str)
|
self.assertIsInstance(ret, str)
|
||||||
|
|
||||||
def test_as_dict(self):
|
def test_as_dict_deprecation(self):
|
||||||
# Arrange
|
# Arrange
|
||||||
filename = "Tests/images/pil136.tiff"
|
filename = "Tests/images/pil136.tiff"
|
||||||
im = Image.open(filename)
|
im = Image.open(filename)
|
||||||
|
|
||||||
|
self.assert_warning(DeprecationWarning, lambda: im.tag_v2.as_dict())
|
||||||
|
self.assert_warning(DeprecationWarning, lambda: im.tag.as_dict())
|
||||||
|
|
||||||
|
def test_dict(self):
|
||||||
|
# Arrange
|
||||||
|
filename = "Tests/images/pil136.tiff"
|
||||||
|
im = Image.open(filename)
|
||||||
|
|
||||||
# v2 interface
|
# v2 interface
|
||||||
self.assertEqual(
|
v2_tags = {256: 55, 257: 43, 258: (8, 8, 8, 8), 259: 1,
|
||||||
im.tag_v2.as_dict(),
|
262: 2, 296: 2, 273: (8,), 338: (1,), 277: 4,
|
||||||
{256: 55, 257: 43, 258: (8, 8, 8, 8), 259: 1,
|
279: (9460,), 282: 72.0, 283: 72.0, 284: 1}
|
||||||
262: 2, 296: 2, 273: (8,), 338: (1,), 277: 4,
|
self.assertEqual(dict(im.tag_v2), v2_tags)
|
||||||
279: (9460,), 282: 72.0, 283: 72.0, 284: 1})
|
self.assertEqual(im.tag_v2.as_dict(), v2_tags)
|
||||||
|
|
||||||
# legacy interface
|
# legacy interface
|
||||||
self.assertEqual(
|
legacy_tags = {256: (55,), 257: (43,), 258: (8, 8, 8, 8), 259: (1,),
|
||||||
im.tag.as_dict(),
|
262: (2,), 296: (2,), 273: (8,), 338: (1,), 277: (4,),
|
||||||
{256: (55,), 257: (43,), 258: (8, 8, 8, 8), 259: (1,),
|
279: (9460,), 282: ((720000, 10000),),
|
||||||
262: (2,), 296: (2,), 273: (8,), 338: (1,), 277: (4,),
|
283: ((720000, 10000),), 284: (1,)}
|
||||||
279: (9460,), 282: ((720000, 10000),),
|
self.assertEqual(dict(im.tag), legacy_tags)
|
||||||
283: ((720000, 10000),), 284: (1,)})
|
self.assertEqual(im.tag.as_dict(), legacy_tags)
|
||||||
|
|
||||||
def test__delitem__(self):
|
def test__delitem__(self):
|
||||||
filename = "Tests/images/pil136.tiff"
|
filename = "Tests/images/pil136.tiff"
|
||||||
im = Image.open(filename)
|
im = Image.open(filename)
|
||||||
len_before = len(im.ifd.as_dict())
|
len_before = len(dict(im.ifd))
|
||||||
del im.ifd[256]
|
del im.ifd[256]
|
||||||
len_after = len(im.ifd.as_dict())
|
len_after = len(dict(im.ifd))
|
||||||
self.assertEqual(len_before, len_after + 1)
|
self.assertEqual(len_before, len_after + 1)
|
||||||
|
|
||||||
def test_load_byte(self):
|
def test_load_byte(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user