def setUp(self): self.filename = 'array2gif_test.gif' self.flickinger_dataset = np.array( [[[255, 255, 255, 255, 255, 0, 0, 0, 0, 0], [255, 255, 255, 255, 255, 0, 0, 0, 0, 0], [255, 255, 255, 255, 255, 0, 0, 0, 0, 0], [255, 255, 255, 255, 255, 255, 255, 0, 0, 0], [255, 255, 255, 255, 255, 255, 255, 0, 0, 0], [0, 0, 0, 255, 255, 255, 255, 255, 255, 255], [0, 0, 0, 255, 255, 255, 255, 255, 255, 255], [0, 0, 0, 0, 0, 255, 255, 255, 255, 255], [0, 0, 0, 0, 0, 255, 255, 255, 255, 255], [0, 0, 0, 0, 0, 255, 255, 255, 255, 255]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 255, 255, 255, 255, 0, 0, 0], [0, 0, 0, 255, 255, 255, 255, 0, 0, 0], [0, 0, 0, 255, 255, 255, 255, 0, 0, 0], [0, 0, 0, 255, 255, 255, 255, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 255, 255, 255, 255, 255], [0, 0, 0, 0, 0, 255, 255, 255, 255, 255], [0, 0, 0, 0, 0, 255, 255, 255, 255, 255], [0, 0, 0, 255, 255, 255, 255, 255, 255, 255], [0, 0, 0, 255, 255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 255, 255, 255, 0, 0, 0], [255, 255, 255, 255, 255, 255, 255, 0, 0, 0], [255, 255, 255, 255, 255, 0, 0, 0, 0, 0], [255, 255, 255, 255, 255, 0, 0, 0, 0, 0], [255, 255, 255, 255, 255, 0, 0, 0, 0, 0]]]) self.flickinger_image = core.get_image(self.flickinger_dataset)
def test_color_table_error_when_more_than_256_colors(self): x = np.array(range(100)) z = np.zeros(len(x)) d = np.array([[x, z, z], [z, x, z], [z, z, x]]) image = core.get_image(d) with self.assertRaises(RuntimeError): core.get_colors(image)
def test_no_color_table_error_when_less_equal_256_colors(self): x = np.array(range(85)) z = np.zeros(len(x)) d = np.array([[x, z, z], [z, x, z], [z, z, x]]) image = core.get_image(d) try: core.get_colors(image) except RuntimeError as e: msg = "`get_colors` RuntimeError on 255 distinct colors.\n{}" self.fail(msg.format(e))
def test_pixels_in_order(self): d = np.array([[[1]], [[2]], [[3]]]) img = core.get_image(d) self.assertEqual(img[0][0], b'\x01\x02\x03')
def test_pixels_three_bytes(self): d = np.array([[[1]], [[2]], [[3]]]) img = core.get_image(d) self.assertEqual(len(img[0][0]), 3)
def test_no_warning_on_uint8_dataset(self): d = np.array([[[1]], [[2]], [[3]]]) with warnings.catch_warnings(record=True) as wlist: core.get_image(d) self.assertEqual(len(wlist), 0)
def test_warning_on_non_uint8_dataset(self): d = np.array([[[1]], [[2]], [[3.14]]]) with warnings.catch_warnings(record=True) as wlist: core.get_image(d) self.assertTrue(len(wlist) > 0) self.assertTrue(any('array2gif' in w.filename for w in wlist))