From 1b78f2f9fb8b7191419b7b6b3bca438d642c882a Mon Sep 17 00:00:00 2001 From: tcezard Date: Fri, 23 Aug 2024 12:12:37 +0100 Subject: [PATCH] Couple of fixes --- eva_sub_cli/orchestrator.py | 2 +- eva_sub_cli/submit.py | 3 ++- eva_sub_cli/validators/docker_validator.py | 2 +- eva_sub_cli/validators/native_validator.py | 4 ++++ tests/test_orchestrator.py | 10 ++++++---- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/eva_sub_cli/orchestrator.py b/eva_sub_cli/orchestrator.py index c59079a..a14c31d 100755 --- a/eva_sub_cli/orchestrator.py +++ b/eva_sub_cli/orchestrator.py @@ -155,7 +155,7 @@ def orchestrate_process(submission_dir, vcf_files, reference_fasta, metadata_jso metadata_file = metadata_json or metadata_xlsx if not os.path.exists(os.path.abspath(metadata_file)): - raise FileNotFoundError(f'The provided metadata file {metadata_file} does not exist') + raise FileNotFoundError(f'The provided metadata file {os.path.abspath(metadata_file)} does not exist') if metadata_json: metadata_json = os.path.abspath(metadata_json) diff --git a/eva_sub_cli/submit.py b/eva_sub_cli/submit.py index 8f71128..62d1a94 100644 --- a/eva_sub_cli/submit.py +++ b/eva_sub_cli/submit.py @@ -64,7 +64,8 @@ def _upload_submission(self): def _upload_file(self, submission_upload_url, input_file): base_name = os.path.basename(input_file) self.debug(f'Transfer {base_name} to EVA FTP') - r = requests.put(os.path.join(submission_upload_url, base_name), data=open(input_file, 'rb')) + with open(input_file, 'rb') as f: + r = requests.put(os.path.join(submission_upload_url, base_name), data=open(input_file, 'rb')) r.raise_for_status() self.debug(f'Upload of {base_name} completed') diff --git a/eva_sub_cli/validators/docker_validator.py b/eva_sub_cli/validators/docker_validator.py index ea4a600..6e2ec0b 100644 --- a/eva_sub_cli/validators/docker_validator.py +++ b/eva_sub_cli/validators/docker_validator.py @@ -12,7 +12,7 @@ logger = logging_config.get_logger(__name__) container_image = 'ebivariation/eva-sub-cli' -container_tag = 'v0.0.1.dev14' +container_tag = 'v0.0.1.dev15' container_validation_dir = '/opt/vcf_validation' container_validation_output_dir = 'vcf_validation_output' diff --git a/eva_sub_cli/validators/native_validator.py b/eva_sub_cli/validators/native_validator.py index f125907..eb95939 100644 --- a/eva_sub_cli/validators/native_validator.py +++ b/eva_sub_cli/validators/native_validator.py @@ -24,11 +24,15 @@ def _validate(self): def run_validator(self): self.verify_executables_installed() + curr_wd = os.getcwd() try: command = self.get_validation_cmd() + os.chdir(self.submission_dir) self._run_quiet_command("Run Validation using Nextflow", command) except subprocess.CalledProcessError as ex: logger.error(ex) + finally: + os.chdir(curr_wd) def get_validation_cmd(self): if self.metadata_xlsx and not self.metadata_json: diff --git a/tests/test_orchestrator.py b/tests/test_orchestrator.py index 2af0edd..5433ffe 100644 --- a/tests/test_orchestrator.py +++ b/tests/test_orchestrator.py @@ -239,11 +239,13 @@ def test_orchestrate_with_metadata_xlsx(self): ) m_docker_validator().validate_and_report.assert_called_once_with() - def test_metadata_file_does_not_exist_error(self): with self.assertRaises(Exception) as context: - orchestrate_process(self.test_sub_dir, None, None, None, self.metadata_xlsx, - tasks=[VALIDATE], executor=DOCKER) - self.assertRegex(str(context.exception),r"The provided metadata file .*/resources/test_sub_dir/sub_metadata.xlsx does not exist") + orchestrate_process(self.test_sub_dir, None, None, None, 'Non_existing_metadata.xlsx', + tasks=[VALIDATE], executor=DOCKER) + self.assertRegex( + str(context.exception), + r"The provided metadata file .*/resources/test_sub_dir/Non_existing_metadata.xlsx does not exist" + )