From 6f358dd128ec6aceda7ba077f83139e96064f2d3 Mon Sep 17 00:00:00 2001 From: Austin Macdonald Date: Wed, 28 Aug 2024 09:39:47 -0500 Subject: [PATCH 1/2] Add test and fix for argparse abreviation issue --- src/con_duct/__main__.py | 1 + test/test_arg_parsing.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/con_duct/__main__.py b/src/con_duct/__main__.py index 8d81cf8a..a59ad273 100644 --- a/src/con_duct/__main__.py +++ b/src/con_duct/__main__.py @@ -503,6 +503,7 @@ def from_argv( cls, cli_args: Optional[list[str]] = None, **cli_kwargs: Any ) -> Arguments: parser = argparse.ArgumentParser( + allow_abbrev=False, description=ABOUT_DUCT, formatter_class=CustomHelpFormatter, ) diff --git a/test/test_arg_parsing.py b/test/test_arg_parsing.py index 1d4a95c1..23fd4f99 100644 --- a/test/test_arg_parsing.py +++ b/test/test_arg_parsing.py @@ -40,3 +40,18 @@ def test_duct_missing_cmd() -> None: assert "duct: error: the following arguments are required: command" in str( e.stdout ) + + +def test_abreviation_disabled() -> None: + """ + If abbreviation is enabled, options passed to command (not duct) are still + filtered through the argparse and causes problems. + """ + try: + subprocess.check_output(["duct", "ps", "--output"], stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as e: + assert e.returncode == 1 + assert "duct: error: ambiguous option: --output could match" not in str( + e.stdout + ) + assert "ps [options]" in str(e.stdout) From da60d351f6dc491c6adc80ced7e779bef1ca4ee2 Mon Sep 17 00:00:00 2001 From: Austin Macdonald Date: Wed, 28 Aug 2024 10:36:45 -0500 Subject: [PATCH 2/2] Catch possibility that ps erroneously passes Co-authored-by: Yaroslav Halchenko --- test/test_arg_parsing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_arg_parsing.py b/test/test_arg_parsing.py index 23fd4f99..00bfff63 100644 --- a/test/test_arg_parsing.py +++ b/test/test_arg_parsing.py @@ -49,6 +49,7 @@ def test_abreviation_disabled() -> None: """ try: subprocess.check_output(["duct", "ps", "--output"], stderr=subprocess.STDOUT) + raise AssertionError("Invocation of 'ps' should have failed") except subprocess.CalledProcessError as e: assert e.returncode == 1 assert "duct: error: ambiguous option: --output could match" not in str(