Skip to content

Commit b996b8f

Browse files
authored
(tests) add workaround to enable deltalake to use AWS profile creds (#1934)
* Tests - add workaround to enable deltalake to use AWS profile creds * Remove fixture * Fix Duplicate AWS_S3_ALLOW_UNSAFE_RENAME when overwrite_schema=True
1 parent a5c8282 commit b996b8f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

tests/test_s3_deltalake.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
1+
import boto3
12
import pandas as pd
23
import pytest
34
from deltalake import DeltaTable, write_deltalake
45

56
import awswrangler as wr
67

78

8-
@pytest.fixture(scope="session")
9-
def storage_options():
10-
return {"AWS_S3_ALLOW_UNSAFE_RENAME": "TRUE"}
9+
def _get_storage_options():
10+
credentials = boto3.Session().get_credentials().get_frozen_credentials()
11+
return {
12+
"AWS_S3_ALLOW_UNSAFE_RENAME": "TRUE",
13+
"AWS_ACCESS_KEY_ID": credentials.access_key,
14+
"AWS_SECRET_ACCESS_KEY": credentials.secret_key,
15+
"AWS_SESSION_TOKEN": credentials.token,
16+
}
1117

1218

1319
@pytest.mark.parametrize("s3_additional_kwargs", [None, {"ServerSideEncryption": "AES256"}])
1420
@pytest.mark.parametrize("pyarrow_additional_kwargs", [None, {"safe": True, "deduplicate_objects": False}])
15-
def test_read_deltalake(path, s3_additional_kwargs, pyarrow_additional_kwargs, storage_options):
21+
def test_read_deltalake(path, s3_additional_kwargs, pyarrow_additional_kwargs):
1622
df = pd.DataFrame({"c0": [1, 2, 3], "c1": ["foo", None, "bar"], "c2": [3.0, 4.0, 5.0], "c3": [True, False, None]})
17-
write_deltalake(table_or_uri=path, data=df, storage_options=storage_options)
23+
write_deltalake(table_or_uri=path, data=df, storage_options=_get_storage_options())
1824

1925
df2 = wr.s3.read_deltalake(
2026
path=path, s3_additional_kwargs=s3_additional_kwargs, pyarrow_additional_kwargs=pyarrow_additional_kwargs
2127
)
2228
assert df2.equals(df)
2329

2430

25-
def test_read_deltalake_versioned(path, storage_options):
31+
def test_read_deltalake_versioned(path):
2632
df = pd.DataFrame({"c0": [1, 2, 3], "c1": ["foo", "baz", "bar"]})
33+
storage_options = _get_storage_options()
2734
write_deltalake(table_or_uri=path, data=df, storage_options=storage_options)
2835
table = DeltaTable(path, version=0, storage_options=storage_options)
2936

@@ -40,9 +47,9 @@ def test_read_deltalake_versioned(path, storage_options):
4047
assert df4.equals(df)
4148

4249

43-
def test_read_deltalake_partitions(path, storage_options):
50+
def test_read_deltalake_partitions(path):
4451
df = pd.DataFrame({"c0": [1, 2, 3], "c1": [True, False, True], "par0": ["foo", "foo", "bar"], "par1": [1, 2, 2]})
45-
write_deltalake(table_or_uri=path, data=df, partition_by=["par0", "par1"], storage_options=storage_options)
52+
write_deltalake(table_or_uri=path, data=df, partition_by=["par0", "par1"], storage_options=_get_storage_options())
4653

4754
df2 = wr.s3.read_deltalake(path=path, columns=["c0"], partitions=[("par0", "=", "foo"), ("par1", "=", "1")])
4855
assert df2.shape == (1, 1)

0 commit comments

Comments
 (0)