diff --git a/seqerakit/cli.py b/seqerakit/cli.py index 0bb29e6..b0b7c43 100644 --- a/seqerakit/cli.py +++ b/seqerakit/cli.py @@ -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: @@ -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, [ diff --git a/seqerakit/seqeraplatform.py b/seqerakit/seqeraplatform.py index a08f816..4a62bb0 100644 --- a/seqerakit/seqeraplatform.py +++ b/seqerakit/seqeraplatform.py @@ -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) diff --git a/tests/unit/test_seqeraplatform.py b/tests/unit/test_seqeraplatform.py index 941f0ed..2173afb 100644 --- a/tests/unit/test_seqeraplatform.py +++ b/tests/unit/test_seqeraplatform.py @@ -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):