From d08851d6a72755a4960ebb17eaa0baf7709308a0 Mon Sep 17 00:00:00 2001 From: Cunliang Geng Date: Thu, 24 Aug 2023 17:19:31 +0200 Subject: [PATCH] replace HTTPError with more robust Exception for `download_and_extract_antismash_data` to make sure deletion of exttract_path can always happen. --- src/nplinker/genomics/antismash/antismash_downloader.py | 7 ++----- tests/genomics/antismash/test_antismash_downloader.py | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/nplinker/genomics/antismash/antismash_downloader.py b/src/nplinker/genomics/antismash/antismash_downloader.py index 2ef1b018..a2192f93 100644 --- a/src/nplinker/genomics/antismash/antismash_downloader.py +++ b/src/nplinker/genomics/antismash/antismash_downloader.py @@ -2,7 +2,6 @@ from os import PathLike from pathlib import Path import shutil -from urllib.error import HTTPError from nplinker.logconfig import LogConfig from nplinker.utils import download_and_extract_archive from nplinker.utils import list_dirs @@ -74,12 +73,10 @@ def download_and_extract_antismash_data(antismash_id: str, logger.info('antiSMASH BGC data of %s is downloaded and extracted.', antismash_id) - except HTTPError as e: + except Exception as e: shutil.rmtree(extract_path) logger.warning(e) - raise HTTPError(e.url, e.code, - f"Could not find a valid url for {antismash_id}", - e.headers, e.fp) from e + raise e def _check_roots(download_root: PathLike, extract_root: PathLike): diff --git a/tests/genomics/antismash/test_antismash_downloader.py b/tests/genomics/antismash/test_antismash_downloader.py index d73aa1a7..0a548980 100644 --- a/tests/genomics/antismash/test_antismash_downloader.py +++ b/tests/genomics/antismash/test_antismash_downloader.py @@ -55,7 +55,7 @@ def test_nonexisting_id(self, tmp_path): extract_root = tmp_path / "extracted" extract_root.mkdir() for test_id in nonexisting_ids: - with pytest.raises(HTTPError): + with pytest.raises(RuntimeError): download_and_extract_antismash_data(test_id, download_root, extract_root) extracted_folder = extract_root / "antismash" / test_id