1
0
Fork 0

Adding upstream version 0.6.3.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-06-03 07:18:11 +02:00
parent 271f3e2863
commit b5da990db5
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
12 changed files with 249 additions and 347 deletions

View file

@ -1,38 +1,42 @@
"""Most of argparse examples rebuilt with climp."""
import pytest
import argparse
from . import examples
from decli import cli
import unittest
import pytest
from decli import cli
from . import examples
class Test(unittest.TestCase):
def test_main_example_ok(self):
def test_main_example_ok(self) -> None:
parser = examples.main_example()
args = parser.parse_args("1 2 3 4".split())
assert args.accumulate(args.integers) == 4
def test_main_example_sums_ok(self):
def test_main_example_sums_ok(self) -> None:
parser = examples.main_example()
args = parser.parse_args("1 2 3 4 --sum".split())
assert args.accumulate(args.integers) == 10
def test_main_example_fails(self):
def test_main_example_fails(self) -> None:
parser = examples.main_example()
with pytest.raises(SystemExit):
args = parser.parse_args("a b c".split())
args.accumulate(args.integers)
def test_complete_example(self):
def test_complete_example(self) -> None:
parser = examples.complete_example()
args = parser.parse_args("sum 1 2 3".split())
assert args.func(args.integers) == 6
def test_compose_clis_using_parents(self):
def test_compose_clis_using_parents(self) -> None:
data = {"prog": "daddy", "arguments": [{"name": "something"}]}
parents = examples.compose_clis_using_parents()
parser = cli(data, parents=parents)
@ -41,7 +45,7 @@ class Test(unittest.TestCase):
assert args.something == "XXX"
assert args.foo_parent == 2
def test_compose_clis_using_parents_and_arguments(self):
def test_compose_clis_using_parents_and_arguments(self) -> None:
data = {"prog": "daddy", "arguments": [{"name": "--something"}]}
parents = examples.compose_clis_using_parents()
parser = cli(data, parents=parents)
@ -49,7 +53,7 @@ class Test(unittest.TestCase):
assert args.something == "XXX"
def test_prefix_chars(self):
def test_prefix_chars(self) -> None:
data = examples.prefix_chars()
parser = cli(data)
args = parser.parse_args("+f X ++bar Y".split())
@ -57,7 +61,7 @@ class Test(unittest.TestCase):
assert args.foo == "X"
assert args.bar == "Y"
def test_name_or_flags(self):
def test_name_or_flags(self) -> None:
data = examples.name_or_flags()
parser = cli(data)
@ -68,20 +72,20 @@ class Test(unittest.TestCase):
assert args.bar == "BAR"
assert args.foo == "FOO"
def test_name_or_flags_fail(self):
def test_name_or_flags_fail(self) -> None:
data = examples.name_or_flags()
parser = cli(data)
with pytest.raises(SystemExit):
parser.parse_args(["--foo", "FOO"])
def test_cli_no_args(self):
def test_cli_no_args(self) -> None:
data = {"prog": "daddy", "description": "helloo"}
parser = cli(data)
args = parser.parse_args([])
assert args.__dict__ == {}
def test_groups(self):
def test_groups(self) -> None:
data = examples.grouping_arguments()
parser = cli(data)
help_result = parser.format_help()
@ -89,12 +93,12 @@ class Test(unittest.TestCase):
assert "app" in help_result
assert "package" in help_result
def test_not_optional_arg_name_validation_fails(self):
def test_not_optional_arg_name_validation_fails(self) -> None:
data = {"arguments": [{"name": ["f", "foo"]}]}
with pytest.raises(ValueError):
cli(data)
def test_exclusive_group_ok(self):
def test_exclusive_group_ok(self) -> None:
data = {
"prog": "app",
"arguments": [
@ -115,7 +119,7 @@ class Test(unittest.TestCase):
assert args.install is True
assert args.purge is False
def test_exclusive_group_fails_when_same_group_called(self):
def test_exclusive_group_fails_when_same_group_called(self) -> None:
data = {
"prog": "app",
"arguments": [
@ -136,7 +140,7 @@ class Test(unittest.TestCase):
with pytest.raises(SystemExit):
parser.parse_args("--install --purge".split())
def test_exclusive_group_and_group_together_fail(self):
def test_exclusive_group_and_group_together_fail(self) -> None:
"""
Note:
@ -164,7 +168,7 @@ class Test(unittest.TestCase):
with pytest.raises(ValueError):
cli(data)
def test_subcommand_required(self):
def test_subcommand_required(self) -> None:
data = {
"prog": "cz",
"description": (