Skip to content

Commit d8c85b9

Browse files
committed
Move numpy-images to their own test case.
Change-Id: Ie6b02c7647487c1df9d4e70e9b8eed70dc8b8fe3
1 parent 9c7250f commit d8c85b9

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

tests/test_content.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,23 @@ class HasEnum:
8282
choice: Choices
8383

8484

85+
86+
8587
class UnitTests(parameterized.TestCase):
88+
8689
@parameterized.named_parameters(
87-
["PIL", PIL.Image.open(TEST_PNG_PATH)],
8890
["RGBA", PIL.Image.fromarray(np.zeros([6, 6, 4], dtype=np.uint8))],
91+
["RGB", PIL.Image.fromarray(np.zeros([6, 6, 3], dtype=np.uint8))],
92+
["P", PIL.Image.fromarray(np.zeros([6, 6, 3], dtype=np.uint8)).convert("P")],
93+
)
94+
def test_numpy_to_blob(self, image):
95+
blob = content_types.image_to_blob(image)
96+
self.assertIsInstance(blob, protos.Blob)
97+
self.assertEqual(blob.mime_type, "image/webp")
98+
self.assertStartsWith(blob.data, b"RIFF \x00\x00\x00WEBPVP8L")
99+
100+
@parameterized.named_parameters(
101+
["PIL", PIL.Image.open(TEST_PNG_PATH)],
89102
["IPython", IPython.display.Image(filename=TEST_PNG_PATH)],
90103
)
91104
def test_png_to_blob(self, image):
@@ -96,7 +109,6 @@ def test_png_to_blob(self, image):
96109

97110
@parameterized.named_parameters(
98111
["PIL", PIL.Image.open(TEST_JPG_PATH)],
99-
["RGB", PIL.Image.fromarray(np.zeros([6, 6, 3], dtype=np.uint8))],
100112
["IPython", IPython.display.Image(filename=TEST_JPG_PATH)],
101113
)
102114
def test_jpg_to_blob(self, image):
@@ -107,7 +119,6 @@ def test_jpg_to_blob(self, image):
107119

108120
@parameterized.named_parameters(
109121
["PIL", PIL.Image.open(TEST_GIF_PATH)],
110-
["P", PIL.Image.fromarray(np.zeros([6, 6, 3], dtype=np.uint8)).convert("P")],
111122
["IPython", IPython.display.Image(filename=TEST_GIF_PATH)],
112123
)
113124
def test_gif_to_blob(self, image):

0 commit comments

Comments
 (0)