def test_folder_with_no_images(): """[summary] """ # Empty dir empty_dir(TEST_DIRECTORY_PATH) # Get catalog_path catalog_path = os.path.join(TEST_DIRECTORY_PATH, "catalog") os.makedirs(catalog_path) # Get label_path label_name = "label" label_path = os.path.join(catalog_path, label_name) os.makedirs(label_path) # Add a file file_path = os.path.join(label_path, "tmp.txt") with open(file_path, "w") as tmp_file: tmp_file.write("test") # Get all labels from catalog labels = get_labels_from_catalog(catalog_path) # Assert assert len(labels) == 0 # Delete os.remove(file_path) shutil.rmtree(label_path) shutil.rmtree(catalog_path) shutil.rmtree(TEST_DIRECTORY_PATH)
def test_empty_folder(): """[summary] """ # Empty dir empty_dir(TEST_DIRECTORY_PATH) # Get catalog_path catalog_path = os.path.join(TEST_DIRECTORY_PATH, "catalog") os.makedirs(catalog_path) # Get label_path label_name = "label" label_path = os.path.join(catalog_path, label_name) os.makedirs(label_path) # Get all labels from catalog labels = get_labels_from_catalog(catalog_path) # Assert assert len(labels) == 0 # Delete shutil.rmtree(label_path) shutil.rmtree(catalog_path) shutil.rmtree(TEST_DIRECTORY_PATH)
def test_fixed_width(): """[summary] """ # Empty dir empty_dir(TEST_DIRECTORY_PATH) # Create image img_h = np.random.randint(10, 100) img_w = np.random.randint(10, 100) img = np.zeros((img_h, img_w, 3)) # Save image img_path = os.path.join(TEST_DIRECTORY_PATH, "tmp.jpg") cv2.imwrite(img_path, img) # Resize img resized_img = read_image(img_path, width=50) resized_h, resized_w, _ = resized_img.shape # Assert assert resized_w == 50 assert resized_h == int(50 * img_h / img_w) # Delete os.remove(img_path) shutil.rmtree(TEST_DIRECTORY_PATH)
def test_empty_folder(): """[summary] """ # Empty dir empty_dir(TEST_DIRECTORY_PATH) # Get all images from folder paths = get_all_images_from_folder(TEST_DIRECTORY_PATH) # Assert assert len(paths) == 0
def test_folder_with_multiple_images(): """[summary] """ # Empty dir empty_dir(TEST_DIRECTORY_PATH) # Build catalog catalog_path, label_paths, img_paths = build_catalog(TEST_DIRECTORY_PATH) # Get all images from folder paths = get_all_images_from_folder(TEST_DIRECTORY_PATH) # Assert assert len(paths) == len(img_paths) for img_path in img_paths: assert img_path in paths # Delete delete_catalog(TEST_DIRECTORY_PATH, catalog_path, label_paths, img_paths)
def test_folder_with_no_images(): """[summary] """ # Empty dir empty_dir(TEST_DIRECTORY_PATH) # Add a file file_path = os.path.join(TEST_DIRECTORY_PATH, "tmp.txt") with open(file_path, "w") as tmp_file: tmp_file.write("test") # Get all images from folder paths = get_all_images_from_folder(TEST_DIRECTORY_PATH) # Assert assert len(paths) == 0 # Delete os.remove(file_path) shutil.rmtree(TEST_DIRECTORY_PATH)
def test_folder_with_one_label(): """[summary] """ # Empty dir empty_dir(TEST_DIRECTORY_PATH) # Build catalog nb_labels = 1 catalog_path, label_paths, img_paths = build_catalog(TEST_DIRECTORY_PATH, nb_labels=nb_labels) # Get all labels from catalog labels = get_labels_from_catalog(catalog_path) # Assert assert len(labels) == nb_labels for label_path in label_paths: label_name = label_path.split("/")[-1] assert label_name in labels # Delete delete_catalog(TEST_DIRECTORY_PATH, catalog_path, label_paths, img_paths)
def test_compute_fingerprint(): """[summary] """ # Empty dir empty_dir(TEST_DIRECTORY_PATH) # Build catalog catalog_path, label_paths, img_paths = build_catalog(TEST_DIRECTORY_PATH, nb_labels=10, nb_images_per_label=2) # Build config config = build_config() # Compute fingerprint fingerprint = compute_fingerprint(catalog_path, config) # Assert print(fingerprint) assert fingerprint == "6b314882d97623aabeeda9310f073d893201a341ad5844078dd46f73" # Delete catalog delete_catalog(TEST_DIRECTORY_PATH, catalog_path, label_paths, img_paths)