From 0aa8bd00e70c6138ece6d4484234d173099cf5da Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 30 Jun 2021 11:23:57 +1000 Subject: [PATCH] Added warning if defusedxml is not found --- Tests/test_file_jpeg.py | 3 ++- Tests/test_file_png.py | 3 ++- Tests/test_file_tiff.py | 3 ++- src/PIL/Image.py | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index 3876466d3..90926e8d9 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -831,7 +831,8 @@ class TestFileJpeg: def test_getxmp(self): with Image.open("Tests/images/xmp_test.jpg") as im: if ElementTree is None: - assert xmp == {} + with pytest.warns(UserWarning): + assert im.getxmp() == {} else: xmp = im.getxmp() diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index cfeedd932..ffacbbbf4 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -659,7 +659,8 @@ class TestFilePng: def test_getxmp(self): with Image.open("Tests/images/color_snakes.png") as im: if ElementTree is None: - assert im.getxmp() == {} + with pytest.warns(UserWarning): + assert im.getxmp() == {} else: xmp = im.getxmp() diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 3465d946e..57f45bd09 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -651,7 +651,8 @@ class TestFileTiff: def test_getxmp(self): with Image.open("Tests/images/lab.tif") as im: if ElementTree is None: - assert im.getxmp() == {} + with pytest.warns(UserWarning): + assert im.getxmp() == {} else: xmp = im.getxmp() diff --git a/src/PIL/Image.py b/src/PIL/Image.py index c615e9a93..44a9fd0d2 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1364,6 +1364,7 @@ class Image: return value if ElementTree is None: + warnings.warn("XMP data cannot be read without defusedxml dependency") return {} else: root = ElementTree.fromstring(xmp_tags)