Skip to content

Commit

Permalink
Unit test patching
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanFauble committed Dec 17, 2024
1 parent a31f338 commit d49cb07
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
25 changes: 11 additions & 14 deletions synapseclient/core/download/download_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ async def download_file_entity(
if_collision=if_collision,
synapse_cache_location=synapse_cache_location,
cached_file_path=cached_file_path,
entity_id=entity.id,
entity_id=getattr(entity, "id", None),
synapse_client=client,
)
if download_path is None:
Expand All @@ -158,12 +158,14 @@ async def download_file_entity(
if not os.path.exists(download_location):
os.makedirs(download_location)
client.logger.info(
f"[{entity.id}:{file_name}]: Copying existing file from {cached_file_path} to {download_path}"
f"[{getattr(entity, 'id', None)}:{file_name}]: Copying existing "
f"file from {cached_file_path} to {download_path}"
)
shutil.copy(cached_file_path, download_path)
else:
client.logger.info(
f"[{entity.id}:{file_name}]: Found existing file at {download_path}, skipping download."
f"[{getattr(entity, 'id', None)}:{file_name}]: Found existing file "
f"at {download_path}, skipping download."
)

else: # download the file from URL (could be a local file)
Expand Down Expand Up @@ -536,9 +538,7 @@ def download_fn(
),
)

syn.logger.info(
f"[{synapse_id}:{os.path.basename(downloaded_path)}]: Downloaded to {downloaded_path}"
)
syn.logger.info(f"[{synapse_id}]: Downloaded to {downloaded_path}")
syn.cache.add(
file_handle["id"], downloaded_path, file_handle.get("contentMd5", None)
)
Expand Down Expand Up @@ -682,9 +682,7 @@ def download_from_url(
actual_md5 = None
redirect_count = 0
delete_on_md5_mismatch = True
client.logger.debug(
f"[{entity_id}:{os.path.basename(destination)}]: Downloading from {url} to {destination}"
)
client.logger.debug(f"[{entity_id}]: Downloading from {url} to {destination}")
while redirect_count < REDIRECT_LIMIT:
redirect_count += 1
scheme = urllib_urlparse.urlparse(url).scheme
Expand Down Expand Up @@ -869,7 +867,7 @@ def _ftp_report_hook(
)
increment_progress_bar(n=transferred, progress_bar=progress_bar)
client.logger.debug(
f"[{entity_id}:{os.path.basename(destination)}]: Resuming "
f"[{entity_id}]: Resuming "
f"partial download to {temp_destination}. "
f"{previously_transferred}/{to_be_transferred} bytes already "
"transferred."
Expand Down Expand Up @@ -910,7 +908,7 @@ def _ftp_report_hook(
# verify that the file was completely downloaded and retry if it is not complete
if to_be_transferred > 0 and transferred < to_be_transferred:
client.logger.warning(
f"\n[{entity_id}:{os.path.basename(destination)}]: "
f"\n[{entity_id}]: "
"Retrying download because the connection ended early.\n"
)
continue
Expand All @@ -921,8 +919,7 @@ def _ftp_report_hook(
break
else:
client.logger.error(
f"[{entity_id}:{os.path.basename(destination)}]: "
f"Unable to download URLs of type {scheme}"
f"[{entity_id}]: " f"Unable to download URLs of type {scheme}"
)
return None

Expand Down Expand Up @@ -1022,7 +1019,7 @@ def resolve_download_path_collisions(
pass # Let the download proceed and overwrite the local file.
elif if_collision == COLLISION_KEEP_LOCAL:
client.logger.info(
f"[{entity_id}:{os.path.basename(download_path)}]: Found existing "
f"[{entity_id}]: Found existing "
f"file at {download_path}, skipping download."
)

Expand Down
14 changes: 7 additions & 7 deletions tests/unit/synapseutils/unit_test_synapseutils_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ def test_sync_from_synapse_download_file_is_false(syn: Synapse) -> None:
new_callable=AsyncMock,
side_effect=[
mocked_project_rest_api_dict(),
mocked_folder_rest_api_dict(),
mocked_file_rest_api_dict(),
mocked_folder_rest_api_dict(),
],
), patch(
"synapseclient.models.file.get_from_entity_factory",
Expand Down Expand Up @@ -505,17 +505,17 @@ def get_provenance_side_effect(entity, *args, **kwargs) -> Activity:
new_callable=AsyncMock,
side_effect=[
mock_project_dict(),
mock_folder_dict(),
mock_file_dict(syn_id=SYN_123),
mock_folder_dict(),
mock_file_dict(syn_id=SYN_789),
],
), patch(
"synapseclient.api.entity_factory.get_entity_id_bundle2",
new_callable=AsyncMock,
side_effect=[
mocked_project_rest_api_dict(),
mocked_folder_rest_api_dict(),
mocked_file_rest_api_dict(syn_id=SYN_123),
mocked_folder_rest_api_dict(),
mocked_file_rest_api_dict(syn_id=SYN_789),
],
), patch(
Expand Down Expand Up @@ -662,17 +662,17 @@ def get_provenance_side_effect(entity, *args, **kwargs) -> Activity:
new_callable=AsyncMock,
side_effect=[
mock_project_dict(),
mock_folder_dict(),
mock_file_dict(syn_id=SYN_123),
mock_folder_dict(),
mock_file_dict(syn_id=SYN_789),
],
), patch(
"synapseclient.api.entity_factory.get_entity_id_bundle2",
new_callable=AsyncMock,
side_effect=[
mocked_project_rest_api_dict(),
mocked_folder_rest_api_dict(),
mocked_file_rest_api_dict(syn_id=SYN_123),
mocked_folder_rest_api_dict(),
mocked_file_rest_api_dict(syn_id=SYN_789),
],
), patch(
Expand Down Expand Up @@ -784,17 +784,17 @@ def test_sync_from_synapse_manifest_is_suppress(
new_callable=AsyncMock,
side_effect=[
mock_project_dict(),
mock_folder_dict(),
mock_file_dict(syn_id=SYN_123),
mock_folder_dict(),
mock_file_dict(syn_id=SYN_789),
],
), patch(
"synapseclient.api.entity_factory.get_entity_id_bundle2",
new_callable=AsyncMock,
side_effect=[
mocked_project_rest_api_dict(),
mocked_folder_rest_api_dict(),
mocked_file_rest_api_dict(syn_id=SYN_123),
mocked_folder_rest_api_dict(),
mocked_file_rest_api_dict(syn_id=SYN_789),
],
), patch(
Expand Down

0 comments on commit d49cb07

Please sign in to comment.