From 0adffcbcb565c566e224e0375ca309f8fb8d02b4 Mon Sep 17 00:00:00 2001 From: tudacs Date: Wed, 19 Dec 2018 18:35:24 +0100 Subject: [PATCH] Add test for SyntaxError thrown by IptcImagePlugin, assert log --- tests/test_image.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_image.py b/tests/test_image.py index 6f3c5aa..e7aba91 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -1,6 +1,7 @@ import os import PIL import pytest +from unittest.mock import Mock, patch from PIL import Image from sigal import init_logging @@ -160,7 +161,7 @@ def test_get_exif_tags(): assert 'gps' not in simple -def test_get_iptc_data(): +def test_get_iptc_data(caplog): test_image = '1.jpg' src_file = os.path.join(CURRENT_DIR, 'sample', 'pictures', 'iptcTest', test_image) @@ -180,6 +181,12 @@ def test_get_iptc_data(): test_image) assert get_iptc_data(src_file) == {} + # Test catching the SyntaxError -- assert output + config = {'getiptcinfo.side_effect':SyntaxError} + with patch('sigal.image.IptcImagePlugin.getiptcinfo', side_effect=SyntaxError) as i: + get_iptc_data(src_file) + assert ['IPTC Error in'] == [ log.message[:13] for log in caplog.records ] + def test_iso_speed_ratings(): data = {'ISOSpeedRatings': ()}