From 4c5a5c1f0eddef0d384f18d46657c92e954b5075 Mon Sep 17 00:00:00 2001 From: hugovk Date: Wed, 30 Jul 2014 19:34:20 +0300 Subject: [PATCH] Tests for IptcImagePlugin.py --- Tests/test_file_iptc.py | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Tests/test_file_iptc.py diff --git a/Tests/test_file_iptc.py b/Tests/test_file_iptc.py new file mode 100644 index 000000000..4ae85c66b --- /dev/null +++ b/Tests/test_file_iptc.py @@ -0,0 +1,71 @@ +from helper import unittest, PillowTestCase, lena + +from PIL import Image, IptcImagePlugin + +TEST_FILE = "Tests/images/iptc.jpg" + + +class TestFileIptc(PillowTestCase): + + # Helpers + + def dummy_IptcImagePlugin(self): + # Create an IptcImagePlugin object without initializing it + class FakeImage: + pass + im = FakeImage() + im.__class__ = IptcImagePlugin.IptcImageFile + return im + + # Tests + + def test_getiptcinfo_jpg_none(self): + # Arrange + im = lena() + + # Act + iptc = IptcImagePlugin.getiptcinfo(im) + + # Assert + self.assertIsNone(iptc) + + def test_getiptcinfo_jpg_found(self): + # Arrange + im = Image.open(TEST_FILE) + + # Act + iptc = IptcImagePlugin.getiptcinfo(im) + + # Assert + self.assertIsInstance(iptc, dict) + self.assertEqual(iptc[(2, 90)], "Budapest") + self.assertEqual(iptc[(2, 101)], "Hungary") + + # _FIXME: is_raw() is disabled. Should we remove it? + def test__is_raw_equal_zero(self): + # Arrange + im = self.dummy_IptcImagePlugin() + offset = 0 + size = 4 + + # Act + ret = im._is_raw(offset, size) + + # Assert + self.assertEqual(ret, 0) + + def test_i(self): + # Arrange + c = "a" + + # Act + ret = IptcImagePlugin.i(c) + + # Assert + self.assertEqual(ret, 97) + + +if __name__ == '__main__': + unittest.main() + +# End of file