Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve logic to respect cli and dryrun flags with info #156

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions seqerakit/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,15 @@ def main(args=None):
options = parse_args(args if args is not None else sys.argv[1:])
logging.basicConfig(level=options.log_level)

# Parse CLI arguments into a list and create a Seqera Platform instance
cli_args_list = options.cli_args.split() if options.cli_args else []
sp = seqeraplatform.SeqeraPlatform(cli_args=cli_args_list, dryrun=options.dryrun)

# If the info flag is set, run 'tw info'
if options.info:
sp = seqeraplatform.SeqeraPlatform()
print(sp.info())
result = sp.info()
if not options.dryrun:
print(result)
return

if not options.yaml:
Expand All @@ -161,11 +166,6 @@ def main(args=None):
else:
options.yaml = [sys.stdin]

# Parse CLI arguments into a list
cli_args_list = options.cli_args.split() if options.cli_args else []

sp = seqeraplatform.SeqeraPlatform(cli_args=cli_args_list, dryrun=options.dryrun)

block_manager = BlockParser(
sp,
[
Expand Down
6 changes: 3 additions & 3 deletions seqerakit/seqeraplatform.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ def _execute_command(self, full_cmd, to_json=False):

return json.loads(stdout) if to_json else stdout

def _execute_info_command(self):
def _execute_info_command(self, *args, **kwargs):
# Directly execute 'tw info' command
command = "tw info"
return self._execute_command(command)
command = ["info"]
return self._tw_run(command, *args, **kwargs)

def _handle_command_errors(self, stdout):
logging.error(stdout)
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/test_seqeraplatform.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,32 @@ def test_cli_args_exclusion_of_verbose(self): # TODO: remove this test once fix
"--verbose is not supported as a CLI argument to seqerakit.",
)

@patch("subprocess.Popen")
def test_info_command_construction(self, mock_subprocess):
# Mock the subprocess call to prevent actual execution
mock_subprocess.return_value = MagicMock(returncode=0)
mock_subprocess.return_value.communicate.return_value = (b"", b"")

self.sp.info()
called_command = mock_subprocess.call_args[0][0]

# Check if the constructed command is correct
expected_command_part = "tw --url http://tower-api.com --insecure info"
self.assertIn(expected_command_part, called_command)

# Check if the cli_args are included in the called command
for arg in self.cli_args:
self.assertIn(arg, called_command)

@patch("subprocess.Popen")
def test_info_command_dryrun(self, mock_subprocess):
# Initialize SeqeraPlatform with dryrun enabled
self.sp.dryrun = True
self.sp.info()

# Check that subprocess.Popen is not called
mock_subprocess.assert_not_called()


class TestKitOptions(unittest.TestCase):
def setUp(self):
Expand Down
Loading