Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/common.py
Show First 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | def check_archive(archive_name: str, archive_name_to_check: str): | ||||
"""Helper function to ensure archive_name is present within the | """Helper function to ensure archive_name is present within the | ||||
archive_name_to_check. | archive_name_to_check. | ||||
Raises: | Raises: | ||||
AssertionError if archive_name is not present within | AssertionError if archive_name is not present within | ||||
archive_name_to_check | archive_name_to_check | ||||
""" | """ | ||||
ARCHIVE_FILEPATH_PATTERN = re.compile( | |||||
r"client_[0-9].*/[0-9]{8}-[0-9]{6}\.[0-9]{6}/[a-zA-Z0-9.].*" | |||||
) | |||||
assert ARCHIVE_FILEPATH_PATTERN.match(archive_name_to_check) | |||||
if "." in archive_name: | if "." in archive_name: | ||||
filename, extension = archive_name.split(".") | filename, extension = archive_name.split(".") | ||||
pattern = re.compile(".*/%s.*\\.%s" % (filename, extension)) | pattern = re.compile(".*/%s.*\\.%s" % (filename, extension)) | ||||
else: | else: | ||||
pattern = re.compile(".*/%s" % archive_name) | pattern = re.compile(".*/%s" % archive_name) | ||||
assert pattern.match(archive_name_to_check) is not None | assert pattern.match(archive_name_to_check) is not None |