help with modified positional argument

This commit is contained in:
2019-04-02 08:49:36 +02:00
parent f90c02282a
commit 3ac9031411
2 changed files with 79 additions and 56 deletions

View File

@ -109,6 +109,26 @@ root:
assert f.getvalue() == output
def test_readme_help_modif():
output = """usage: prog.py str [-h] [-v] --str STR
optional arguments:
-h, --help show this help message and exit
-v, --verbosity increase output verbosity
--str STR string option
"""
parser = TiramisuCmdlineParser(get_config(), 'prog.py')
f = StringIO()
with redirect_stdout(f):
try:
parser.parse_args(['str', '--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}
prog.py: error: the following arguments are required: cmd
@ -158,7 +178,7 @@ prog.py: error: the following arguments are required: cmd
def test_readme_mandatory():
output = """usage: prog.py [-h] [-v] --str STR {str,list,int,none}
output = """usage: prog.py str [-h] [-v] --str STR
prog.py: error: the following arguments are required: --str
"""
parser = TiramisuCmdlineParser(get_config(), 'prog.py')
@ -174,7 +194,7 @@ prog.py: error: the following arguments are required: --str
def test_readme_mandatory_tree():
output = """usage: prog.py [-h] [-v] --root.str STR {str,list,int,none}
output = """usage: prog.py str [-h] [-v] --root.str STR
prog.py: error: the following arguments are required: --root.str
"""
parser = TiramisuCmdlineParser(get_config(True), 'prog.py')
@ -190,7 +210,7 @@ prog.py: error: the following arguments are required: --root.str
def test_readme_mandatory_tree_flatten():
output = """usage: prog.py [-h] [-v] --str STR {str,list,int,none}
output = """usage: prog.py str [-h] [-v] --str STR
prog.py: error: the following arguments are required: --str
"""
parser = TiramisuCmdlineParser(get_config(True), 'prog.py', fullpath=False)
@ -206,7 +226,7 @@ prog.py: error: the following arguments are required: --str
def test_readme_cross():
output = """usage: prog.py [-h] [-v] {str,list,int,none}
output = """usage: prog.py none [-h] [-v]
prog.py: error: unrecognized arguments: --int
"""
parser = TiramisuCmdlineParser(get_config(), 'prog.py')
@ -222,7 +242,7 @@ prog.py: error: unrecognized arguments: --int
def test_readme_cross_tree():
output = """usage: prog.py [-h] [-v] {str,list,int,none}
output = """usage: prog.py none [-h] [-v]
prog.py: error: unrecognized arguments: --int
"""
parser = TiramisuCmdlineParser(get_config(True), 'prog.py')
@ -238,7 +258,7 @@ prog.py: error: unrecognized arguments: --int
def test_readme_cross_tree_flatten():
output = """usage: prog.py [-h] [-v] {str,list,int,none}
output = """usage: prog.py none [-h] [-v]
prog.py: error: unrecognized arguments: --int
"""
parser = TiramisuCmdlineParser(get_config(True), 'prog.py', fullpath=False)