From 93823db63adacc5702a041e6e18d0d004fbb2373 Mon Sep 17 00:00:00 2001 From: Colin Parsons Date: Tue, 15 Oct 2019 17:02:42 -0500 Subject: [PATCH] Reformated test within test_augment.py --- tests/copa/test_augment.py | 69 +++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/tests/copa/test_augment.py b/tests/copa/test_augment.py index 6e8139d..94867ee 100644 --- a/tests/copa/test_augment.py +++ b/tests/copa/test_augment.py @@ -5,7 +5,6 @@ from invisible_flow.constants import COPA_DB_BIND_KEY from invisible_flow.copa.augment import Augment -from invisible_flow.copa.data_allegation_category import AllegationCategory from tests.helpers.if_test_base import IFTestBase from manage import db @@ -13,37 +12,37 @@ class TestAugment: - def test_adding_augmented_copa_record_to_db(self): - # using test file that is not actual copa that has been cleaned/transformed - copa_split_csv = os.path.join(IFTestBase.resource_directory, 'copa_scraped_split.csv') - df = pd.read_csv(copa_split_csv) - clone_df = df - db.create_all(bind=COPA_DB_BIND_KEY) - - categories = df.loc[:, 'current_category'].unique() - - for i in range(len(categories)): - db.session.add(AllegationCategory( - category=categories[i], - category_code=i, - cr_id='cats meow' + str(i) - )) - db.session.commit() - - augmented = Augment().get_augmented_copa_data(copa_split_csv) - - category_code_map = pd.DataFrame( - AllegationCategory.query.with_entities(AllegationCategory.category, AllegationCategory.category_code) - ) - - for category in categories: - category_code = \ - category_code_map.loc[category_code_map['category'] == category]['category_code'].values[0] - clone_df = clone_df.replace(category, category_code) - - assert_frame_equal(augmented, clone_df) - assert len(augmented) == len(df) - assert len(clone_df) == len(df) + # def test_adding_augmented_copa_record_to_db(self): + # # using test file that is not actual copa that has been cleaned/transformed + # copa_split_csv = os.path.join(IFTestBase.resource_directory, 'copa_scraped_split.csv') + # df = pd.read_csv(copa_split_csv) + # clone_df = df + # db.create_all(bind=COPA_DB_BIND_KEY) + # + # categories = df.loc[:, 'current_category'].unique() + # + # for i in range(len(categories)): + # db.session.add(AllegationCategory( + # category=categories[i], + # category_code=i, + # cr_id='cats meow' + str(i) + # )) + # db.session.commit() + # + # augmented = Augment().get_augmented_copa_data(copa_split_csv) + # + # category_code_map = pd.DataFrame( + # AllegationCategory.query.with_entities(AllegationCategory.category, AllegationCategory.category_code) + # ) + # + # for category in categories: + # category_code = \ + # category_code_map.loc[category_code_map['category'] == category]['category_code'].values[0] + # clone_df = clone_df.replace(category, category_code) + # + # assert_frame_equal(augmented, clone_df) + # assert len(augmented) == len(df) + # assert len(clone_df) == len(df) def test_adding_augmented_copa_record_to_db_no_category_matches(self): copa_split_csv = os.path.join(IFTestBase.resource_directory, 'copa_scraped_split.csv') @@ -57,10 +56,10 @@ def test_adding_augmented_copa_record_to_db_no_category_matches(self): def test_adding_augmented_copa_record_to_db(self): # using test file that is not actual copa that has been cleaned/transformed - copa_csv_file = os.path.join(IFTestBase.resource_directory, 'copa_scraped_split.csv') original_dataframe = pd.read_csv(copa_csv_file) db.create_all(bind=COPA_DB_BIND_KEY) + log_no_column = original_dataframe.loc[:, 'log_no'].unique() categories_column = original_dataframe.loc[:, 'current_category'].unique() augmented_dataframe = Augment().get_augmented_copa_data(copa_csv_file) @@ -70,5 +69,5 @@ def test_adding_augmented_copa_record_to_db(self): assert augmented_dataframe is not None assert original_dataframe.equals(augmented_dataframe) - print("orginal" , original_dataframe.loc[:, 'current_category'] , "/n") - print("augmented" , augmented_dataframe.loc[:, 'current_category']) \ No newline at end of file + print("orginal", original_dataframe.loc[:, 'current_category'], "/n") + print("augmented", augmented_dataframe.loc[:, 'current_category'])