File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ import os
12from datetime import datetime
23from importlib import reload
34from 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" )
382395def awswrangler_import () -> Iterator [ModuleType ]:
383396 import awswrangler
Original file line number Diff line number Diff line change 11import logging
22import os
3+ from typing import Any
34from unittest import mock
45from 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+
524550def test_dynamodb_partiql (moto_dynamodb ):
525551 table_name = "table"
526552 items = [{"key" : 1 }, {"key" : 2 , "my_value" : "Hello" }]
You can’t perform that action at this time.
0 commit comments