def test_basic_help_text2(): p = Parser( Opt('-n', nargs = 1, sections = ['foo', 'bar', 'blort'], text = 'N of times to do it'), Opt('-f -x --foo', sections = ['foo'], text = 'Some Foo behavior'), dict(option_spec = '--bar', nargs = 5), Opt('<x>', text = 'The X file'), Opt('<y>', text = 'The Y file'), program = 'frob', ) exp = dedent(''' Usage: frob -n --foo --bar <x> <y> Foo options: -n N of times to do it --foo Some Foo behavior Bar options: -n N of times to do it Blort options: -n N of times to do it Positional arguments: <x> The X file <y> The Y file Options: --bar Aliases: --foo -f -x ''') got = p.help_text() assert exp == got
def test_basic_help_text1(): long_help = 'The N of times to do the operation that needs to be done, either now or in the future' p = Parser( Opt('-n', nargs = 1, sections = ['foo', 'bar', 'blort'], text = long_help), Opt('--foo', sections = ['foo'], text = 'Some Foo behavior'), Opt('--xy X Y', sections = ['foo'], text = 'Some xy behavior'), dict(option_spec = '--bar', nargs = 5), Opt('--some_long_opt1'), Opt('--some_crazy_insane_long_opt2', text = long_help), Opt('--some_long_opt3'), Opt('--some_long_opt4'), Opt('--some_long_opt5'), Opt('--some_long_opt6'), Opt('--some_long_opt7'), Opt('<x>', text = 'The X file'), Opt('<y>', text = 'The Y file'), formatter_config = FormatterConfig( Section('foo', 'Foo options'), Section(SectionName.POS), Section('bar', 'Bar options'), Section(SectionName.OPT, 'Some Options'), Section(SectionName.USAGE, 'Usage'), ), ) exp = dedent(''' Foo options: -n The N of times to do the operation that needs to be done, either now or in the future --foo Some Foo behavior --xy X Y Some xy behavior Positional arguments: <x> The X file <y> The Y file Bar options: -n The N of times to do the operation that needs to be done, either now or in the future Some Options: --bar --some_long_opt1 --some_crazy_insane_long_opt2 The N of times to do the operation that needs to be done, either now or in the future --some_long_opt3 --some_long_opt4 --some_long_opt5 --some_long_opt6 --some_long_opt7 Usage: cli -n --foo [--xy X Y] --bar --some_long_opt1 --some_crazy_insane_long_opt2 --some_long_opt3 --some_long_opt4 --some_long_opt5 --some_long_opt6 --some_long_opt7 <x> <y> Blort options: -n The N of times to do the operation that needs to be done, either now or in the future ''') got = p.help_text() assert exp == got exp = dedent(''' Foo options: -n The N of times to do the operation that needs to be done, either now or in the future --foo Some Foo behavior --xy X Y Some xy behavior Bar options: -n The N of times to do the operation that needs to be done, either now or in the future ''') got = p.help_text('foo', 'bar') assert exp == got