Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ build
coverage.xml
dist
venv
.venv
doc/source/main_help.rst
doc/source/subcommands
Dockerfile
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+autocomplete_tests.infrastructure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Increase terminal size window in autocomplete integration tests.
15 changes: 8 additions & 7 deletions test/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,12 @@ def b2_uri_args(apiver_int):

subfolder_list: list[str] = []

@pytest.fixture(scope="session")

@pytest.fixture(scope='session')
def base_persistent_bucket(b2_api):
bucket = get_or_create_persistent_bucket(b2_api)
yield bucket
prune_used_files(b2_api=b2_api,bucket=bucket, folders=subfolder_list)
prune_used_files(b2_api=b2_api, bucket=bucket, folders=subfolder_list)


@pytest.fixture
Expand All @@ -442,13 +443,13 @@ def unique_subfolder():


@pytest.fixture
def persistent_bucket(unique_subfolder,
base_persistent_bucket) -> Generator[PersistentBucketAggregate]:
def persistent_bucket(
unique_subfolder, base_persistent_bucket
) -> Generator[PersistentBucketAggregate]:
"""
Since all consumers of the `bucket_name` fixture expect a new bucket to be created,
we need to mirror this behavior by appending a unique subfolder to the persistent bucket name.
"""
yield PersistentBucketAggregate(base_persistent_bucket.name,
unique_subfolder)
yield PersistentBucketAggregate(base_persistent_bucket.name, unique_subfolder)

logger.info("Persistent bucket aggregate finished completion.")
logger.info('Persistent bucket aggregate finished completion.')
31 changes: 25 additions & 6 deletions test/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,15 @@ def bucket_name_part(length: int) -> str:
logger.info('name_part: %s', name_part)
return name_part


T = TypeVar('T')


def wrap_iterables(generators: list[Iterable[T]]):
for g in generators:
yield from g


@dataclass
class Api:
account_id: str
Expand Down Expand Up @@ -224,20 +228,26 @@ def clean_buckets(self, quick=False):
TooManyRequests,
max_tries=8,
)
def clean_bucket(self, bucket_object: Bucket | str, only_files: bool = False, only_folders: list[str] | None = None, ignore_retentions: bool = False):
def clean_bucket(
self,
bucket_object: Bucket | str,
only_files: bool = False,
only_folders: list[str] | None = None,
ignore_retentions: bool = False,
):
"""
Clean contents of bucket, by default also deleting the bucket.

Args:
bucket (Bucket | str): Bucket object or name
only_files (bool): If to only delete files and not the bucket
Args:
bucket (Bucket | str): Bucket object or name
only_files (bool): If to only delete files and not the bucket
only_folders (list[str] | None): If not None, filter to only files in given folders.
ignore_retentions (bool): If deletion should happen regardless of files' retention mode.
"""
bucket: Bucket
if isinstance(bucket_object, str):
bucket = self.api.get_bucket_by_name(bucket_object)
else:
else:
bucket = bucket_object

if not only_files:
Expand All @@ -253,7 +263,16 @@ def clean_bucket(self, bucket_object: Bucket | str, only_files: bool = False, on

file_versions: Iterable[Any]
if only_folders:
file_versions = wrap_iterables([bucket.ls(latest_only=False, recursive=True, folder_to_list=folder,) for folder in only_folders])
file_versions = wrap_iterables(
[
bucket.ls(
latest_only=False,
recursive=True,
folder_to_list=folder,
)
for folder in only_folders
]
)
else:
file_versions = bucket.ls(latest_only=False, recursive=True)

Expand Down
5 changes: 4 additions & 1 deletion test/integration/persistent_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@ def get_or_create_persistent_bucket(b2_api: Api) -> Bucket:
b2_api.bucket_name_log.append(bucket_name)
return bucket


def prune_used_files(b2_api: Api, bucket: Bucket, folders: List[str]):
b2_api.clean_bucket(bucket_object=bucket, only_files=True, only_folders=folders,ignore_retentions=True)
b2_api.clean_bucket(
bucket_object=bucket, only_files=True, only_folders=folders, ignore_retentions=True
)
2 changes: 1 addition & 1 deletion test/integration/test_autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def autocomplete_installed(env, homedir, bashrc, cli_version, cli_command, is_ru
@pytest.fixture
def shell(env):
shell = pexpect.spawn('bash -i', env=env, maxread=1000)
shell.setwinsize(100, 100) # required to see all suggestions in tests
shell.setwinsize(100, 1000) # required to see all suggestions in tests
yield shell
shell.close()

Expand Down