for bool, generate --no-xxxx option

This commit is contained in:
2019-04-02 21:02:08 +02:00
parent 075de80f73
commit 266cef224e
2 changed files with 120 additions and 65 deletions

View File

@ -59,7 +59,7 @@ def get_config(has_tree=False):
def test_readme_help():
output = """usage: prog.py [-h] [-v] {str,list,int,none}
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
positional arguments:
{str,list,int,none} choice the sub argument
@ -67,6 +67,7 @@ positional arguments:
optional arguments:
-h, --help show this help message and exit
-v, --verbosity increase output verbosity
-nv, --no-verbosity
"""
parser = TiramisuCmdlineParser(get_config(), 'prog.py')
f = StringIO()
@ -76,7 +77,7 @@ optional arguments:
def test_readme_help_tree():
output = """usage: prog.py [-h] [-v] {str,list,int,none}
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
optional arguments:
-h, --help show this help message and exit
@ -84,6 +85,7 @@ optional arguments:
root:
{str,list,int,none} choice the sub argument
-v, --root.verbosity increase output verbosity
-nv, --root.no-verbosity
"""
parser = TiramisuCmdlineParser(get_config(True), 'prog.py')
f = StringIO()
@ -93,7 +95,7 @@ root:
def test_readme_help_tree_flatten():
output = """usage: prog.py [-h] [-v] {str,list,int,none}
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
optional arguments:
-h, --help show this help message and exit
@ -101,6 +103,7 @@ optional arguments:
root:
{str,list,int,none} choice the sub argument
-v, --verbosity increase output verbosity
-nv, --no-verbosity
"""
parser = TiramisuCmdlineParser(get_config(True), 'prog.py', fullpath=False)
f = StringIO()
@ -110,12 +113,13 @@ root:
def test_readme_help_modif_positional():
output = """usage: prog.py str [-h] [-v] --str STR
output = """usage: prog.py str [-h] [-v] [-nv] --str STR
optional arguments:
-h, --help show this help message and exit
-v, --verbosity increase output verbosity
--str STR string option
-h, --help show this help message and exit
-v, --verbosity increase output verbosity
-nv, --no-verbosity
--str STR string option
"""
parser = TiramisuCmdlineParser(get_config(), 'prog.py')
f = StringIO()
@ -130,11 +134,12 @@ optional arguments:
def test_readme_help_modif():
output = """usage: prog.py str --str toto [-h] [-v]
output = """usage: prog.py str --str toto [-h] [-v] [-nv]
optional arguments:
-h, --help show this help message and exit
-v, --verbosity increase output verbosity
-h, --help show this help message and exit
-v, --verbosity increase output verbosity
-nv, --no-verbosity
"""
parser = TiramisuCmdlineParser(get_config(), 'prog.py')
f = StringIO()
@ -167,8 +172,27 @@ optional arguments:
assert f.getvalue() == output
def test_readme_help_modif_short_no():
output = """usage: prog.py str --verbosity [-h] --str STR
optional arguments:
-h, --help show this help message and exit
--str STR string option
"""
parser = TiramisuCmdlineParser(get_config(), 'prog.py')
f = StringIO()
with redirect_stdout(f):
try:
parser.parse_args(['str', '-nv', '--help'])
except SystemExit as err:
assert str(err) == "0"
else:
raise Exception('must raises')
assert f.getvalue() == output
def test_readme_positional_mandatory():
output = """usage: prog.py [-h] [-v] {str,list,int,none}
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
prog.py: error: the following arguments are required: cmd
"""
parser = TiramisuCmdlineParser(get_config(), 'prog.py')
@ -184,7 +208,7 @@ prog.py: error: the following arguments are required: cmd
def test_readme_positional_mandatory_tree():
output = """usage: prog.py [-h] [-v] {str,list,int,none}
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
prog.py: error: the following arguments are required: root.cmd
"""
parser = TiramisuCmdlineParser(get_config(True), 'prog.py')
@ -200,7 +224,7 @@ prog.py: error: the following arguments are required: root.cmd
def test_readme_positional_mandatory_tree_flatten():
output = """usage: prog.py [-h] [-v] {str,list,int,none}
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
prog.py: error: the following arguments are required: cmd
"""
parser = TiramisuCmdlineParser(get_config(True), 'prog.py', fullpath=False)
@ -216,7 +240,7 @@ prog.py: error: the following arguments are required: cmd
def test_readme_mandatory():
output = """usage: prog.py str [-h] [-v] --str STR
output = """usage: prog.py str [-h] [-v] [-nv] --str STR
prog.py: error: the following arguments are required: --str
"""
parser = TiramisuCmdlineParser(get_config(), 'prog.py')
@ -232,7 +256,7 @@ prog.py: error: the following arguments are required: --str
def test_readme_mandatory_tree():
output = """usage: prog.py str [-h] [-v] --root.str STR
output = """usage: prog.py str [-h] [-v] [-nv] --root.str STR
prog.py: error: the following arguments are required: --root.str
"""
parser = TiramisuCmdlineParser(get_config(True), 'prog.py')
@ -248,7 +272,7 @@ prog.py: error: the following arguments are required: --root.str
def test_readme_mandatory_tree_flatten():
output = """usage: prog.py str [-h] [-v] --str STR
output = """usage: prog.py str [-h] [-v] [-nv] --str STR
prog.py: error: the following arguments are required: --str
"""
parser = TiramisuCmdlineParser(get_config(True), 'prog.py', fullpath=False)
@ -264,7 +288,7 @@ prog.py: error: the following arguments are required: --str
def test_readme_cross():
output = """usage: prog.py none [-h] [-v]
output = """usage: prog.py none [-h] [-v] [-nv]
prog.py: error: unrecognized arguments: --int
"""
parser = TiramisuCmdlineParser(get_config(), 'prog.py')
@ -280,7 +304,7 @@ prog.py: error: unrecognized arguments: --int
def test_readme_cross_tree():
output = """usage: prog.py none [-h] [-v]
output = """usage: prog.py none [-h] [-v] [-nv]
prog.py: error: unrecognized arguments: --int
"""
parser = TiramisuCmdlineParser(get_config(True), 'prog.py')
@ -296,7 +320,7 @@ prog.py: error: unrecognized arguments: --int
def test_readme_cross_tree_flatten():
output = """usage: prog.py none [-h] [-v]
output = """usage: prog.py none [-h] [-v] [-nv]
prog.py: error: unrecognized arguments: --int
"""
parser = TiramisuCmdlineParser(get_config(True), 'prog.py', fullpath=False)
@ -388,6 +412,17 @@ def test_readme_int_verbosity_short():
assert config.value.dict() == output
def test_readme_int_verbosity_short_no():
output = {'cmd': 'int',
'int': 3,
'verbosity': False,
'v': False}
config = get_config()
parser = TiramisuCmdlineParser(config, 'prog.py')
parser.parse_args(['int', '--int', '3', '-nv'])
assert config.value.dict() == output
def test_readme_int_verbosity_short_tree():
output = {'root.cmd': 'int',
'root.int': 3,