Skip to content

Commit 15967c4

Browse files
committed
No tool provided needs to be handled explicitly. Add missing smoke test for tool's help.
1 parent 7e3514c commit 15967c4

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

python/grass/app/cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def main(args=None, program=None):
121121
"run",
122122
help="run a tool",
123123
add_help=False,
124-
epilog="Tool name is followed by it parameters.",
124+
epilog="Tool name is followed by its parameters.",
125125
)
126126
run_subparser.add_argument("tool", type=str, nargs="?", help="name of a tool")
127127
run_subparser.add_argument("--help", action="store_true")
@@ -177,5 +177,9 @@ def main(args=None, program=None):
177177
if parsed_args.tool is None and parsed_args.help:
178178
run_subparser.print_help()
179179
return 0
180+
if parsed_args.tool is None:
181+
run_subparser.print_usage()
182+
# argparse gives 2 without parameters, so we behave the same.
183+
return 2
180184
return parsed_args.func(parsed_args, other_args, print_help=parsed_args.help)
181185
return parsed_args.func(parsed_args)

python/grass/app/tests/grass_app_cli_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,50 @@
66

77

88
def test_cli_help_runs():
9+
"""Check help the main command"""
910
with pytest.raises(SystemExit) as exception:
1011
main(["--help"])
1112
assert exception.value.code == 0
1213

1314

1415
@pytest.mark.skipif(sys.platform.startswith("win"), reason="No man on Windows")
1516
def test_man_subcommand_runs():
17+
"""Check that man subcommand runs without an error"""
1618
assert main(["man", "g.region"]) == 0
1719

1820

21+
def test_subcommand_man_no_page():
22+
"""argparse gives 2 without parameters"""
23+
with pytest.raises(SystemExit) as exception:
24+
main(["man"])
25+
assert exception.value.code == 2
26+
27+
1928
def test_subcommand_run_help():
29+
"""Check help of a subcommand"""
2030
assert main(["run", "--help"]) == 0
2131

2232

33+
def test_subcommand_run_no_tool():
34+
"""argparse gives 2 without parameters"""
35+
assert main(["run"]) == 2
36+
37+
38+
def test_subcommand_run_tool_help():
39+
"""Check help of a tool"""
40+
assert main(["run", "g.region", "--help"]) == 0
41+
42+
2343
def test_subcommand_run_tool_special_flag():
44+
"""Check that a special flag is supported"""
2445
assert main(["run", "g.region", "--interface-description"]) == 0
2546

2647

2748
def test_subcommand_run_tool_regular_run():
49+
"""Check that a tool runs without error"""
2850
assert main(["run", "g.region", "-p"]) == 0
2951

3052

3153
def test_subcommand_run_tool_failure_run():
54+
"""Check that a tool produces non-zero return code"""
3255
assert main(["run", "g.region", "raster=does_not_exist"]) == 1

0 commit comments

Comments
 (0)