Skip to content

Commit bb208bd

Browse files
Add tests for S3 wait functions (#1896)
1 parent 861fb35 commit bb208bd

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/test_s3_wait.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import logging
2+
3+
import botocore
4+
import pandas as pd
5+
import pytest
6+
7+
import awswrangler as wr
8+
9+
logging.getLogger("awswrangler").setLevel(logging.DEBUG)
10+
11+
12+
@pytest.mark.parametrize("use_threads", [True, False])
13+
def test_wait_object_exists_single_file(path: str, use_threads: bool) -> None:
14+
df = pd.DataFrame({"FooBoo": [1, 2, 3]})
15+
file_path = f"{path}data.csv"
16+
17+
wr.s3.to_csv(df, file_path)
18+
19+
wr.s3.wait_objects_exist(paths=[file_path], use_threads=use_threads)
20+
21+
22+
@pytest.mark.parametrize("use_threads", [True, False])
23+
def test_wait_object_exists_multiple_files(path: str, use_threads: bool) -> None:
24+
df = pd.DataFrame({"FooBoo": [1, 2, 3]})
25+
26+
file_paths = [f"{path}data.csv", f"{path}data2.csv", f"{path}data3.csv"]
27+
for file_path in file_paths:
28+
wr.s3.to_csv(df, file_path)
29+
30+
wr.s3.wait_objects_exist(paths=file_paths, use_threads=use_threads)
31+
32+
33+
@pytest.mark.parametrize("use_threads", [True, False])
34+
def test_wait_object_not_exists(path: str, use_threads: bool) -> None:
35+
wr.s3.wait_objects_not_exist(paths=[path], use_threads=use_threads)
36+
37+
38+
@pytest.mark.parametrize("use_threads", [True, False])
39+
@pytest.mark.timeout(5)
40+
def test_wait_object_timeout(path: str, use_threads: bool) -> None:
41+
with pytest.raises(botocore.exceptions.WaiterError):
42+
wr.s3.wait_objects_exist(
43+
paths=[path],
44+
use_threads=use_threads,
45+
delay=0.5,
46+
max_attempts=3,
47+
)
48+
49+
50+
@pytest.mark.parametrize("use_threads", [True, False])
51+
def test_wait_object_exists_empty_list(use_threads: bool) -> None:
52+
wr.s3.wait_objects_exist(paths=[])

0 commit comments

Comments
 (0)