Skip to content

Commit

Permalink
Lock file was specified instead of the locked directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
tcezard committed Dec 20, 2024
1 parent 4c37d99 commit 276e27f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
9 changes: 8 additions & 1 deletion eva_sub_cli/executables/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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

23 changes: 19 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import copy
import logging
import os
import shutil
import sys
from unittest import TestCase
from unittest.mock import patch, Mock
Expand All @@ -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',
Expand All @@ -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)

0 comments on commit 276e27f

Please sign in to comment.