def test_hyper_param_populate(driver): driver.get('/') with create_test_project() as p, create_test_featureset( p) as fs, create_test_model(fs) as m: driver.refresh() proj_select = Select( driver.find_element_by_css_selector('[name=project]')) proj_select.select_by_value(str(p.id)) driver.find_element_by_id('react-tabs-6').click() driver.find_element_by_partial_link_text('Create New Model').click() driver.find_element_by_partial_link_text( 'Choose Model Parameters').click() model_select = Select( driver.find_element_by_css_selector('[name=modelType]')) model_select.select_by_visible_text("RandomForestClassifier") driver.implicitly_wait(0.1) driver.find_element_by_xpath( "//label[contains(text(),'n_estimators')]") driver.find_element_by_xpath( "//label[contains(text(),'max_features')]") model_select.select_by_visible_text("RidgeClassifierCV") driver.implicitly_wait(0.1) driver.find_element_by_xpath("//label[contains(text(),'alphas')]") driver.find_element_by_xpath("//label[contains(text(),'scoring')]") model_select.select_by_visible_text("BayesianRidgeRegressor") driver.implicitly_wait(0.1) driver.find_element_by_xpath("//label[contains(text(),'n_iter')]") driver.find_element_by_xpath("//label[contains(text(),'alpha_1')]")
def test_delete_model(driver): driver.get('/') with create_test_project() as p, create_test_featureset(p) as fs,\ create_test_model(fs) as m: driver.refresh() proj_select = Select(driver.find_element_by_css_selector('[name=project]')) proj_select.select_by_value(str(p.id)) driver.find_element_by_id('react-tabs-6').click() driver.find_element_by_partial_link_text('Delete').click() driver.implicitly_wait(1) status_td = driver.find_element_by_xpath( "//div[contains(text(),'Model deleted')]")
def test_predict_raw_data(): with create_test_project() as p, create_test_dataset(p) as ds,\ create_test_featureset(p) as fs, create_test_model(fs) as m: ts_data = [[1, 2, 3, 4], [32.2, 53.3, 32.3, 32.52], [0.2, 0.3, 0.6, 0.3]] impute_kwargs = {'strategy': 'constant', 'value': None} query_string = ('{}/predict_raw_data?ts_data={}' '&modelID={}&impute_kwargs={}').format( cfg['server']['url'], json.dumps(ts_data), json.dumps(m.id), json.dumps(impute_kwargs)) response = requests.post(query_string).json() assert response['status'] == 'success' assert response['data']['0']['features']['total_time'] == 3.0 assert 'Mira' in response['data']['0']['prediction']
def test_prediction_to_csv_class(): """Test util.prediction_to_csv""" with create_test_project() as p, create_test_dataset(p) as ds,\ create_test_featureset(p) as fs,\ create_test_model(fs, model_type='LinearSGDClassifier') as m,\ create_test_prediction(ds, m) as pred: pred = featureset.from_netcdf(pred.file.uri) assert util.prediction_to_csv(pred) ==\ [['ts_name', 'true_target', 'prediction'], ['0', 'Mira', 'Mira'], ['1', 'Classical_Cepheid', 'Classical_Cepheid'], ['2', 'Mira', 'Mira'], ['3', 'Classical_Cepheid', 'Classical_Cepheid'], ['4', 'Mira', 'Mira']]
def test_model_info_display(driver): with create_test_project() as p, create_test_featureset(p) as fs,\ create_test_model(fs) as m: driver.refresh() proj_select = Select(driver.find_element_by_css_selector('[name=project]')) proj_select.select_by_value(str(p.id)) driver.find_element_by_id('react-tabs-6').click() driver.find_element_by_xpath("//td[contains(text(),'{}')]".format(m.name)).click() assert driver.find_element_by_xpath("//th[contains(text(),'Model Type')]")\ .is_displayed() assert driver.find_element_by_xpath("//th[contains(text(),'Hyper " "Parameters')]").is_displayed() assert driver.find_element_by_xpath("//th[contains(text(),'Training " "Data Score')]").is_displayed()
def test_prediction_to_csv_regr(): """Test util.prediction_to_csv""" with create_test_project() as p, create_test_dataset(p, label_type='regr') as ds,\ create_test_featureset(p, label_type='regr') as fs,\ create_test_model(fs, model_type='LinearRegressor') as m,\ create_test_prediction(ds, m) as pred: pred = xr.open_dataset(pred.file.uri) results = util.prediction_to_csv(pred) assert results[0] == ['ts_name', 'true_target', 'prediction'] npt.assert_array_almost_equal( [[float(e) for e in row] for row in results[1:]], [[0, 2.2, 2.2], [1, 3.4, 3.4], [2, 4.4, 4.4], [3, 2.2, 2.2], [4, 3.1, 3.1]])
def test_plot_features(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds,\ create_test_featureset(p) as fs: driver.refresh() proj_select = Select(driver.find_element_by_css_selector('[name=project]')) proj_select.select_by_value(str(p.id)) driver.find_element_by_id('react-tabs-4').click() driver.implicitly_wait(1) driver.find_element_by_xpath("//td[contains(text(),'{}')]".format(fs.name)).click() driver.implicitly_wait(1) driver.find_element_by_xpath("//b[contains(text(),'Please wait while we load your plotting data...')]") driver.implicitly_wait(3) driver.find_element_by_css_selector("[class=svg-container]")
def test_pred_results_table_lsgdc(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds,\ create_test_featureset(p) as fs,\ create_test_model(fs, model_type='LinearSGDClassifier') as m,\ create_test_prediction(ds, m): _click_prediction_row(p.id, driver) try: rows = _grab_pred_results_table_rows(driver, 'Mira') rows = [row.text for row in rows] npt.assert_array_equal([ '0 Mira Mira', '1 Classical_Cepheid Classical_Cepheid', '2 Mira Mira', '3 Classical_Cepheid Classical_Cepheid', '4 Mira Mira' ], rows) except: driver.save_screenshot("/tmp/pred_click_tr_fail.png") raise
def test_delete_prediction(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds,\ create_test_featureset(p) as fs, create_test_model(fs) as m,\ create_test_prediction(ds, m): driver.refresh() proj_select = Select( driver.find_element_by_css_selector('[name=project]')) proj_select.select_by_value(str(p.id)) driver.find_element_by_id('react-tabs-8').click() driver.implicitly_wait(1) driver.find_element_by_xpath( "//td[contains(text(),'Completed')]").click() time.sleep(0.2) driver.find_element_by_partial_link_text('Delete').click() driver.implicitly_wait(1) status_td = driver.find_element_by_xpath( "//div[contains(text(),'Prediction deleted')]")
def test_pred_results_table_regr(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds,\ create_test_featureset(p, label_type='regr') as fs,\ create_test_model(fs, model_type='LinearRegressor') as m,\ create_test_prediction(ds, m): _click_prediction_row(p.id, driver) try: rows = _grab_pred_results_table_rows(driver, '3.4') rows = [[float(el) for el in row.text.split(' ')] for row in rows] npt.assert_array_almost_equal( [[0.0, 2.2, 2.2000000000000006 ], [1.0, 3.4, 3.4000000000000004], [2.0, 4.4, 4.400000000000001], [3.0, 2.2, 2.1999999999999993], [4.0, 3.1, 3.099999999999999]], rows) except: driver.save_screenshot("/tmp/pred_click_tr_fail.png") raise
def test_download_prediction_csv_class(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds,\ create_test_featureset(p) as fs,\ create_test_model(fs, model_type='LinearSGDClassifier') as m,\ create_test_prediction(ds, m): _click_download(p.id, driver) assert os.path.exists('/tmp/cesium_prediction_results.csv') try: npt.assert_equal( np.genfromtxt('/tmp/cesium_prediction_results.csv', dtype='str'), [ 'ts_name,true_target,prediction', '0,Mira,Mira', '1,Classical_Cepheid,Classical_Cepheid', '2,Mira,Mira', '3,Classical_Cepheid,Classical_Cepheid', '4,Mira,Mira' ]) finally: os.remove('/tmp/cesium_prediction_results.csv')
def test_cannot_build_model_unlabeled_data(driver): driver.get('/') with create_test_project() as p,\ create_test_featureset(p, label_type='none') as fs: driver.refresh() proj_select = Select(driver.find_element_by_css_selector('[name=project]')) proj_select.select_by_value(str(p.id)) driver.find_element_by_id('react-tabs-6').click() driver.find_element_by_partial_link_text('Create New Model').click() model_name = driver.find_element_by_css_selector('[name=modelName]') model_name.send_keys(str(uuid.uuid4())) driver.find_element_by_class_name('btn-primary').click() driver.implicitly_wait(2) driver.find_element_by_xpath( "//div[contains(.,'Cannot build model for unlabeled feature set.')]")
def test_pred_results_table_rfc(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds,\ create_test_featureset(p) as fs, create_test_model(fs) as m,\ create_test_prediction(ds, m): _click_prediction_row(p.id, driver) try: rows = _grab_pred_results_table_rows(driver, 'Mira') for row in rows: probs = [ float(v.text) for v in row.find_elements_by_tag_name('td')[3::2] ] assert sorted(probs, reverse=True) == probs driver.find_element_by_xpath( "//th[contains(text(),'Time Series')]") except: driver.save_screenshot("/tmp/pred_click_tr_fail.png") raise
def test_prediction_to_csv_regr(): """Test util.prediction_to_csv""" with create_test_project() as p, create_test_dataset(p, label_type='regr') as ds,\ create_test_featureset(p, label_type='regr') as fs,\ create_test_model(fs, model_type='LinearRegressor') as m,\ create_test_prediction(ds, m) as pred: pred = featureset.from_netcdf(pred.file.uri) results = util.prediction_to_csv(pred) assert results[0] == ['ts_name', 'true_target', 'prediction'] npt.assert_array_almost_equal( [[float(e) for e in row] for row in results[1:]], [[0, 2.2, 2.2], [1, 3.4, 3.4], [2, 4.4, 4.4], [3, 2.2, 2.2], [4, 3.1, 3.1]])
def test_delete_featureset(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds,\ create_test_featureset(p) as fs: driver.refresh() proj_select = Select(driver.find_element_by_css_selector('[name=project]')) proj_select.select_by_value(str(p.id)) driver.find_element_by_id('react-tabs-4').click() driver.find_element_by_partial_link_text('Delete').click() driver.implicitly_wait(1) status_td = driver.find_element_by_xpath( "//div[contains(text(),'Feature set deleted')]") try: el = driver.find_element_by_xpath( "//td[contains(text(),'{}')]".format(test_featureset_name)) except NoSuchElementException: pass else: raise Exception("Featureset still present in table after delete.")
def test_download_prediction_csv_regr(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p, label_type='regr') as ds,\ create_test_featureset(p, label_type='regr') as fs,\ create_test_model(fs, model_type='LinearRegressor') as m,\ create_test_prediction(ds, m): _click_download(p.id, driver) assert os.path.exists('/tmp/cesium_prediction_results.csv') try: results = np.genfromtxt('/tmp/cesium_prediction_results.csv', dtype='str', delimiter=',') npt.assert_equal(results[0], ['ts_name', 'true_target', 'prediction']) npt.assert_array_almost_equal( [[float(e) for e in row] for row in results[1:]], [[0, 2.2, 2.2], [1, 3.4, 3.4], [2, 4.4, 4.4], [3, 2.2, 2.2], [4, 3.1, 3.1]]) finally: os.remove('/tmp/cesium_prediction_results.csv')
def test_delete_featureset(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds,\ create_test_featureset(p) as fs: driver.refresh() proj_select = Select( driver.find_element_by_css_selector('[name=project]')) proj_select.select_by_value(str(p.id)) driver.find_element_by_id('react-tabs-4').click() driver.find_element_by_partial_link_text('Delete').click() driver.implicitly_wait(1) status_td = driver.find_element_by_xpath( "//div[contains(text(),'Feature set deleted')]") try: el = driver.find_element_by_xpath( "//td[contains(text(),'{}')]".format(test_featureset_name)) except NoSuchElementException: pass else: raise Exception("Featureset still present in table after delete.")
def test_plot_features(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds,\ create_test_featureset(p) as fs: driver.refresh() proj_select = Select( driver.find_element_by_css_selector('[name=project]')) proj_select.select_by_value(str(p.id)) driver.find_element_by_id('react-tabs-4').click() driver.implicitly_wait(1) driver.find_element_by_xpath("//td[contains(text(),'{}')]".format( fs.name)).click() driver.implicitly_wait(1) driver.find_element_by_xpath( "//b[contains(text(),'Please wait while we load your plotting data...')]" ) driver.implicitly_wait(3) driver.find_element_by_css_selector("[class=svg-container]")
def test_add_prediction_rfr(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p, label_type='regr') as ds,\ create_test_featureset(p, label_type='regr') as fs,\ create_test_model(fs, model_type='RandomForestRegressor') as m: _add_prediction(p.id, driver)
def test_build_model_lr(driver): driver.get('/') with create_test_project() as p,\ create_test_featureset(p, label_type='regr') as fs: _build_model(p.id, 'LinearRegressor', driver)
def test_build_model_lsgdc(driver): driver.get('/') with create_test_project() as p, create_test_featureset(p) as fs: _build_model(p.id, 'LinearSGDClassifier', driver)
def test_build_model_rfc(driver): driver.get('/') with create_test_project() as p, create_test_featureset(p) as fs: _build_model(p.id, 'RandomForestClassifier', driver)
def test_add_prediction_rfc(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds,\ create_test_featureset(p) as fs, create_test_model(fs) as m: _add_prediction(p.id, driver)
def test_add_prediction_lsgdc(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds,\ create_test_featureset(p) as fs,\ create_test_model(fs, model_type='LinearSGDClassifier') as m: _add_prediction(p.id, driver)