def test_check_uncheck_features(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds: 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('Compute New Features').click() driver.find_element_by_xpath("//li[contains(text(),'General')]").click() amplitude = driver.find_element_by_css_selector('[name=amplitude]') assert amplitude.get_attribute('value') == 'true' driver.find_element_by_partial_link_text('Check/Uncheck All').click() time.sleep(0.3) assert amplitude.get_attribute('value') == 'false' driver.find_element_by_partial_link_text('Check/Uncheck All').click() time.sleep(0.1) assert amplitude.get_attribute('value') == 'true' driver.find_element_by_xpath("//li[contains(.,'Cadence')]").click() n_epochs = driver.find_element_by_css_selector('[name=n_epochs]') assert n_epochs.get_attribute('value') == 'true' driver.find_element_by_partial_link_text('Check/Uncheck All').click() time.sleep(0.1) assert n_epochs.get_attribute('value') == 'false' driver.find_element_by_xpath("//li[contains(.,'Lomb-Scargle')]").click() driver.find_element_by_partial_link_text('Check/Uncheck All').click() assert driver.find_element_by_css_selector( '[name=fold2P_slope_10percentile]').get_attribute('value') == 'false'
def test_add_new_featureset(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds: 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( 'Compute New Features').click() featureset_name = driver.find_element_by_css_selector( '[name=featuresetName]') featureset_name.send_keys(test_featureset_name) driver.find_element_by_class_name('btn-primary').click() driver.implicitly_wait(1) status_td = driver.find_element_by_xpath( "//div[contains(text(),'Feature computation begun')]") status_td = driver.find_element_by_xpath( "//td[contains(text(),'In progress')]") driver.implicitly_wait(30) status_td = driver.find_element_by_xpath( "//td[contains(text(),'Completed')]")
def test_check_uncheck_tags(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds: 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( 'Compute New Features').click() driver.find_element_by_partial_link_text('Filter By Tag').click() driver.find_element_by_xpath( "//li[contains(text(),'General')]").click() driver.find_element_by_css_selector('[name=amplitude]') driver.find_element_by_css_selector('[label=Astronomy]').click() time.sleep(0.1) driver.find_element_by_css_selector('[label=General]').click() time.sleep(0.1) with pytest.raises(NoSuchElementException): driver.find_element_by_css_selector('[name=amplitude]').click() driver.find_element_by_css_selector('[label=General]').click() driver.implicitly_wait(1) driver.find_element_by_css_selector('[name=amplitude]')
def test_dataset_delete(): """Test that deleting a `Dataset` also removes any associated files.""" with create_test_project() as p: ds = create_test_dataset(p).__enter__() # skip cleanup step uris = ds.uris assert all(os.path.exists(f) for f in uris) ds.delete_instance() assert not any(os.path.exists(f) for f in uris)
def test_delete_dataset(driver): with create_test_project() as p, create_test_dataset(p) as ds: 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-2').click() driver.find_element_by_partial_link_text('Delete').click() driver.implicitly_wait(1) status_td = driver.find_element_by_xpath( "//div[contains(text(),'Dataset deleted')]")
def test_delete_dataset(driver): with create_test_project() as p, create_test_dataset(p) as ds: 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-2').click() driver.find_element_by_partial_link_text('Delete').click() driver.implicitly_wait(1) status_td = driver.find_element_by_xpath( "//div[contains(text(),'Dataset deleted')]")
def test_dataset_info_display(driver): with create_test_project() as p, create_test_dataset(p) as ds: 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-2').click() driver.find_element_by_xpath("//td[contains(text(),'{}')]".format(ds.name)).click() assert driver.find_element_by_xpath("//th[contains(text(),'Time Series " "File Names')]").is_displayed() assert driver.find_element_by_xpath("//th[contains(text(),'Meta " "Features')]").is_displayed()
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_dataset_info_display(driver): with create_test_project() as p, create_test_dataset(p) as ds: 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-2').click() driver.find_element_by_xpath("//td[contains(text(),'{}')]".format( ds.name)).click() assert driver.find_element_by_xpath( "//th[contains(text(),'Time Series " "File Names')]").is_displayed() assert driver.find_element_by_xpath("//th[contains(text(),'Meta " "Features')]").is_displayed()
def test_feature_descriptions_displayed(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds: 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('Compute New Features').click() driver.find_element_by_xpath("//li[contains(text(),'General')]").click() driver.implicitly_wait(0.5) driver.find_element_by_xpath( "//div[contains(.,'Half the difference between the maximum and " "minimum magnitude.')]")
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_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_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_feature_descriptions_displayed(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds: 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( 'Compute New Features').click() driver.find_element_by_xpath( "//li[contains(text(),'General')]").click() driver.implicitly_wait(0.5) driver.find_element_by_xpath( "//div[contains(.,'Half the difference between the maximum and " "minimum magnitude.')]")
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_cannot_compute_zero_features(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds: 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( 'Compute New Features').click() driver.find_element_by_xpath( "//li[contains(text(),'General')]").click() amplitude = driver.find_element_by_css_selector('[name=amplitude]') assert amplitude.get_attribute('value') == 'true' driver.find_element_by_partial_link_text('Check/Uncheck All').click() time.sleep(0.1) assert amplitude.get_attribute('value') == 'false' driver.find_element_by_xpath("//li[contains(.,'Cadence')]").click() n_epochs = driver.find_element_by_css_selector('[name=n_epochs]') assert n_epochs.get_attribute('value') == 'true' driver.find_element_by_partial_link_text('Check/Uncheck All').click() time.sleep(0.1) assert n_epochs.get_attribute('value') == 'false' driver.find_element_by_xpath( "//li[contains(.,'Lomb-Scargle')]").click() driver.find_element_by_partial_link_text('Check/Uncheck All').click() assert driver.find_element_by_css_selector( '[name=fold2P_slope_10percentile]').get_attribute( 'value') == 'false' featureset_name = driver.find_element_by_css_selector( '[name=featuresetName]') featureset_name.send_keys(test_featureset_name) driver.find_element_by_class_name('btn-primary').click() driver.implicitly_wait(1) driver.find_element_by_xpath( "//div[contains(.,'At least one feature must be selected')]")
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_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_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_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_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_new_featureset(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds: 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('Compute New Features').click() featureset_name = driver.find_element_by_css_selector('[name=featuresetName]') featureset_name.send_keys(test_featureset_name) driver.find_element_by_class_name('btn-primary').click() driver.implicitly_wait(1) status_td = driver.find_element_by_xpath( "//div[contains(text(),'Feature computation begun')]") status_td = driver.find_element_by_xpath("//td[contains(text(),'In progress')]") driver.implicitly_wait(30) status_td = driver.find_element_by_xpath("//td[contains(text(),'Completed')]")
def test_check_uncheck_tags(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds: 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('Compute New Features').click() driver.find_element_by_partial_link_text('Filter By Tag').click() driver.find_element_by_xpath("//li[contains(text(),'General')]").click() driver.find_element_by_css_selector('[name=amplitude]') driver.find_element_by_css_selector('[label=Astronomy]').click() time.sleep(0.1) driver.find_element_by_css_selector('[label=General]').click() time.sleep(0.1) with pytest.raises(NoSuchElementException): driver.find_element_by_css_selector('[name=amplitude]').click() driver.find_element_by_css_selector('[label=General]').click() driver.implicitly_wait(1) driver.find_element_by_css_selector('[name=amplitude]')
def test_check_uncheck_features(driver): driver.get('/') with create_test_project() as p, create_test_dataset(p) as ds: 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( 'Compute New Features').click() driver.find_element_by_xpath( "//li[contains(text(),'General')]").click() amplitude = driver.find_element_by_css_selector('[name=amplitude]') assert amplitude.get_attribute('value') == 'true' driver.find_element_by_partial_link_text('Check/Uncheck All').click() time.sleep(0.3) assert amplitude.get_attribute('value') == 'false' driver.find_element_by_partial_link_text('Check/Uncheck All').click() time.sleep(0.1) assert amplitude.get_attribute('value') == 'true' driver.find_element_by_xpath("//li[contains(.,'Cadence')]").click() n_epochs = driver.find_element_by_css_selector('[name=n_epochs]') assert n_epochs.get_attribute('value') == 'true' driver.find_element_by_partial_link_text('Check/Uncheck All').click() time.sleep(0.1) assert n_epochs.get_attribute('value') == 'false' driver.find_element_by_xpath( "//li[contains(.,'Lomb-Scargle')]").click() driver.find_element_by_partial_link_text('Check/Uncheck All').click() assert driver.find_element_by_css_selector( '[name=fold2P_slope_10percentile]').get_attribute( 'value') == 'false'
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_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_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)