def test_preprocess_data_invalid_model_str(): """Raise an error if the model_str is not a valid model""" with pytest.raises(ValueError): preprocess_data(IMG_COL_HEAD, 'derp', csv_path=DIRECTORY_CSV_PATH_PREPROCESS, new_csv_name=ERROR_NEW_CSV_NAME_PREPROCESS)
def test_preprocess_data_fake_csv(): """Raise an error if the csv_path doesn't point to a file""" error_file = 'rehtonaybtmaerdecnaraeppaeremasawootehtahtdootsrednueh' try: assert not os.path.isfile(error_file) except AssertionError: logging.error( 'Whoops, that dreamer exists. change to error_file to a file path that does not exist.' ) with pytest.raises(TypeError): preprocess_data(IMG_COL_HEAD, 'xception', csv_path=error_file, list_of_images=IMAGE_LIST_SINGLE) assert not os.path.isfile(ERROR_NEW_CSV_PATH_PREPROCESS)
def test_preprocess_data_fake_dir(): """Raise an error if the image_path doesn't point to a real directory""" error_dir = 'egaugnalymgnidnatsrednufoerusuoyera/emdaerohwuoy/' try: assert not os.path.isdir(error_dir) except AssertionError: logging.error( 'Whoops, that labyrinth exists. ' 'Change error_dir to a directory path that does not exist.') with pytest.raises(TypeError): preprocess_data(IMG_COL_HEAD, 'xception', list_of_images=IMAGE_LIST_SINGLE, image_path=error_dir) assert not os.path.isfile(ERROR_NEW_CSV_PATH_PREPROCESS)
def test_preprocess_data(image_path, csv_path, new_csv_name, check_arrays, image_list): """ Full integration test: check for Type and Value errors for badly passed variables, and make sure that the network preprocesses data correctly for all three cases. """ # Ensure the new csv doesn't already exist if os.path.isfile(new_csv_name): os.remove(new_csv_name) # Create the full (data, csv_path, image_list) for each of the three cases preprocessed_case = preprocess_data(IMG_COL_HEAD, 'xception', grayscale=False, image_path=image_path, csv_path=csv_path, new_csv_name=new_csv_name) # Ensure a new csv wasn't created when they weren't needed, and that a new csv # WAS created when it was needed. Then, remove the new csv. assert not os.path.isfile(ERROR_NEW_CSV_NAME_PREPROCESS) if new_csv_name == NEW_CSV_NAME_PREPROCESS: csv_path = new_csv_name compare_preprocessing(preprocessed_case, csv_path, check_arrays, image_list) if new_csv_name == NEW_CSV_NAME_PREPROCESS: assert os.path.isfile(new_csv_name) os.remove(new_csv_name)
def test_preprocess_data(image_path, csv_path, check_arrays, image_list): """ Full integration test: check for Type and Value errors for badly passed variables, and make sure that the network preprocesses data correctly for all three cases. """ # Create the full (data, csv_path, image_list) for each of the three cases preprocessed_case = preprocess_data(IMG_COL_HEAD, 'xception', list_of_images=image_list, grayscale=False, image_path=image_path, csv_path=csv_path) compare_preprocessing(preprocessed_case, csv_path, check_arrays, image_list)
def test_preprocess_data_grayscale(): # Ensure the new csv doesn't already exist if os.path.isfile(ERROR_NEW_CSV_PATH_PREPROCESS): os.remove(ERROR_NEW_CSV_PATH_PREPROCESS) # Create the full (data, csv_path, image_list) for each of the three cases preprocessed_case = preprocess_data(IMG_COL_HEAD, 'xception', grayscale=True, image_path=IMAGE_PATH, csv_path=DIRECTORY_CSV_PATH_PREPROCESS) # Ensure a new csv wasn't created when they weren't needed assert not os.path.isfile(ERROR_NEW_CSV_PATH_PREPROCESS) compare_preprocessing(preprocessed_case, DIRECTORY_CSV_PATH_PREPROCESS, GRAYSCALE_ARRAYS, COMBINED_LIST_PREPROCESS)
def test_preprocess_data_invalid_url_or_dir(): """Raise an error if the image in the column is an invalid path""" preprocess_data(IMG_COL_HEAD, 'xception', list_of_images=IMAGE_LIST_SINGLE, csv_path=ERROR_ROW_CSV)
def test_preprocess_data_no_input(): """Raise error if no csv or directory is passed""" with pytest.raises(ValueError): preprocess_data(IMG_COL_HEAD, 'xception', [''])