Esempio n. 1
0
def test_read_csvs_zero_csv_path():
    # Setup
    # When no CSV files are on disk

    # When reading files the functions raises ValueError.
    try:
        io.read_csvs("nofilesondisk.csv")
        raise Exception
    except ValueError:
        pass
    finally:
        remove_csv_files()
Esempio n. 2
0
def test_read_csvs_two_unmatching_csv_files():
    # Setup
    # When two csv files do not have same column names
    df = pd.DataFrame([[1, 2, 3], [1, 2, 3], [1, 2, 3]],
                      columns=["a", "b", "c"])
    df.to_csv(CSV_FILE_PATH.format(0), index=False)
    df = pd.DataFrame([[1, 2, 3], [1, 2, 3], [1, 2, 3]],
                      columns=["d", "e", "f"])
    df.to_csv(CSV_FILE_PATH.format(1), index=False)

    # If the csv files are read into DataFrame
    try:
        io.read_csvs(CSV_FILE_PATH.format("*"))
        # if read does read the unmatching files give an error
        raise ValueError
    except ValueError:
        # If the read raises an exception it is ok
        pass
    finally:
        remove_csv_files()
Esempio n. 3
0
def test_read_csvs_three_csv_path():
    # Setup
    # When a CSV file with 3 cols and 3 rows is on disk
    create_csv_file(3)

    # If the csv file is read into DataFrame
    dfs = io.read_csvs(CSV_FILE_PATH.format("*"))

    # Then the dataframe has 3 cols and 9 rows
    try:
        assert len(dfs.columns) == 3
        assert len(dfs) == 9
    finally:
        # Cleanup
        remove_csv_files()
Esempio n. 4
0
def test_read_csvs_three_csv_path():
    # Setup
    # When a CSV file with 3 cols and 4 rows is on disk
    number_of_files = 3
    create_csv_file(number_of_files)

    # If the csv file is read into DataFrame
    df = io.read_csvs(CSV_FILE_PATH.format("*"))

    # Then the dataframe has 3 cols and 12 rows
    try:
        assert len(df.columns) == 3
        assert len(df) == 4 * number_of_files
    finally:
        # Cleanup
        remove_csv_files()
Esempio n. 5
0
def test_read_csvs_three_separated_csv_path():
    # Setup
    # When a CSV file with 3 cols and 3 rows is on disk
    create_csv_file(3)

    # If the csv file is read into DataFrame
    dfs = io.read_csvs(CSV_FILE_PATH.format("*"), seperate_df=True)

    # Then the dataframe list has 3 dataframes
    try:
        assert len(dfs) == 3
        for df in dfs.values():
            assert len(df) == 3
            assert len(df.columns) == 3
    finally:
        # Cleanup
        remove_csv_files()
Esempio n. 6
0
def test_read_csvs_three_separated_csv_path():
    # Setup
    # When a CSV file with 3 cols and 4 rows is on disk
    number_of_files = 3
    create_csv_file(number_of_files)

    # If the csv file is read into DataFrame
    dfs_dict = io.read_csvs(CSV_FILE_PATH.format("*"), separate_df=True)

    # Then the dataframe list has 3 dataframes
    try:
        assert len(dfs_dict) == number_of_files
        for df in dfs_dict.values():  # noqa: PD011
            assert len(df) == 4
            assert len(df.columns) == 3
    finally:
        # Cleanup
        remove_csv_files()
Esempio n. 7
0
def test_read_csvs_lists():
    # Setup
    # When a CSV file with 3 cols and 4 rows is on disk
    number_of_files = 3
    create_csv_file(number_of_files)
    csvs_list = [CSV_FILE_PATH.format(i) for i in range(number_of_files)]

    # If the list of csv files is read into DataFrame
    dfs_list = io.read_csvs(files_path=csvs_list, separate_df=True)

    # Then the dataframe list has 3 dataframes
    try:
        assert len(dfs_list) == number_of_files
        for df in dfs_list.values():  # noqa: PD011
            assert len(df) == 4
            assert len(df.columns) == 3
    finally:
        # Cleanup
        remove_csv_files()