def test_merge_in_file_fails(test_data_path, data_generator): """ Check that error is raised if argument isn't an iterable of pandas data structures. """ output = os.path.join(test_data_path, "merge_fail.csv") remove_file(output) with pytest.raises(TypeError): merge_in_file(output, 12)
def test_to_file_fails(test_data_path, to_file_frame): """ Check error raises when writing to file non-pandas entity. """ output = os.path.join(test_data_path, "to_file.csv") remove_file(output) with pytest.raises(AttributeError): to_file([1, 2, 3], test_data_path, "to_file.csv")
def test_to_file(test_data_path, to_file_frame): """ Check write to file works """ output = os.path.join(test_data_path, "to_file.csv") remove_file(output) to_file(to_file_frame, test_data_path, "to_file.csv") frm = pd.read_csv(output) assert frm["A"].sum() == 6
def test_merge_in_file(test_data_path, data_generator): """ Check that files can be merged in a temporary file """ output = os.path.join(test_data_path, "merged_data.csv") remove_file(output) gen = data_generator(10, 5, 2) merge_in_file(output, gen) frame = pd.read_csv(output) n_cases, k = frame.shape assert n_cases == 10 * 5 assert k == 2
def test_merge_in_file_repetition(test_data_path, data_generator): """ Check that files can be merged in a temporary file when function called twice. """ output = os.path.join(test_data_path, "merged_data.csv") remove_file(output) gen = data_generator(10, 5, 2) merge_in_file(output, gen) gen = data_generator(10, 5, 2) merge_in_file(output, gen, delete_file=True) frame = pd.read_csv(output) n_cases, k = frame.shape assert n_cases == 10 * 5 assert k == 2