Skip to content

Commit 87687e1

Browse files
committed
ensure uniqueness and depth
1 parent d1a4f5a commit 87687e1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/pytest-simcore/src/pytest_simcore/file_extra.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66
from faker import Faker
7-
from pydantic import ByteSize
7+
from pydantic import ByteSize, NonNegativeInt
88
from pytest_simcore.helpers.logging_tools import log_context
99

1010

@@ -33,6 +33,7 @@ def _create_random_content(
3333
file_min_size: ByteSize,
3434
file_max_size: ByteSize,
3535
remaining_size: ByteSize,
36+
depth: NonNegativeInt | None,
3637
) -> ByteSize:
3738
if remaining_size <= 0:
3839
return remaining_size
@@ -43,7 +44,9 @@ def _create_random_content(
4344
max_value=min(remaining_size, file_max_size),
4445
)
4546
)
46-
file_path = base_dir / f"{faker.file_path(depth=faker.pyint(0, 5), absolute=False)}"
47+
if depth is None:
48+
depth = faker.pyint(0, 5)
49+
file_path = base_dir / f"{faker.unique.file_path(depth=depth, absolute=False)}"
4750
file_path.parent.mkdir(parents=True, exist_ok=True)
4851
assert not file_path.exists()
4952
with file_path.open("wb") as fp:
@@ -62,6 +65,7 @@ def _create_folder_of_size_with_multiple_files(
6265
directory_size: ByteSize,
6366
file_min_size: ByteSize,
6467
file_max_size: ByteSize,
68+
depth: NonNegativeInt | None = None,
6569
) -> Path:
6670
# Helper function to create random files and directories
6771
assert file_min_size > 0
@@ -82,6 +86,7 @@ def _create_folder_of_size_with_multiple_files(
8286
file_min_size=file_min_size,
8387
file_max_size=file_max_size,
8488
remaining_size=remaining_size,
89+
depth=depth,
8590
)
8691
num_files_created += 1
8792
ctx.logger.info("created %s files", num_files_created)

0 commit comments

Comments
 (0)