-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from asmacdo/test-arg-parse
Add tests for correct handling of args
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import subprocess | ||
import pytest | ||
|
||
|
||
def test_duct_help() -> None: | ||
out = subprocess.check_output(["duct", "--help", "ps"]) | ||
assert "usage: duct [-h]" in str(out) | ||
|
||
|
||
def test_cmd_help() -> None: | ||
out = subprocess.check_output(["duct", "ps", "--help"]) | ||
assert "ps [options]" in str(out) | ||
assert "usage: duct [-h]" not in str(out) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"args", | ||
[ | ||
["duct", "--unknown", "ps"], | ||
["duct", "--unknown", "ps", "--shouldhavenoeffect"], | ||
], | ||
) | ||
def test_duct_unrecognized_arg(args: list) -> None: | ||
try: | ||
subprocess.check_output(args, stderr=subprocess.STDOUT) | ||
pytest.fail("Command should have failed with a non-zero exit code") | ||
except subprocess.CalledProcessError as e: | ||
assert e.returncode == 2 | ||
assert "duct: error: unrecognized arguments: --unknown" in str(e.stdout) | ||
|
||
|
||
def test_duct_missing_cmd() -> None: | ||
try: | ||
subprocess.check_output( | ||
["duct", "--sample-interval", "1"], stderr=subprocess.STDOUT | ||
) | ||
pytest.fail("Command should have failed with a non-zero exit code") | ||
except subprocess.CalledProcessError as e: | ||
assert e.returncode == 2 | ||
assert "duct: error: the following arguments are required: command" in str( | ||
e.stdout | ||
) |