Skip to content

Commit

Permalink
reorder if statement in kernel download logic
Browse files Browse the repository at this point in the history
  • Loading branch information
subagonsouth committed Sep 16, 2024
1 parent fef6a11 commit 0ee0d32
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions imap_processing/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,33 @@ def _download_de440s(spice_test_data_path):
kernel_name = kernel_url.split("/")[-1]
local_filepath = spice_test_data_path / kernel_name

if not local_filepath.exists():
allowed_attempts = 3
for attempt_number in range(allowed_attempts):
try:
with requests.get(kernel_url, stream=True, timeout=30) as r:
r.raise_for_status()
with open(local_filepath, "wb") as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
break
except requests.exceptions.RequestException as error:
logger.info(f"Request failed. {error}")
if attempt_number < allowed_attempts:
logger.info(
f"Trying again, retries left "
f"{allowed_attempts - attempt_number}, "
f"Exception: {error}"
)
time.sleep(1)
else:
logger.error(
f"Failed to download file after {allowed_attempts} "
f"attempts, Final Error: {error}"
)
raise

logger.info("Cached kernel file to %s", local_filepath)
if local_filepath.exists():
return
allowed_attempts = 3
for attempt_number in range(allowed_attempts):
try:
with requests.get(kernel_url, stream=True, timeout=30) as r:
r.raise_for_status()
with open(local_filepath, "wb") as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
logger.info("Cached kernel file to %s", local_filepath)
break
except requests.exceptions.RequestException as error:
logger.info(f"Request failed. {error}")
if attempt_number < allowed_attempts:
logger.info(
f"Trying again, retries left "
f"{allowed_attempts - attempt_number}, "
f"Exception: {error}"
)
time.sleep(1)
else:
logger.error(
f"Failed to download file after {allowed_attempts} "
f"attempts, Final Error: {error}"
)
raise


def pytest_collection_modifyitems(items):
Expand Down

0 comments on commit 0ee0d32

Please sign in to comment.