remove OD with no description in help if option remove_empty_description_od set to True

This commit is contained in:
2019-07-26 15:40:54 +02:00
parent 3d0ac1fb19
commit 62c0812863
2 changed files with 47 additions and 3 deletions

View File

@ -42,7 +42,7 @@ def get_config(json, has_tree=False, default_verbosity=False, add_long=False, ad
'Sub-Tree 2',
[str_])
od2 = OptionDescription('od2',
'Second OptionDescription',
'',
[before, subtree, after])
root = OptionDescription('root',
'root',
@ -80,7 +80,7 @@ od1.od0:
-nv, --od1.od0.no-verbosity
od2:
Second OptionDescription
od2
--od2.before BEFORE Before
--od2.after AFTER After
@ -115,7 +115,7 @@ od1.od0:
-nv, --od1.od0.no-verbosity
od2:
Second OptionDescription
od2
--od2.before BEFORE Before
--od2.after AFTER After
@ -133,6 +133,38 @@ od2.subtree:
assert f.getvalue() == output
def test_optiondescription_help_remove_empty_description_od(json):
output = """usage: prog.py [-h] [-v] [-nv] --od2.subtree.str STR --od2.before BEFORE
--od2.after AFTER
{str,list,int,none}
optional arguments:
-h, --help show this help message and exit
od1:
First OptionDescription
od1.od0:
Sub-Tree 1
{str,list,int,none} choice the sub argument
-v, --od1.od0.verbosity
increase output verbosity
-nv, --od1.od0.no-verbosity
od2.subtree:
Sub-Tree 2
--od2.subtree.str STR
string option 2
"""
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', remove_empty_description_od=True)
f = StringIO()
with redirect_stdout(f):
parser.print_help()
assert f.getvalue() == output
def test_optiondescription_help_subtree(json):
output = """usage: prog.py [-h] --od2.subtree.str STR --od2.before BEFORE --od2.after
AFTER