|
35 | 35 | TEST_JPG_URL = "https://storage.googleapis.com/generativeai-downloads/data/test_img.jpg"
|
36 | 36 | TEST_JPG_DATA = TEST_JPG_PATH.read_bytes()
|
37 | 37 |
|
| 38 | +TEST_GIF_PATH = HERE / "test_img.gif" |
| 39 | +TEST_GIF_URL = "https://storage.googleapis.com/generativeai-downloads/data/test_img.gif" |
| 40 | +TEST_GIF_DATA = TEST_GIF_PATH.read_bytes() |
| 41 | + |
38 | 42 |
|
39 | 43 | # simple test function
|
40 | 44 | def datetime():
|
@@ -88,6 +92,17 @@ def test_jpg_to_blob(self, image):
|
88 | 92 | self.assertEqual(blob.mime_type, "image/jpeg")
|
89 | 93 | self.assertStartsWith(blob.data, b"\xff\xd8\xff\xe0\x00\x10JFIF")
|
90 | 94 |
|
| 95 | + @parameterized.named_parameters( |
| 96 | + ["PIL", PIL.Image.open(TEST_GIF_PATH)], |
| 97 | + ["P", PIL.Image.fromarray(np.zeros([6, 6, 3], dtype=np.uint8)).convert("P")], |
| 98 | + ["IPython", IPython.display.Image(filename=TEST_GIF_PATH)], |
| 99 | + ) |
| 100 | + def test_gif_to_blob(self, image): |
| 101 | + blob = content_types.image_to_blob(image) |
| 102 | + self.assertIsInstance(blob, protos.Blob) |
| 103 | + self.assertEqual(blob.mime_type, "image/gif") |
| 104 | + self.assertStartsWith(blob.data, b"GIF87a") |
| 105 | + |
91 | 106 | @parameterized.named_parameters(
|
92 | 107 | ["BlobDict", {"mime_type": "image/png", "data": TEST_PNG_DATA}],
|
93 | 108 | ["protos.Blob", protos.Blob(mime_type="image/png", data=TEST_PNG_DATA)],
|
|
0 commit comments