Skip to content

Commit

Permalink
Reformated test within test_augment.py
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-parsons committed Oct 15, 2019
1 parent 3bf9e99 commit 93823db
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions tests/copa/test_augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,44 @@

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


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')
Expand All @@ -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)
Expand All @@ -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'])
print("orginal", original_dataframe.loc[:, 'current_category'], "/n")
print("augmented", augmented_dataframe.loc[:, 'current_category'])

0 comments on commit 93823db

Please sign in to comment.