def test_open_img(self): img = imgs.create_rgb() # given an Pillow Image, open_img should return the same instance self.assertEqual(id(img), id(analyse.open_img(img))) # given an path, open_img should return a Pillow Image instance with imgs.TempFile(img) as img_path: opened_img = analyse.open_img(img_path) self.assertTrue(isinstance(opened_img, Image.Image)) self.assertEqual(list(img.getdata()), list(opened_img.getdata()))
def test_iter_planes(self): img = imgs.create_rgb() planes = list(analyse.iter_planes(img)) # 3 bands (R, G, B) w/ 8 planes + 1 special band (RGB) with 8 planes self.assertEqual(3 * 8 + 8, len(planes)) band, bit, plane = planes[0] self.assertEqual('R', band) self.assertEqual(0, bit) self.assertEqual(np.prod(img.size), plane.size) self.assertEqual(0, plane.sum())
def test_save_img(self): img = imgs.create_rgb() # when out_path is None, this should not write any file with imgs.TempFile() as path: analyse.save_img(img, None) self.assertFalse(os.path.isfile(path)) # when out_path is set to a string, save_img should save the file with imgs.TempFile() as path: analyse.save_img(img, path) self.assertTrue(os.path.isfile(path))