Source code for test_exif_lib

"""
This module contains unit tests for the MetaImage class in the exif_lib module.
The tests verify the functionality of modifying, reading, and clearing comments
in image metadata using the MetaImage class.
"""

from exif_lib import MetaImage
import unittest


[docs] class TestExivlib(unittest.TestCase): """ Unit tests for the MetaImage class to ensure correct functionality of modifying, reading, and clearing image comments. Attributes: comment (str): The comment to be used in tests for modifying and reading image comments. """ comment = "Raspi"
[docs] def test_modify_comment(self): """ Test the modify_comment method of MetaImage. This test initializes a MetaImage object with a sample image, modifies the comment in the image metadata, and asserts that the comment was modified correctly. """ img = MetaImage("../SourceImage/image.jpg") img.modify_comment(self.comment) self.assertEqual(img.read_comment(), self.comment)
[docs] def test_read_comment(self): """ Test the read_comment method of MetaImage. This test initializes a MetaImage object with a sample image and asserts that the comment read from the image metadata matches the expected comment. """ img = MetaImage("../SourceImage/image.jpg") self.assertEqual(img.read_comment(), self.comment)
[docs] def test_clear_comment(self): """ Test the clear_comment method of MetaImage. This test initializes a MetaImage object with a sample image, clears the comment in the image metadata, and asserts that the comment was cleared (returns None). """ img = MetaImage("../SourceImage/image.jpg") self.assertEqual(img.clear_comment(), None)
if __name__ == "__main__": unittest.main()