Skip to content

Commit

Permalink
Merge pull request #166 from asmacdo/test-arg-parse
Browse files Browse the repository at this point in the history
Add tests for correct handling of args
  • Loading branch information
asmacdo authored Aug 28, 2024
2 parents c2f1187 + 34cc1e3 commit fa3212d
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/test_arg_parsing.py
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
)

0 comments on commit fa3212d

Please sign in to comment.