Add ArgumentAction.STORE_BOOL_OPTIONAL, Add BreakChainSignal
This commit is contained in:
@ -98,13 +98,17 @@ def test_enable_retry_not_action():
|
||||
cmd = Command(
|
||||
key="C",
|
||||
description="Retry action",
|
||||
action=DummyInputAction,
|
||||
action=DummyInputAction(
|
||||
name="dummy_input_action",
|
||||
),
|
||||
retry=True,
|
||||
)
|
||||
assert cmd.retry is True
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
assert cmd.action.retry_policy.enabled is False
|
||||
assert "'function' object has no attribute 'retry_policy'" in str(exc_info.value)
|
||||
assert "'DummyInputAction' object has no attribute 'retry_policy'" in str(
|
||||
exc_info.value
|
||||
)
|
||||
|
||||
|
||||
def test_chain_retry_all():
|
||||
@ -134,13 +138,17 @@ def test_chain_retry_all_not_base_action():
|
||||
cmd = Command(
|
||||
key="E",
|
||||
description="Chain with retry",
|
||||
action=DummyInputAction,
|
||||
action=DummyInputAction(
|
||||
name="dummy_input_action",
|
||||
),
|
||||
retry_all=True,
|
||||
)
|
||||
assert cmd.retry_all is True
|
||||
with pytest.raises(Exception) as exc_info:
|
||||
assert cmd.action.retry_policy.enabled is False
|
||||
assert "'function' object has no attribute 'retry_policy'" in str(exc_info.value)
|
||||
assert "'DummyInputAction' object has no attribute 'retry_policy'" in str(
|
||||
exc_info.value
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from falyx.action import Action, SelectionAction
|
||||
from falyx.action import Action
|
||||
from falyx.exceptions import CommandArgumentError
|
||||
from falyx.parser import ArgumentAction, CommandArgumentParser
|
||||
|
||||
@ -217,11 +217,3 @@ async def test_action_with_default_and_value_positional():
|
||||
|
||||
with pytest.raises(CommandArgumentError):
|
||||
await parser.parse_args(["be"])
|
||||
|
||||
|
||||
# @pytest.mark.asyncio
|
||||
# async def test_selection_action():
|
||||
# parser = CommandArgumentParser()
|
||||
# action = SelectionAction("select", selections=["a", "b", "c"])
|
||||
# parser.add_argument("--select", action=ArgumentAction.ACTION, resolver=action)
|
||||
# args = await parser.parse_args(["--select"])
|
||||
|
@ -8,4 +8,4 @@ def test_argument_action():
|
||||
assert action != "invalid_action"
|
||||
assert action.value == "append"
|
||||
assert str(action) == "append"
|
||||
assert len(ArgumentAction.choices()) == 8
|
||||
assert len(ArgumentAction.choices()) == 9
|
||||
|
83
tests/test_parsers/test_store_bool_optional.py
Normal file
83
tests/test_parsers/test_store_bool_optional.py
Normal file
@ -0,0 +1,83 @@
|
||||
import pytest
|
||||
|
||||
from falyx.exceptions import CommandArgumentError
|
||||
from falyx.parser import ArgumentAction, CommandArgumentParser
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_store_bool_optional_true():
|
||||
parser = CommandArgumentParser()
|
||||
parser.add_argument(
|
||||
"--debug",
|
||||
action=ArgumentAction.STORE_BOOL_OPTIONAL,
|
||||
help="Enable debug mode.",
|
||||
)
|
||||
args = await parser.parse_args(["--debug"])
|
||||
assert args["debug"] is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_store_bool_optional_false():
|
||||
parser = CommandArgumentParser()
|
||||
parser.add_argument(
|
||||
"--debug",
|
||||
action=ArgumentAction.STORE_BOOL_OPTIONAL,
|
||||
help="Enable debug mode.",
|
||||
)
|
||||
args = await parser.parse_args(["--no-debug"])
|
||||
assert args["debug"] is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_store_bool_optional_default_none():
|
||||
parser = CommandArgumentParser()
|
||||
parser.add_argument(
|
||||
"--debug",
|
||||
action=ArgumentAction.STORE_BOOL_OPTIONAL,
|
||||
help="Enable debug mode.",
|
||||
)
|
||||
args = await parser.parse_args([])
|
||||
assert args["debug"] is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_store_bool_optional_flag_order():
|
||||
parser = CommandArgumentParser()
|
||||
parser.add_argument(
|
||||
"--dry-run",
|
||||
action=ArgumentAction.STORE_BOOL_OPTIONAL,
|
||||
help="Run without making changes.",
|
||||
)
|
||||
args = await parser.parse_args(["--dry-run"])
|
||||
assert args["dry_run"] is True
|
||||
args = await parser.parse_args(["--no-dry-run"])
|
||||
assert args["dry_run"] is False
|
||||
|
||||
|
||||
def test_store_bool_optional_requires_long_flag():
|
||||
parser = CommandArgumentParser()
|
||||
with pytest.raises(CommandArgumentError):
|
||||
parser.add_argument(
|
||||
"-d", action=ArgumentAction.STORE_BOOL_OPTIONAL, help="Invalid"
|
||||
)
|
||||
|
||||
|
||||
def test_store_bool_optional_disallows_multiple_flags():
|
||||
parser = CommandArgumentParser()
|
||||
with pytest.raises(CommandArgumentError):
|
||||
parser.add_argument("--debug", "-d", action=ArgumentAction.STORE_BOOL_OPTIONAL)
|
||||
|
||||
|
||||
def test_store_bool_optional_duplicate_dest():
|
||||
parser = CommandArgumentParser()
|
||||
parser.add_argument(
|
||||
"--debug",
|
||||
action=ArgumentAction.STORE_BOOL_OPTIONAL,
|
||||
help="Enable debug mode.",
|
||||
)
|
||||
with pytest.raises(CommandArgumentError):
|
||||
parser.add_argument(
|
||||
"--debug",
|
||||
action=ArgumentAction.STORE_TRUE,
|
||||
help="Conflicting debug option.",
|
||||
)
|
Reference in New Issue
Block a user