def test_init_without_overwrite(self): # For image. image_media = op.join(self.work_dir, 'images') os.makedirs(image_media) with self.assertRaises(ValueError): backendMedia.MediaWriter(media_type='pictures', image_media=image_media) # For mask. mask_media = op.join(self.work_dir, 'masks') os.makedirs(mask_media) with self.assertRaises(ValueError): backendMedia.MediaWriter(media_type='pictures', mask_media=mask_media)
def test_close_without_error(self): # Pictures. writer = backendMedia.MediaWriter(media_type='pictures', image_media=op.join( self.work_dir, 'pictures')) writer.imwrite(np.zeros((100, 100, 3), dtype=np.uint8)) writer.close() # Video. writer = backendMedia.MediaWriter(media_type='video', image_media=op.join( self.work_dir, 'video.avi')) writer.imwrite(np.zeros((100, 100, 3), dtype=np.uint8)) writer.close()
def test_init_without_overwrite(self): # For image. image_media = op.join(self.work_dir, 'images.avi') with open(image_media, 'w'): pass with self.assertRaises(ValueError): backendMedia.MediaWriter(media_type='video', image_media=image_media) # For mask. mask_media = op.join(self.work_dir, 'masks.avi') with open(mask_media, 'w'): pass with self.assertRaises(ValueError): backendMedia.MediaWriter(media_type='video', mask_media=mask_media)
def test_pictures_maskwrite(self): mask_media = op.join(self.work_dir, 'masks') writer = backendMedia.MediaWriter(media_type='pictures', mask_media=mask_media) writer.maskwrite(np.zeros((100, 100), dtype=np.uint8)) writer.close() self.assertTrue(op.exists(op.join(mask_media, '000000.png')))
def test_pictures_imwrite(self): image_media = op.join(self.work_dir, 'images') writer = backendMedia.MediaWriter(media_type='pictures', image_media=image_media) writer.imwrite(np.zeros((100, 100, 3), dtype=np.uint8)) writer.close() self.assertTrue(op.exists(op.join(image_media, '000000.jpg')))
def test_init_create_dir(self): image_media = op.join(self.work_dir, 'images') mask_media = op.join(self.work_dir, 'masks') backendMedia.MediaWriter(media_type='pictures', image_media=image_media, mask_media=mask_media) self.assertTrue(op.exists(image_media)) self.assertTrue(op.exists(mask_media))
def test_init_no_extension(self): # Instead of "images.avi". image_media = op.join(self.work_dir, 'images') writer = backendMedia.MediaWriter(media_type='video', image_media=image_media) with self.assertRaises(TypeError): writer.imwrite(np.zeros((100, 100, 3), dtype=np.uint8)) writer.close()
def test_maskwrite_namehint(self): mask_media = op.join(self.work_dir, 'masks') writer = backendMedia.MediaWriter(media_type='pictures', mask_media=mask_media) mask_gt = skimage.io.imread('testdata/cars/masks/000000.png') writer.close() writer.maskwrite(mask_gt, namehint='mymask') mask = skimage.io.imread(op.join(mask_media, 'mymask.png')) self.assertLess(_diff(mask, mask_gt), 0.002) writer.close()
def test_video_init_create_files(self): image_media = op.join(self.work_dir, 'images.avi') mask_media = op.join(self.work_dir, 'masks.avi') writer = backendMedia.MediaWriter(media_type='video', image_media=image_media, mask_media=mask_media) writer.imwrite(np.zeros((100, 100, 3), dtype=np.uint8)) writer.maskwrite(np.zeros((100, 100), dtype=np.uint8)) writer.close() self.assertTrue(op.exists(image_media)) self.assertTrue(op.exists(mask_media))
def test_init_overwrite_files(self): image_media = op.join(self.work_dir, 'images.avi') mask_media = op.join(self.work_dir, 'masks.avi') with open(image_media, 'w'): pass with open(mask_media, 'w'): pass writer = backendMedia.MediaWriter(media_type='video', image_media=image_media, mask_media=mask_media, overwrite=True) writer.close() self.assertTrue(op.exists(image_media)) self.assertTrue(op.exists(mask_media))
def test_init_overwrite_dirs(self): image_media = op.join(self.work_dir, 'images') mask_media = op.join(self.work_dir, 'masks') os.makedirs(image_media) os.makedirs(mask_media) with open(op.join(image_media, 'myfile'), 'w'): pass with open(op.join(mask_media, 'myfile'), 'w'): pass backendMedia.MediaWriter(media_type='pictures', image_media=image_media, mask_media=mask_media, overwrite=True) # Check that dirs are recreated. self.assertTrue(op.exists(image_media)) self.assertTrue(op.exists(mask_media)) # Check that files dissapeared from the dirs. self.assertFalse(op.exists(op.join(image_media, 'myfile'))) self.assertFalse(op.exists(op.join(mask_media, 'myfile')))
def test_close_uninit_without_error(self): writer = backendMedia.MediaWriter(media_type='pictures') writer.close() writer = backendMedia.MediaWriter(media_type='video') writer.close()