Skip to content

Commit 50ae1d4

Browse files
committed
test(layout): add tests for literal choices rendering in help
1 parent 528c02e commit 50ae1d4

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

tests/argparse/layout/test_help_rendering_regressions.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323
from interfacy.argparse_backend import Argparser
2424
from interfacy.argparse_backend.argument_parser import ArgumentParser
25+
from interfacy.naming import DefaultFlagStrategy
2526
from interfacy.schema.schema import Command, ParserSchema
2627

2728

@@ -620,6 +621,93 @@ def test_argparse_layout_group_usage_includes_subcommand_choices() -> None:
620621
assert "{cache-prune}" in help_text
621622

622623

624+
@pytest.mark.parametrize(
625+
("layout", "expected_positional_choices", "expected_flag_choices"),
626+
[
627+
(
628+
StandardLayout(),
629+
"[choices: alpha, beta]",
630+
"[choices: csv, txt]",
631+
),
632+
(
633+
ArgparseLayout(),
634+
"Choices: alpha, beta.",
635+
"Choices: csv, txt.",
636+
),
637+
(
638+
InterfacyLayout(),
639+
"[choices: alpha, beta]",
640+
"[choices: csv, txt, default=csv]",
641+
),
642+
(
643+
Modern(),
644+
"choices: alpha, beta",
645+
"choices: csv, txt",
646+
),
647+
(
648+
Aligned(),
649+
"[choices: alpha, beta]",
650+
"[choices: csv, txt]",
651+
),
652+
(
653+
AlignedTyped(),
654+
"[choices: alpha, beta]",
655+
"[choices: csv, txt]",
656+
),
657+
(
658+
ClapLayout(),
659+
"[possible values: alpha, beta]",
660+
"[possible values: csv, txt]",
661+
),
662+
],
663+
)
664+
def test_all_layouts_render_literal_choices_for_positional_and_optional_flag(
665+
layout,
666+
expected_positional_choices: str,
667+
expected_flag_choices: str,
668+
) -> None:
669+
def demo(subject: Literal["alpha", "beta"], *, output: Literal["csv", "txt"] = "csv") -> None:
670+
"""Demo command."""
671+
672+
parser = Argparser(help_layout=layout, sys_exit_enabled=False, print_result=False)
673+
parser.add_command(demo)
674+
675+
help_text = parser.build_parser().format_help()
676+
assert expected_positional_choices in help_text
677+
assert expected_flag_choices in help_text
678+
679+
680+
@pytest.mark.parametrize(
681+
("layout", "expected_required_flag_choices"),
682+
[
683+
(StandardLayout(), "[choices: left, right]"),
684+
(ArgparseLayout(), "Choices: left, right."),
685+
(InterfacyLayout(), "[choices: left, right]"),
686+
(Modern(), "choices: left, right"),
687+
(Aligned(), "[choices: left, right]"),
688+
(AlignedTyped(), "[choices: left, right]"),
689+
(ClapLayout(), "[possible values: left, right]"),
690+
],
691+
)
692+
def test_all_layouts_render_literal_choices_for_required_flags(
693+
layout,
694+
expected_required_flag_choices: str,
695+
) -> None:
696+
def demo(*, axis: Literal["left", "right"], output: Literal["csv", "txt"] = "csv") -> None:
697+
"""Demo command."""
698+
699+
parser = Argparser(
700+
help_layout=layout,
701+
sys_exit_enabled=False,
702+
print_result=False,
703+
flag_strategy=DefaultFlagStrategy(style="keyword_only"),
704+
)
705+
parser.add_command(demo)
706+
707+
help_text = parser.build_parser().format_help()
708+
assert expected_required_flag_choices in help_text
709+
710+
623711
def test_clap_layout_wraps_long_possible_values() -> None:
624712
def list_items(
625713
sort: Literal[

0 commit comments

Comments
 (0)