def test_copy_data_files_featurize_prep():
    """Test copy data files - featurization prep"""
    tmp_dir = tempfile.mkdtemp()
    test_data_dir = DATA_PATH
    args_dict = {
        'copied_data_dir': tmp_dir,
        'headerfile_path': pjoin(test_data_dir,
                                 "asas_training_subset_classes.dat"),
        'zipfile_path': "None",
        'custom_script_path': pjoin(test_data_dir,
                                    "testfeature1.py")}
    tmp_files_list = ridc.copy_data_files_featurize_prep(args_dict)
    assert os.path.exists(pjoin(tmp_dir, "function_args.pkl"))
    assert os.path.exists(pjoin(tmp_dir,
                                "asas_training_subset_classes.dat"))
    copied_custom_script_path = pjoin(tmp_dir, "custom_feature_defs.py")
    assert os.path.exists(copied_custom_script_path)
    os.remove(copied_custom_script_path)
    shutil.rmtree(tmp_dir, ignore_errors=True)
    assert isinstance(tmp_files_list, list) and len(tmp_files_list) > 0
def test_copy_results_files_featurize():
    """Test copy results files - featurize"""
    copied_data_dir = os.path.join(cfg.PROJECT_PATH, "tmp",
                                   str(uuid.uuid4())[:10])
    os.makedirs(copied_data_dir)
    featurize_setup()
    shutil.copy(
        pjoin(DATA_PATH, "testfeature1.py"),
        cfg.CUSTOM_FEATURE_SCRIPT_FOLDER)
    headerfile_path = pjoin(
        cfg.UPLOAD_FOLDER, "asas_training_subset_classes_with_metadata.dat")
    zipfile_path = pjoin(cfg.UPLOAD_FOLDER,
                         "asas_training_subset.tar.gz")
    features_to_use = ["std_err", "freq1_harmonics_freq_0"]
    featureset_key = "TEST01"
    is_test = True
    already_featurized = False
    custom_script_path = pjoin(cfg.CUSTOM_FEATURE_SCRIPT_FOLDER,
                               "testfeature1.py")
    args_dict = locals()
    tmp_files = ridc.copy_data_files_featurize_prep(args_dict)
    client, cont_id = ridc.spin_up_and_run_container("featurize",
                                                     copied_data_dir)
    ridc.copy_results_files_featurize(featureset_key, client, cont_id)
    shutil.rmtree(copied_data_dir, ignore_errors=True)
    assert(os.path.exists(pjoin(cfg.FEATURES_FOLDER,
                                "TEST01_features.csv")))
    assert(os.path.exists(pjoin(cfg.FEATURES_FOLDER,
                                "TEST01_classes.npy")))
    assert(os.path.exists(pjoin(pjoin(cfg.MLTSP_PACKAGE_PATH,
                                      "Flask/static/data"),
                                "TEST01_features_with_classes.csv")))
    os.remove(pjoin(cfg.FEATURES_FOLDER, "TEST01_classes.npy"))
    os.remove(pjoin(cfg.FEATURES_FOLDER, "TEST01_features.csv"))
    os.remove(pjoin(pjoin(cfg.MLTSP_PACKAGE_PATH,
                          "Flask/static/data"),
                    "TEST01_features_with_classes.csv"))
    featurize_teardown()