From 276e27fe59c60e4b5569bfab8e99a0c7738110ca Mon Sep 17 00:00:00 2001 From: tcezard Date: Fri, 20 Dec 2024 12:05:17 +0000 Subject: [PATCH] Lock file was specified instead of the locked directory. --- eva_sub_cli/executables/cli.py | 9 ++++++++- tests/test_cli.py | 23 +++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/eva_sub_cli/executables/cli.py b/eva_sub_cli/executables/cli.py index db8c0c4..42c6495 100755 --- a/eva_sub_cli/executables/cli.py +++ b/eva_sub_cli/executables/cli.py @@ -79,6 +79,7 @@ def parse_args(cmd_line_args): def main(): + exit_status = 0 args = parse_args(sys.argv[1:]) args.submission_dir = os.path.abspath(args.submission_dir) @@ -91,7 +92,7 @@ def main(): try: # lock the submission directory - with DirLock(os.path.join(args.submission_dir, '.lock')) as lock: + with DirLock(os.path.join(args.submission_dir)) as lock: # Create the log file logging_config.add_file_handler(os.path.join(args.submission_dir, 'eva_submission.log'), logging.DEBUG) # Pass on all the arguments to the orchestrator @@ -100,9 +101,15 @@ def main(): print(f'Could not acquire the lock file for {args.submission_dir} because another process is using this ' f'directory or a previous process did not terminate correctly. ' f'If the problem persists, remove the lock file manually.') + exit_status = 65 except FileNotFoundError as fne: print(fne) + exit_status = 66 except SubmissionNotFoundException as snfe: print(f'{snfe}. Please contact EVA Helpdesk') + exit_status = 67 except SubmissionStatusException as sse: print(f'{sse}. Please try again later. If the problem persists, please contact EVA Helpdesk') + exit_status = 68 + return exit_status + diff --git a/tests/test_cli.py b/tests/test_cli.py index 2381cdc..8056c7c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,5 +1,7 @@ import copy import logging +import os +import shutil import sys from unittest import TestCase from unittest.mock import patch, Mock @@ -11,19 +13,31 @@ class TestCli(TestCase): + resources_folder = os.path.join(os.path.dirname(__file__), 'resources') + submission_dir = os.path.abspath(os.path.join(resources_folder, 'submission_dir')) + + def setUp(self) -> None: + os.makedirs(self.submission_dir, exist_ok=True) + + def tearDown(self) -> None: + if os.path.exists(self.submission_dir): + shutil.rmtree(self.submission_dir) + def test_main(self): - args = Mock(submission_dir='.', vcf_files=[], reference_fasta='', metadata_json=None, metadata_xlsx='', + args = Mock(submission_dir=self.submission_dir, + vcf_files=[], reference_fasta='', metadata_json=None, metadata_xlsx='', tasks='validate', executor='native', debug=False) with patch('eva_sub_cli.executables.cli.parse_args', return_value=args), \ patch('eva_sub_cli.orchestrator.orchestrate_process'): - cli.main() + exit_status = cli.main() # Check that the debug message is shown logger = orchestrator.logger logger.debug('test') + assert exit_status == 0 def test_validate_args(self): cmd_args = [ - '--submission_dir', '.', + '--submission_dir', self.submission_dir, '--vcf_files', 'test.vcf', '--reference_fasta', 'test.fasta', '--metadata_json', 'test.json', @@ -32,9 +46,10 @@ def test_validate_args(self): '--debug' ] args = cli.parse_args(cmd_args) - assert args.submission_dir == '.' + assert args.submission_dir == self.submission_dir with patch('sys.exit') as m_exit: cli.parse_args(cmd_args[:2]+cmd_args[4:]) m_exit.assert_called_once_with(1) +