def test_import_images_are_ordered_and_unduplicated(): # we know that import_images returns images in path order imgs = list(mio.import_images(mio.data_dir_path())) imgs_filenames = [i.path.stem for i in imgs] print(imgs_filenames) exp_imgs_filenames = ['breakingbad', 'einstein', 'lenna', 'menpo_thumbnail', 'takeo', 'tongue'] assert exp_imgs_filenames == imgs_filenames
def test_import_lazy_list(): from menpo.base import LazyList data_path = mio.data_dir_path() ll = mio.import_images(data_path) assert isinstance(ll, LazyList) ll = mio.import_landmark_files(data_path) assert isinstance(ll, LazyList)
def test_ioinfo(): # choose a random asset (all should have it!) img = pio.import_builtin_asset('einstein.jpg') path = pio.data_path_to('einstein.jpg') assert(img.ioinfo.filepath == path) assert(img.ioinfo.filename == 'einstein') assert(img.ioinfo.extension == '.jpg') assert(img.ioinfo.dir == pio.data_dir_path())
def test_path(): # choose a random asset (all should have it!) img = mio.import_builtin_asset('einstein.jpg') path = mio.data_path_to('einstein.jpg') assert(img.path == path) assert(img.path.stem == 'einstein') assert(img.path.suffix == '.jpg') assert(img.path.parent == mio.data_dir_path()) assert(img.path.name == 'einstein.jpg')
def test_import_images(): imgs_glob = os.path.join(pio.data_dir_path(), '*') imgs = list(pio.import_images(imgs_glob)) imgs_filenames = set(i.ioinfo.filename for i in imgs) exp_imgs_filenames = {'einstein', 'takeo', 'breakingbad', 'lenna'} assert(len(exp_imgs_filenames - imgs_filenames) == 0)
def test_import_image_no_norm(): img_path = os.path.join(mio.data_dir_path(), 'einstein.jpg') im = mio.import_image(img_path, normalise=False) assert im.pixels.dtype == np.uint8
def test_import_images_zero_max_images(): # different since the conditional 'if max_assets' is skipped, # thus all images might be imported. list(mio.import_images(mio.data_dir_path(), max_images=0))
def test_image_paths(): ls = mio.image_paths(os.path.join(mio.data_dir_path(), '*')) assert(len(ls) == 5)
def test_import_images(): imgs = list(mio.import_images(mio.data_dir_path())) imgs_filenames = set(i.path.stem for i in imgs) exp_imgs_filenames = {'einstein', 'takeo', 'breakingbad', 'lenna'} assert(len(exp_imgs_filenames - imgs_filenames) == 0)
def test_image_paths(): ls = mio.image_paths(mio.data_dir_path()) assert (len(list(ls)) == 6)
def test_shuffle_kwarg_true_calls_shuffle(mock): list(mio.import_images(mio.data_dir_path(), shuffle=True)) assert mock.called
def test_import_image(): img_path = mio.data_dir_path() / 'einstein.jpg' im = mio.import_image(img_path) assert im.pixels.dtype == np.float assert im.n_channels == 1
def test_import_landmark_file(): lm_path = mio.data_dir_path() / 'einstein.pts' mio.import_landmark_file(lm_path)
def test_import_image_no_norm(): img_path = mio.data_dir_path() / 'einstein.jpg' im = mio.import_image(img_path, normalise=False) assert im.pixels.dtype == np.uint8
def test_import_as_generator(): import types gen = mio.import_images(mio.data_dir_path(), as_generator=True) assert isinstance(gen, types.GeneratorType) gen = mio.import_landmark_files(mio.data_dir_path(), as_generator=True) assert isinstance(gen, types.GeneratorType)
def test_import_image_no_norm(): img_path = mio.data_dir_path() / 'einstein.jpg' im = mio.import_image(img_path, normalize=False) assert im.pixels.dtype == np.uint8
def test_import_landmark_file(): lm_path = os.path.join(mio.data_dir_path(), 'einstein.pts') mio.import_landmark_file(lm_path)
def test_import_images(): imgs = list(mio.import_images(mio.data_dir_path())) imgs_filenames = set(i.path.stem for i in imgs) exp_imgs_filenames = {'einstein', 'takeo', 'tongue', 'breakingbad', 'lenna', 'menpo_thumbnail'} assert exp_imgs_filenames == imgs_filenames
def test_import_image(): img_path = os.path.join(mio.data_dir_path(), 'einstein.jpg') mio.import_images(img_path)
def test_image_paths(): ls = mio.image_paths(mio.data_dir_path()) assert(len(list(ls)) == 6)
def test_import_mesh(): obj_path = os.path.join(mio.data_dir_path(), 'bunny.obj') mio.import_images(obj_path)
def test_import_auto(): assets_glob = os.path.join(mio.data_dir_path(), '*') assets = list(mio.import_auto(assets_glob)) assert(len(assets) == 6)
def test_import_images_negative_max_images(): list(mio.import_images(mio.data_dir_path(), max_images=-2))
def test_import_auto_max_meshes(): assets_glob = os.path.join(mio.data_dir_path(), '*') assets = list(mio.import_auto(assets_glob, max_meshes=1)) assert(sum([isinstance(x, TriMesh) for x in assets]) == 1)
def test_mesh_paths(): ls = mio.mesh_paths(os.path.join(mio.data_dir_path(), '*')) assert(len(ls) == 2)