Exemple #1
0
def test_blob_df():
    name = gen_name()

    # upload the blob
    with deletable(dp.Blob.upload_df(df=df, name=name)) as b1:
        # are fields added?
        check_name(b1, name)
        # was the import as expected?
        assert b1.num_rows == 4
        assert b1.num_columns == 2
        assert b1.cells == 8

        # download
        df1 = b1.download_df()

        # is the exported df as expected?
        assert df1.size == b1.cells
        assert df1.shape == (b1.num_rows, b1.num_columns)
        check_df_equal(df1, df)

        # test obj lookup using name
        b2 = dp.Blob.get(b1.name)
        assert b2.name == b1.name
        # test obj lookup using id
        b3 = dp.Blob.by_id(b1.id)
        assert b3.name == b2.name
Exemple #2
0
def test_blob_csv_export(tmp_path: Path):
    # upload a df file
    b1 = dp.Blob.upload_df(df, name=gen_name())

    with deletable(b1):
        # export back to a csv and compare
        fn1 = tmp_path / "exported.csv"
        b1.download_file(fn1)
        df1 = pd.read_csv(fn1)
        check_df_equal(df, df1)
        # export back to excel and compare
        fn2 = tmp_path / "exported.xlsx"
        b1.download_file(fn2)
        df2 = pd.read_excel(fn2, engine="openpyxl")
        check_df_equal(df, df2)
Exemple #3
0
def test_blob_csv(tmp_path: Path):
    # upload a csv file
    # TODO - use df_processor?
    fn = tmp_path / "initial.csv"
    df.to_csv(fn, index=False)
    b1 = dp.Blob.upload_file(fn, name=gen_name())

    with deletable(b1):
        # export back to a csv and compare
        fn1 = tmp_path / "exported.csv"
        b1.download_file(fn1)
        df1 = pd.read_csv(fn1)
        check_df_equal(df, df1)
        # export back to excel and compare
        fn2 = tmp_path / "exported.xlsx"
        b1.download_file(fn2)
        df2 = pd.read_excel(fn2, engine="openpyxl")
        check_df_equal(df, df2)