From ba8ed1931e01b1070520efeeb80102b84f617a8b Mon Sep 17 00:00:00 2001 From: Fabrice Normandin Date: Mon, 28 Aug 2023 15:42:46 -0400 Subject: [PATCH] Fix test for error output, make commands required Signed-off-by: Fabrice Normandin --- milatools/cli/commands.py | 11 ++++++----- tests/cli/test_commands.py | 2 +- .../test_invalid_command_output_mila_.txt | 2 ++ .../test_invalid_command_output_mila_code_.txt | 4 ++++ .../test_invalid_command_output_mila_forward_.txt | 2 ++ ...test_invalid_command_output_mila_search_conda_.txt | 2 ++ .../test_invalid_command_output_mila_serve_.txt | 3 +++ 7 files changed, 20 insertions(+), 6 deletions(-) diff --git a/milatools/cli/commands.py b/milatools/cli/commands.py index 67bb0616..01ec5a11 100644 --- a/milatools/cli/commands.py +++ b/milatools/cli/commands.py @@ -108,7 +108,7 @@ def mila(): help="Milatools version", ) - subparsers = parser.add_subparsers() + subparsers = parser.add_subparsers(required=True, dest="") # ----- mila docs ------ @@ -149,7 +149,6 @@ def mila(): forward_parser.add_argument("REMOTE", help="node:port to forward") forward_parser.add_argument( "--page", - # nargs="?", help="String to append after the URL", default=None, metavar="VALUE", @@ -216,7 +215,9 @@ def mila(): help="Start services on compute nodes and forward them to your local machine.", formatter_class=SortingHelpFormatter, ) - serve_subparsers = serve_parser.add_subparsers(dest="serve_command", required=True) + serve_subparsers = serve_parser.add_subparsers( + dest="", required=True + ) # ----- mila serve connect ------ @@ -228,7 +229,6 @@ def mila(): serve_connect_parser.add_argument( "IDENTIFIER", type=str, - # todo:remove spaces help="Server identifier output by the original mila serve command", ) serve_connect_parser.add_argument( @@ -345,7 +345,8 @@ def mila(): args = parser.parse_args() args_dict = vars(args) function = args_dict.pop("function") - _ = args_dict.pop("serve_command", None) + _ = args_dict.pop("") + _ = args_dict.pop("", None) # replace SEARCH -> "search", REMOTE -> "remote", etc. args_dict = _convert_uppercase_keys_to_lowercase(args_dict) assert callable(function) diff --git a/tests/cli/test_commands.py b/tests/cli/test_commands.py index 12e84010..60894a04 100644 --- a/tests/cli/test_commands.py +++ b/tests/cli/test_commands.py @@ -71,7 +71,7 @@ def test_invalid_command_output( buf = io.StringIO() with contextlib.suppress(SystemExit), pytest.raises( SystemExit - ), contextlib.redirect_stdout(buf): + ), contextlib.redirect_stdout(buf), contextlib.redirect_stderr(buf): main() file_regression.check(_convert_argparse_output_to_pre_py311_format(buf.getvalue())) diff --git a/tests/cli/test_commands/test_invalid_command_output_mila_.txt b/tests/cli/test_commands/test_invalid_command_output_mila_.txt index e69de29b..220a4cf5 100644 --- a/tests/cli/test_commands/test_invalid_command_output_mila_.txt +++ b/tests/cli/test_commands/test_invalid_command_output_mila_.txt @@ -0,0 +1,2 @@ +usage: mila [-h] [--version] {docs,intranet,init,forward,code,serve} ... +mila: error: the following arguments are required: diff --git a/tests/cli/test_commands/test_invalid_command_output_mila_code_.txt b/tests/cli/test_commands/test_invalid_command_output_mila_code_.txt index e69de29b..8f59354b 100644 --- a/tests/cli/test_commands/test_invalid_command_output_mila_code_.txt +++ b/tests/cli/test_commands/test_invalid_command_output_mila_code_.txt @@ -0,0 +1,4 @@ +usage: mila code [-h] [--alloc ...] [--command VALUE] [--job VALUE] + [--node VALUE] [--persist] + PATH +mila code: error: the following arguments are required: PATH diff --git a/tests/cli/test_commands/test_invalid_command_output_mila_forward_.txt b/tests/cli/test_commands/test_invalid_command_output_mila_forward_.txt index e69de29b..9f5812de 100644 --- a/tests/cli/test_commands/test_invalid_command_output_mila_forward_.txt +++ b/tests/cli/test_commands/test_invalid_command_output_mila_forward_.txt @@ -0,0 +1,2 @@ +usage: mila forward [-h] [--page VALUE] [--port VALUE] REMOTE +mila forward: error: the following arguments are required: REMOTE diff --git a/tests/cli/test_commands/test_invalid_command_output_mila_search_conda_.txt b/tests/cli/test_commands/test_invalid_command_output_mila_search_conda_.txt index e69de29b..98bdd3a5 100644 --- a/tests/cli/test_commands/test_invalid_command_output_mila_search_conda_.txt +++ b/tests/cli/test_commands/test_invalid_command_output_mila_search_conda_.txt @@ -0,0 +1,2 @@ +usage: mila [-h] [--version] {docs,intranet,init,forward,code,serve} ... +mila: error: argument : invalid choice: 'search' (choose from 'docs', 'intranet', 'init', 'forward', 'code', 'serve') diff --git a/tests/cli/test_commands/test_invalid_command_output_mila_serve_.txt b/tests/cli/test_commands/test_invalid_command_output_mila_serve_.txt index e69de29b..c57438c5 100644 --- a/tests/cli/test_commands/test_invalid_command_output_mila_serve_.txt +++ b/tests/cli/test_commands/test_invalid_command_output_mila_serve_.txt @@ -0,0 +1,3 @@ +usage: mila serve [-h] + {connect,kill,list,lab,notebook,tensorboard,mlflow,aim} ... +mila serve: error: the following arguments are required: