diff --git a/cwltool/main.py b/cwltool/main.py index d71b1b8a1..4d7914ee7 100755 --- a/cwltool/main.py +++ b/cwltool/main.py @@ -682,8 +682,8 @@ def formatTime(self, record: logging.LogRecord, datefmt: Optional[str] = None) - def setup_provenance( args: argparse.Namespace, - argsl: List[str], runtimeContext: RuntimeContext, + argsl: Optional[List[str]] = None, ) -> Tuple[ProvOut, "logging.StreamHandler[ProvOut]"]: if not args.compute_checksum: _logger.error("--provenance incompatible with --no-compute-checksum") @@ -1049,10 +1049,8 @@ def main( prov_log_stream: Optional[Union[io.TextIOWrapper, WritableBagFile]] = None if args.provenance: - if argsl is None: - raise Exception("argsl cannot be None") try: - prov_log_stream, prov_log_handler = setup_provenance(args, argsl, runtimeContext) + prov_log_stream, prov_log_handler = setup_provenance(args, runtimeContext, argsl) except ArgumentException: return 1 diff --git a/tests/test_main_parsed_args.py b/tests/test_main_parsed_args.py new file mode 100644 index 000000000..7a94d9225 --- /dev/null +++ b/tests/test_main_parsed_args.py @@ -0,0 +1,40 @@ +import io +from pathlib import Path + +from cwltool.argparser import arg_parser +from cwltool.main import main + +from .util import get_data + + +def test_main_parsed_args(tmp_path: Path) -> None: + """Affirm that main can be called with parsed args only.""" + stdout = io.StringIO() + stderr = io.StringIO() + + unparsed_args = [get_data("tests/echo.cwl"), "--inp", "Hello"] + parsed_args = arg_parser().parse_args(unparsed_args) + + try: + assert main(args=parsed_args, stdout=stdout, stderr=stderr) == 0 + except SystemExit as err: + assert err.code == 0 + + +def test_main_parsed_args_provenance(tmp_path: Path) -> None: + """Affirm that main can be called with parsed args only, requesting provenance.""" + stdout = io.StringIO() + stderr = io.StringIO() + + prov_folder = tmp_path / "provenance" # will be created if necessary + + unparsed_args = ["--provenance", str(prov_folder), get_data("tests/echo.cwl"), "--inp", "Hello"] + parsed_args = arg_parser().parse_args(unparsed_args) + + try: + assert main(args=parsed_args, stdout=stdout, stderr=stderr) == 0 + except SystemExit as err: + assert err.code == 0 + + manifest_file = prov_folder / "metadata" / "manifest.json" + assert manifest_file.is_file(), f"Can't find RO-Crate manifest {manifest_file}"