|  | 
| 1 | 1 | import argparse | 
| 2 | 2 | from io import StringIO | 
| 3 | 3 | from pathlib import Path | 
| 4 |  | -from typing import Callable | 
|  | 4 | +from typing import Any, Callable, Dict, List | 
| 5 | 5 | 
 | 
| 6 | 6 | import pytest | 
| 7 | 7 | 
 | 
| @@ -195,3 +195,35 @@ def test_argparser_without_doc() -> None: | 
| 195 | 195 |     p = argparse.ArgumentParser() | 
| 196 | 196 |     parser = generate_parser(p, tool, {}, [], False) | 
| 197 | 197 |     assert parser.description is None | 
|  | 198 | + | 
|  | 199 | + | 
|  | 200 | +@pytest.mark.parametrize( | 
|  | 201 | +    "job_order,expected_values", | 
|  | 202 | +    [ | 
|  | 203 | +        # no arguments, so we expect the default value | 
|  | 204 | +        ([], ["/home/bart/cwl_test/test1"]), | 
|  | 205 | +        # arguments, provided, one or many, meaning that the default value is not expected | 
|  | 206 | +        (["--file_paths", "/home/bart/cwl_test/test2"], ["/home/bart/cwl_test/test2"]), | 
|  | 207 | +        ( | 
|  | 208 | +            [ | 
|  | 209 | +                "--file_paths", | 
|  | 210 | +                "/home/bart/cwl_test/test2", | 
|  | 211 | +                "--file_paths", | 
|  | 212 | +                "/home/bart/cwl_test/test3", | 
|  | 213 | +            ], | 
|  | 214 | +            ["/home/bart/cwl_test/test2", "/home/bart/cwl_test/test3"], | 
|  | 215 | +        ), | 
|  | 216 | +    ], | 
|  | 217 | +) | 
|  | 218 | +def test_argparse_append_with_default( | 
|  | 219 | +    job_order: List[str], expected_values: List[str] | 
|  | 220 | +) -> None: | 
|  | 221 | +    """The appended arguments must not include the default. But if no appended argument, then the default is used.""" | 
|  | 222 | +    loadingContext = LoadingContext() | 
|  | 223 | +    tool = load_tool(get_data("tests/default_values_list.cwl"), loadingContext) | 
|  | 224 | +    toolparser = generate_parser( | 
|  | 225 | +        argparse.ArgumentParser(prog="test"), tool, {}, [], False | 
|  | 226 | +    ) | 
|  | 227 | +    cmd_line = vars(toolparser.parse_args(job_order))  # type: ignore[call-overload] | 
|  | 228 | +    file_paths = list(cmd_line["file_paths"]) | 
|  | 229 | +    assert expected_values == file_paths | 
0 commit comments