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.pkl") feats_known_dict = {"feat1": 0.215, "feat2": 0.311} ts_datafile = pjoin(DATA_PATH, "dotastro_215153.dat") t, m, e = ctt.parse_ts_data(ts_datafile) feats_known_dict['t'] = t feats_known_dict['m'] = m feats_known_dict['e'] = e 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) assert(os.path.exists(copied_file_path1)) assert(os.path.exists(copied_file_path2)) with open(copied_file_path2, "rb") as f: unpickled_dict = pickle.load(f) npt.assert_equal(unpickled_dict, feats_known_dict) shutil.rmtree(tmp_dir_path, ignore_errors=True)
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)
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)
def test_extract_feats_in_docker_container(): """Test custom feature extraction in Docker container""" tmp_dir_path = cft.make_tmp_dir() feats_known_dict = {"feat1": 0.215, "feat2": 0.311} ts_datafile = pjoin(DATA_PATH, "dotastro_215153.dat") t, m, e = ctt.parse_ts_data(ts_datafile) feats_known_dict['t'] = t feats_known_dict['m'] = m feats_known_dict['e'] = e cft.copy_data_to_tmp_dir(tmp_dir_path, pjoin(DATA_PATH, "testfeature1.py"), feats_known_dict) 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) assert(isinstance(results, dict)) npt.assert_almost_equal(results["avg_mag"], 10.347417647058824)
def test_make_tmp_dir(): """Test creation of temp directory""" tmp_dir_path = cft.make_tmp_dir() assert(os.path.exists(tmp_dir_path)) shutil.rmtree(tmp_dir_path, ignore_errors=True) assert(not os.path.exists(tmp_dir_path))