Skip to content

Commit b842429

Browse files
committed
simplify
1 parent 11e0867 commit b842429

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/aws-library/tests/test_s3_client.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from collections.abc import AsyncIterator, Awaitable, Callable
1717
from dataclasses import dataclass
1818
from pathlib import Path
19-
from typing import Any
19+
from typing import Any, Final
2020

2121
import botocore.exceptions
2222
import pytest
@@ -520,14 +520,17 @@ async def test_http_check_bucket_connected(
520520
)
521521

522522

523+
_ROOT_LEVEL: Final[int] = -2
524+
525+
523526
def _get_paths_with_prefix(
524-
uploaded_files: list[UploadedFile], prefix_level: int, path_prefix: Path
527+
uploaded_files: list[UploadedFile], *, prefix_level: int, path_prefix: Path
525528
) -> tuple[set[Path], set[Path]]:
526529
def _filter_by_prefix(uploaded_file: UploadedFile) -> bool:
527530
return Path(uploaded_file.s3_key).is_relative_to(path_prefix)
528531

529532
directories = {
530-
Path(file.s3_key).parents[prefix_level]
533+
Path(file.s3_key).parents[_ROOT_LEVEL - prefix_level]
531534
for file in filter(_filter_by_prefix, uploaded_files)
532535
if Path(file.s3_key).parent != path_prefix
533536
}
@@ -575,7 +578,7 @@ async def test_list_objects(
575578
# go one level deeper, will return all the folders + files in the first level
576579
first_level_prefix = next(iter(top_level_paths))
577580
first_level_directories, first_level_files = _get_paths_with_prefix(
578-
with_uploaded_folder_on_s3, -3, path_prefix=first_level_prefix
581+
with_uploaded_folder_on_s3, prefix_level=1, path_prefix=first_level_prefix
579582
)
580583
first_level_paths = first_level_directories | first_level_files
581584

@@ -593,7 +596,7 @@ async def test_list_objects(
593596
# we go one more level down under a random first-level directory
594597
second_level_prefix = random.choice(list(first_level_directories)) # noqa: S311
595598
second_level_directories, second_level_files = _get_paths_with_prefix(
596-
with_uploaded_folder_on_s3, -4, path_prefix=second_level_prefix
599+
with_uploaded_folder_on_s3, prefix_level=2, path_prefix=second_level_prefix
597600
)
598601
second_level_paths = second_level_directories | second_level_files
599602

0 commit comments

Comments
 (0)