Skip to content

Commit 861fb35

Browse files
Increase coverage for dynamodb _write (#1893)
1 parent 2520f57 commit 861fb35

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tests/conftest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from datetime import datetime
23
from importlib import reload
34
from types import ModuleType
@@ -378,6 +379,18 @@ def glue_data_quality_role(cloudformation_outputs):
378379
return cloudformation_outputs["GlueDataQualityRole"]
379380

380381

382+
@pytest.fixture(scope="function")
383+
def local_filename() -> Iterator[str]:
384+
filename = os.path.join(".", f"{get_time_str_with_random_suffix()}.data")
385+
386+
yield filename
387+
388+
try:
389+
os.remove(filename)
390+
except OSError:
391+
pass
392+
393+
381394
@pytest.fixture(scope="function", name="wr")
382395
def awswrangler_import() -> Iterator[ModuleType]:
383396
import awswrangler

tests/test_moto.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
from typing import Any
34
from unittest import mock
45
from unittest.mock import ANY
56

@@ -521,6 +522,31 @@ def test_dynamodb_basic_usage(moto_dynamodb):
521522
assert table.item_count == 0
522523

523524

525+
@pytest.mark.parametrize("format", ["csv", "json"])
526+
def test_dynamodb_put_from_file(moto_dynamodb: Any, local_filename: str, format: str) -> None:
527+
table_name = "table"
528+
df = pd.DataFrame({"key": [1, 2], "value": ["foo", "boo"]})
529+
530+
if format == "csv":
531+
df.to_csv(local_filename, index=False)
532+
wr.dynamodb.put_csv(
533+
path=local_filename,
534+
table_name=table_name,
535+
)
536+
elif format == "json":
537+
df.to_json(local_filename, orient="records")
538+
wr.dynamodb.put_json(
539+
path=local_filename,
540+
table_name=table_name,
541+
)
542+
else:
543+
raise RuntimeError(f"Unknown format {format}")
544+
545+
df2 = wr.dynamodb.read_partiql_query(query="SELECT * FROM table")
546+
547+
assert df.shape == df2.shape
548+
549+
524550
def test_dynamodb_partiql(moto_dynamodb):
525551
table_name = "table"
526552
items = [{"key": 1}, {"key": 2, "my_value": "Hello"}]

0 commit comments

Comments
 (0)