コード例 #1
0
def test_copy_data_to_tmp_dir():
    """Test copy data to temp dir"""
    tmp_dir_path = cft.make_tmp_dir()
    copied_file_path1 = pjoin(tmp_dir_path,
                              "custom_feature_defs.py")
    copied_file_path2 = pjoin(tmp_dir_path,
                              "features_already_known_list.pkl")

    feats_known_dict_list = [{"feat1": 0.215, "feat2": 0.311},
                             {"feat1": 1, "feat2": 2}]
    ts_datafile_paths = [pjoin(DATA_PATH, "dotastro_215153.dat")] * 2
    cft.add_tsdata_to_feats_known_dict(feats_known_dict_list,
                                       ts_datafile_paths, None)

    for fpath in [copied_file_path1, copied_file_path2]:
        if os.path.exists(fpath):
            os.remove(fpath)
    assert(not os.path.exists(copied_file_path1))
    cft.copy_data_to_tmp_dir(tmp_dir_path,
                             pjoin(DATA_PATH, "testfeature1.py"),
                             feats_known_dict_list)
    assert(os.path.exists(copied_file_path1))
    assert(os.path.exists(copied_file_path2))
    with open(copied_file_path2, "rb") as f:
        list_of_dict = pickle.load(f)
    npt.assert_equal(list_of_dict, feats_known_dict_list)
    shutil.rmtree(tmp_dir_path, ignore_errors=True)
コード例 #2
0
def test_add_tsdata_to_feats_known_dict():
    """Test add TS data to features already known dict"""
    feats_known_dict_list = [{}]
    ts_datafile_paths = [pjoin(DATA_PATH, "dotastro_215153.dat")]
    cft.add_tsdata_to_feats_known_dict(feats_known_dict_list,
                                       ts_datafile_paths, None)
    npt.assert_equal(len(feats_known_dict_list[0]["t"]), 170)
    npt.assert_equal(len(feats_known_dict_list[0]["m"]), 170)
    npt.assert_equal(len(feats_known_dict_list[0]["e"]), 170)
    assert(isinstance(feats_known_dict_list[0]["e"][0], float))
コード例 #3
0
def test_extract_feats_in_docker_container():
    """Test custom feature extraction in Docker container"""
    tmp_dir_path = cft.make_tmp_dir()
    feats_known_dict_list = [{"feat1": 0.215, "feat2": 0.311}]
    ts_datafile_paths = [pjoin(DATA_PATH, "dotastro_215153.dat")]
    cft.add_tsdata_to_feats_known_dict(feats_known_dict_list,
                                       ts_datafile_paths, None)
    cft.copy_data_to_tmp_dir(tmp_dir_path,
                             pjoin(DATA_PATH, "testfeature1.py"),
                             feats_known_dict_list)
    results = cft.extract_feats_in_docker_container("test", tmp_dir_path)
    shutil.rmtree(tmp_dir_path, ignore_errors=True)
    cft.remove_tmp_files(tmp_dir_path)
    npt.assert_equal(len(results), 1)
    assert(isinstance(results[0], dict))
    npt.assert_almost_equal(results[0]["avg_mag"], 10.347417647058824)