def test_no_app1_segment(self): """Verify behavior of an image without an APP1 segment marker. Assert the ``has_exif`` attribute is false. Verify non-EXIF ``dir()`` list contents. Then, check the ``get_file()`` hexadecimal. """ image_path = os.path.join(os.path.dirname(__file__), "no_app1.png") with open(image_path, "rb") as image_file: my_image = Image(image_file) self.assertFalse(my_image.has_exif) self.assertEqual( str(dir(my_image)), Baseline(""" ['_segments', 'delete', 'delete_all', 'get', 'get_all', 'get_file', 'get_thumbnail', 'has_exif', 'list_all'] """), ) with pytest.raises(RuntimeError, match="image does not contain thumbnail"): my_image.get_thumbnail() self.assertEqual( "\n".join(textwrap.wrap(str(my_image.get_file()), 90)), NO_APP1_PNG)
def test_get_thumbnail(): """Test file contents of thumbnail image.""" with open(os.path.join(os.path.dirname(__file__), "grand_canyon.jpg"), "rb") as image_file: image = Image(image_file) file_hex = binascii.hexlify(image.get_thumbnail()).decode("utf8") assert "\n".join(textwrap.wrap(file_hex, 90)) == GRAND_CANYON_THUMBNAIL