def test_parse_for_req_prov_params(): """Test parse custom script path for required & provided params""" fnames_req_prov_dict, all_required_params, all_provided_params = \ cft.parse_for_req_prov_params(pjoin(DATA_PATH, "testfeature1.py")) assert(all(param in all_provided_params for param in ["period", "avg_mag", "a", "g", "l", "o"])) assert(all(param in all_required_params for param in ["t", "m", "c", "period"])) assert(fnames_req_prov_dict["test_feature6"]["requires"] == ["e"]) assert(all(x in fnames_req_prov_dict["test_feature6"]["provides"] for x in ['q', 'n', 'o']))
def test_call_custom_functions(): """Test executing of custom feature definition functions""" script_fpath = pjoin(DATA_PATH, "testfeature1.py") fnames_req_prov_dict, all_required_params, all_provided_params = \ cft.parse_for_req_prov_params(script_fpath) extracted_feats = cft.call_custom_functions( {"t": [1.0, 1.2, 1.4], "m": [12.2, 14.1, 15.2], "e": [0.2, 0.3, 0.1]}, all_required_params, all_provided_params, fnames_req_prov_dict, script_fpath) assert(isinstance(extracted_feats, dict)) npt.assert_almost_equal(extracted_feats["avg_mag"], np.average([12.2, 14.1, 15.2])) assert(all(x in extracted_feats for x in ["a", "l", "o"]))
def test_call_custom_functions(): """Test executing of custom feature definition functions""" fnames_req_prov_dict, all_required_params, all_provided_params = \ cft.parse_for_req_prov_params(pjoin(DATA_PATH, "testfeature1.py")) if not os.path.exists(pjoin(cfg.TMP_CUSTOM_FEATS_FOLDER, "custom_feature_defs.py")): shutil.copyfile(pjoin(DATA_PATH, "testfeature1.py"), pjoin(cfg.TMP_CUSTOM_FEATS_FOLDER, "custom_feature_defs.py")) extracted_feats = cft.call_custom_functions( {"t": [1.0, 1.2, 1.4], "m": [12.2, 14.1, 15.2], "e": [0.2, 0.3, 0.1]}, all_required_params, all_provided_params, fnames_req_prov_dict) assert(isinstance(extracted_feats, dict)) npt.assert_almost_equal(extracted_feats["avg_mag"], np.average([12.2, 14.1, 15.2])) assert(all(x in extracted_feats for x in ["a", "l", "o"])) os.remove(pjoin(cfg.TMP_CUSTOM_FEATS_FOLDER, "custom_feature_defs.py"))