basedata.ops.tests package

Submodules

basedata.ops.tests.test_base module

Unit-tests for basedata.ops.base submodule

class basedata.ops.tests.test_base.BaseDataClassTests(methodName='runTest')

Bases: unittest.case.TestCase

Tests to ensure class data.BaseDataClass functions properly

test_from_file_csv()

ensure csv is read and stored to BaseDataClass class

test_from_file_fail()

ensure from_file fails elegantly with wrong filetype read

test_from_file_inputdf_persists()

ensure input_df persist only when specified

test_from_file_xls()

ensure xls is read and stored to BaseDataClass class

test_from_file_xlsx()

ensure xlsx is read and stored to BaseDataClass class

test_from_object_class()

ensure class.df object is read and stored to BaseDataClass class

test_from_object_df()

ensure dataframe object is read and stored to BaseDataClass class

test_from_object_fail()

ensure from_object fails elegantly with invalid object

test_to_file()

ensure to_file saves self.df to disk

class basedata.ops.tests.test_base.MiscFunctionsTest(methodName='runTest')

Bases: unittest.case.TestCase

unittests for misc functions located in data/ids submodule

test_inplace_return_series_inplace()

ensure inplace_return_series makes inplace changes

test_inplace_return_series_inplace_target_col()

ensure inplace_return_series makes inplace changes to target_col

test_inplace_return_series_return()

ensure inplace_return_series returns series

test_regex_replace_value()

ensures sub_value_regex returns accurate values

test_regex_sub_value()

ensures sub_value_regex returns accurate values

basedata.ops.tests.test_cols module

Unittests for basedata.ops.cols submodule

class basedata.ops.tests.test_cols.ColumnConversionsMixinTests(methodName='runTest')

Bases: unittest.case.TestCase

unittests for data.cols ColumnConversionsMixin class

create_ColumnConversions_class(df)

returns ColumnConversionsMixin instance for reuse in TestCase

test_add_column()

ensure add_column appends new column to self.df

test_apply_function_lambda()

ensure apply_function works with lambda function

test_apply_function_multicol()

ensure apply_function works when applied to multiple columns

test_apply_function_raises_value_error()

ensure apply_function raises error for inplace no target_column

test_apply_function_saves_target_column()

ensure apply_function saves inplace to target_column

test_check_datetime()

ensure check_datetime returns value counts for all errors

test_check_nonnumeric()

ensure check_numeric returns value counts for all errors

test_map_column_names_inplace()

ensure map_column_names accurately maps names inplace

test_map_column_names_return()

ensure map_column_names returns df and not inplace when False

test_map_values_exhaustive()

ensure map_values accurately maps values

test_map_values_not_exhaustive()

ensure map_values accurately maps values

test_report_values()

ensure report_values reports all values and returns series

test_substitute_chars()

ensure substitute_chars strips non-match characters from column

test_to_datetime_coerce()

ensure to_datetime returns only numerics with coerce default

test_to_datetime_coerce_false()

ensure to_datetime returns non-numeric values with coerce=False

test_to_numeric_coerce()

ensure to_numeric returns only numerics with coerce default

test_to_numeric_coerce_false()

ensure to_numeric returns non-numeric values with coerce=False

basedata.ops.tests.test_databuild module

This test submodule contains the functions and accompanying unit-tests used to build the test datasets that are reused among the various basedata.ops modules’ unit-tests

class basedata.ops.tests.test_databuild.DatabuildTests(methodName='runTest')

Bases: unittest.case.TestCase

unittests for test databuild functions

test_generate_random_datetime_object()

ensures datetime object is generated

test_generate_random_datetime_str()

ensures datetime string is generated

test_generate_random_int()

ensures specified random id generated

test_make_dataframe()

ensure accurate df returned

test_make_datetime_dict()

ensure accurate dict returned

test_make_dirt_dict()

ensure accurate dict returned

test_make_dirty_datetime_dataframe()

ensure make_dirty_ids returns accurate dataframe

test_make_dirty_ids_dataframe()

ensure make_dirty_ids returns accurate dataframe

test_make_dirty_numeric_dataframe()

ensure make_dirty_ids returns accurate dataframe

test_make_id_dict()

ensure accurate dict returned

test_make_simple_dataframe()

ensure make_simple_dataframe returns dataframe type

test_make_twocol_dataframe()

ensure make_twocol_datafram returns two column dataframe

test_merge_dicts()

ensure merged dict returned

test_save_dataframe_csv()

ensure csv is saved

test_save_dataframe_excel()

ensure excel is saved

test_save_dataframe_excel_xml()

ensure excel xml format is saved

test_save_simple_dataframe()

ensure save_simple_dataframe returns fp, df, and path exists

basedata.ops.tests.test_databuild.generate_random_datetime(start=datetime.datetime(2007, 1, 1, 0, 0), end=datetime.datetime(2017, 1, 1, 0, 0), string=True)

returns random datetime between two datetime objects

basedata.ops.tests.test_databuild.generate_random_int(int_len=8)

returns a random integer (i.e. ID number) of given length

basedata.ops.tests.test_databuild.make_dataframe(dicts_list)

builds test dataframe using list of dicts

basedata.ops.tests.test_databuild.make_datetime_dict(n=5, keyname='datetime')

generates dict containing randomly generated datetimes

basedata.ops.tests.test_databuild.make_dirt_dict(clean_dict, keyname, dirt_list)

generates updated dict with dirt values appended

basedata.ops.tests.test_databuild.make_dirty_datetime_dataframe(keycol='test')

returns df with dirty IDs column for reuse in unittests

basedata.ops.tests.test_databuild.make_dirty_ids_dataframe(keycol='test')

returns df with dirty IDs column for reuse in unittests

basedata.ops.tests.test_databuild.make_dirty_numeric_dataframe(keycol='test')

returns df with dirty IDs column for reuse in unittests

basedata.ops.tests.test_databuild.make_id_dict(n=5, int_len=8, keyname='id')

generates dict containing randomly generated IDs

basedata.ops.tests.test_databuild.make_simple_dataframe()

builds and returns simple dataframe for TestCase reuse

basedata.ops.tests.test_databuild.make_twocol_dataframe(colname_1='col1', colname_2='col2', n=5)

builds two column dataframe of random digits for TestCase reuse

basedata.ops.tests.test_databuild.merge_dicts(dicts_list)

generates a single dict from an arbitrary number of separate dicts

basedata.ops.tests.test_databuild.save_dataframe(dataframe, filename, **to_kwargs)

saves df to file, type is either csv or xlsx based on extension

basedata.ops.tests.test_databuild.save_simple_dataframe(tmp_dir, filename)

saves simple dataframe for TestCase reuse

basedata.ops.tests.test_ids module

Unittests for basedata.ops.ids submodule

class basedata.ops.tests.test_ids.DedupeMixinTests(methodName='runTest')

Bases: unittest.case.TestCase

unittests for DedupeMixin class methods

create_Dedupe_class()

returns DedupeMixin instance for reuse in TestCase

test_check_dupes_hasattr()

ensure accurate df saves to duperecords if attr does exist

test_check_dupes_not_hasattr()

ensure accurate df saves to duperecords if attr does not exist

test_drop_dupes_drop()

ensure drop_dupes drops rows from self.df

test_drop_dupes_validate()

ensure drop_dupes raises exception when validate==True

test_flush_duperecords_del()

ensure flush_duperecords deletes class attribute

test_flush_duperecords_pass()

ensure flush_duperecords pass when class attribute doesn’t exist

test_report_dupes_returns()

ensure report_dupes returns accurate df

test_report_dupes_to_file()

ensure report_dupes saves .csv when to_file specified

test_report_dupes_to_file_index()

ensure report_dupes saves .csv when to_file specified

class basedata.ops.tests.test_ids.ValidIDsMixinTests(methodName='runTest')

Bases: unittest.case.TestCase

unittests for ValidIDsMixin class methods

create_ValidIDs_class()

returns DedupeMixin instance for reuse in TestCase

test_drop_blankID_rows()

ensure blankID rows are dropped from dataframe and index reset

test_remove_offlenIDs()

ensure offlenIDs replaced with np.nan values

test_remove_offlenIDs_return_series()

ensure offlenIDs replaced with np.nan values

test_replace_blankIDs()

ensure blank ids are replaced with values from target column

test_replace_blankIDs_return_series()

ensure blank ids are replaced with values from target column

test_report_offlenIDs()

ensure report_offlenIDs returns accurate value_counts series

test_strip_nonnumeric()

ensure strip_nonnumeric strips nonnumeric characters from column

test_strip_nonnumeric_returns_series()

ensure strip_nonnumeric returns series when specified

basedata.ops.tests.tests module

Unittests for base.data.ops submodule __init__.py code

class basedata.ops.tests.tests.BaseDataOpsTests(methodName='runTest')

Bases: unittest.case.TestCase

unittests for base.BaseDataOps class

test_BaseDataOps_invoke()

ensure BaseDataOps.from_object invokes __init__ of parent class

Module contents