def test_invalidate(): """Test whether the invalidate function turns the value of the 'Valid' column to False in a given set of well ids, columns and rows.""" example_platemap = pd.read_csv(inval_platemap, index_col=[0]) # read in an example platemap with invalidated well ids, rows and columns test_object = fa.read_in_envision(data_csv=plate_2_repeat, platemap_csv=plate_map_file, data_type='plate', size=384) # read in actual data and plate map test_object.invalidate(wells=['A2', 'B3', 'E4'], rows=['C', 'G'], columns=[7,8,12,20]) # invalidate specific well ids, rows and columns pd.testing.assert_frame_equal(test_object.plate_map, example_platemap, check_dtype=False) # compare the two dfs without checking the data types because the example df was not read in using the read_in_envision function
def test_background_correct(): """Tests whether the background correction function performs correct calculations to get the background corrected values of p and s channel signal""" with open(HsHis6_PEX5C_vs_HsPEX5C_p_s_corrected, 'rb') as file: # load the list with expexcted data frames from .pkl file expected_list = pickle.load(file) test_object = fa.read_in_envision(data_csv=HsHis6_PEX5C_vs_HsPEX5C, platemap_csv=Hs_His6_PEX5C_vs_HsPEX5C_platemap, data_type='plate', size=384) # execute the tested function test_object.background_correct() # assert the p_corrected and s_corrected data frames are the same as the reference data frames pd.testing.assert_frame_equal(test_object.data_dict['repeat_1']['data']['p_corrected'], expected_list[0], atol=1E-6) pd.testing.assert_frame_equal(test_object.data_dict['repeat_1']['data']['s_corrected'], expected_list[1], atol=1E-6)
def test_calculate_r_i(): """Tests whether the calculate_r_I function performs correct calculations to get the raw and background corrected values of intensity and anisotropy""" with open(HsHis6_PEX5C_vs_HsPEX5C_calc_r_I, 'rb') as file: # load the list with expexcted data frames from .pkl file expected_list = pickle.load(file) test_object = fa.read_in_envision(data_csv=HsHis6_PEX5C_vs_HsPEX5C, platemap_csv=Hs_His6_PEX5C_vs_HsPEX5C_platemap, data_type='plate', size=384) test_object.background_correct() test_object.calculate_r_i(correct=True, plot_i=False, thr=50) pd.testing.assert_frame_equal(test_object.data_dict['repeat_1']['data']['i_raw'], expected_list[0], atol=1E-6) pd.testing.assert_frame_equal(test_object.data_dict['repeat_1']['data']['r_raw'], expected_list[1], atol=1E-6) pd.testing.assert_frame_equal(test_object.data_dict['repeat_1']['data']['i_corrected'], expected_list[2], atol=1E-6) pd.testing.assert_frame_equal(test_object.data_dict['repeat_1']['data']['r_corrected'], expected_list[3], atol=1E-6) pd.testing.assert_frame_equal(test_object.data_dict['repeat_1']['data']['i_percent'], expected_list[4], atol=1E-6)
def _get_testing_data(data_csv, platemap_csv, data_type, size, pkl_file): with open(pkl_file, 'rb') as file: # load the list with expexcted data frames from .pkl file expected_list = pickle.load(file) actual_output = fa.read_in_envision(data_csv = data_csv, platemap_csv=platemap_csv, data_type=data_type, size=size) # execute the tested function actual_g = actual_output.g_factor actual_list = [] for repeat in actual_output.data_dict.values(): # unpack the dictionary with df from the tested function metadata, data = repeat.values() p_channel, s_channel = data.values() actual_list.append(metadata) actual_list.append(p_channel) actual_list.append(s_channel) return actual_list, expected_list, actual_g
def test_no_backg_subt(): """Test for an error raised if the calculate_r_i function is called with the correct parameter as True prior to the background subtraction""" test_object = fa.read_in_envision(data_csv=HsHis6_PEX5C_vs_HsPEX5C, platemap_csv=Hs_His6_PEX5C_vs_HsPEX5C_platemap, data_type='plate', size=384) test_object.calculate_r_i(correct=True, plot_i=False, thr=80)
def test_invalidate_error(): """Test whether the 'invalidate' function raises an error if no arguments are passed.""" test_object = fa.read_in_envision(data_csv=plate_2_repeat, platemap_csv=plate_map_file, data_type='plate', size=384) test_object.invalidate() # execute the invalidate function without specifying well ids, rows or columns to be invalidated
def test_incorrect_data_type(): """Test for error if data_type argument is neither plate nor list.""" test_object = fa.read_in_envision(data_csv=list_A, platemap_csv=plate_map_file, data_type='typo', size=384)
def test_incorrect_data_type_plate(): """Test for error if data_type = plate but raw data file is in list format.""" test_object = fa.read_in_envision(data_csv=list_A, platemap_csv=plate_map_file, data_type='plate', size=384)
def test_incorrect_data_type_list(): """Test for error if data_type = list but raw data file is in plate format.""" test_object = fa.read_in_envision(data_csv=plate_1, platemap_csv=plate_map_file, data_type='list', size=384)
def test_plate_size_error(): """Test for error raised if size is not 384 or 96.""" test_object = fa.read_in_envision(data_csv=plate_1, platemap_csv=plate_map_file, data_type='plate', size=100)