2018-12-01 09:53:31 +01:00
|
|
|
from io import StringIO
|
|
|
|
from contextlib import redirect_stdout, redirect_stderr
|
|
|
|
|
|
|
|
|
|
|
|
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
|
|
|
from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
|
|
|
SymLinkOption, OptionDescription, Config
|
|
|
|
|
|
|
|
|
2019-04-01 21:08:41 +02:00
|
|
|
def get_config(has_tree=False):
|
2018-12-01 09:53:31 +01:00
|
|
|
choiceoption = ChoiceOption('cmd',
|
|
|
|
'choice the sub argument',
|
2019-02-27 07:32:32 +01:00
|
|
|
('str', 'list', 'int', 'none'),
|
2018-12-01 09:53:31 +01:00
|
|
|
properties=('mandatory',
|
|
|
|
'positional'))
|
|
|
|
booloption = BoolOption('verbosity',
|
|
|
|
'increase output verbosity',
|
|
|
|
default=False)
|
|
|
|
short_booloption = SymLinkOption('v', booloption)
|
|
|
|
str_ = StrOption('str',
|
|
|
|
'string option',
|
|
|
|
properties=('mandatory',),
|
|
|
|
requires=[{'option': choiceoption,
|
|
|
|
'expected': 'str',
|
|
|
|
'action': 'disabled',
|
|
|
|
'inverse': True}])
|
|
|
|
list_ = StrOption('list',
|
|
|
|
'list string option',
|
|
|
|
multi=True,
|
|
|
|
properties=('mandatory',),
|
|
|
|
requires=[{'option': choiceoption,
|
|
|
|
'expected': 'list',
|
|
|
|
'action': 'disabled',
|
|
|
|
'inverse': True}])
|
|
|
|
int_ = IntOption('int',
|
|
|
|
'int option',
|
|
|
|
properties=('mandatory',),
|
|
|
|
requires=[{'option': choiceoption,
|
|
|
|
'expected': 'int',
|
|
|
|
'action': 'disabled',
|
|
|
|
'inverse': True}])
|
2019-04-01 21:08:41 +02:00
|
|
|
|
|
|
|
root = OptionDescription('root',
|
|
|
|
'root',
|
|
|
|
[choiceoption,
|
|
|
|
booloption,
|
|
|
|
short_booloption,
|
|
|
|
str_,
|
|
|
|
list_,
|
|
|
|
int_
|
|
|
|
])
|
|
|
|
if has_tree:
|
|
|
|
root = OptionDescription('root',
|
|
|
|
'root',
|
|
|
|
[root])
|
|
|
|
config = Config(root)
|
2019-02-27 07:32:32 +01:00
|
|
|
config.property.read_write()
|
|
|
|
return config
|
2018-12-01 09:53:31 +01:00
|
|
|
|
2019-04-01 21:08:41 +02:00
|
|
|
|
2018-12-01 09:53:31 +01:00
|
|
|
def test_readme_help():
|
2019-02-27 07:32:32 +01:00
|
|
|
output = """usage: prog.py [-h] [-v] {str,list,int,none}
|
2018-12-01 09:53:31 +01:00
|
|
|
|
|
|
|
positional arguments:
|
2019-02-27 07:32:32 +01:00
|
|
|
{str,list,int,none} choice the sub argument
|
2018-12-01 09:53:31 +01:00
|
|
|
|
|
|
|
optional arguments:
|
2019-02-27 07:32:32 +01:00
|
|
|
-h, --help show this help message and exit
|
|
|
|
-v, --verbosity increase output verbosity
|
2018-12-01 09:53:31 +01:00
|
|
|
"""
|
2019-02-27 07:32:32 +01:00
|
|
|
parser = TiramisuCmdlineParser(get_config(), 'prog.py')
|
2018-12-01 09:53:31 +01:00
|
|
|
f = StringIO()
|
|
|
|
with redirect_stdout(f):
|
|
|
|
parser.print_help()
|
|
|
|
assert f.getvalue() == output
|
|
|
|
|
|
|
|
|
2019-04-01 21:08:41 +02:00
|
|
|
def test_readme_help_tree():
|
|
|
|
output = """usage: prog.py [-h] [-v] {str,list,int,none}
|
|
|
|
|
|
|
|
optional arguments:
|
|
|
|
-h, --help show this help message and exit
|
|
|
|
|
|
|
|
root:
|
|
|
|
{str,list,int,none} choice the sub argument
|
|
|
|
-v, --root.verbosity increase output verbosity
|
|
|
|
"""
|
|
|
|
parser = TiramisuCmdlineParser(get_config(True), 'prog.py')
|
|
|
|
f = StringIO()
|
|
|
|
with redirect_stdout(f):
|
|
|
|
parser.print_help()
|
|
|
|
assert f.getvalue() == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_readme_help_tree_flatten():
|
|
|
|
output = """usage: prog.py [-h] [-v] {str,list,int,none}
|
|
|
|
|
|
|
|
optional arguments:
|
|
|
|
-h, --help show this help message and exit
|
|
|
|
|
|
|
|
root:
|
|
|
|
{str,list,int,none} choice the sub argument
|
|
|
|
-v, --verbosity increase output verbosity
|
|
|
|
"""
|
|
|
|
parser = TiramisuCmdlineParser(get_config(True), 'prog.py', fullpath=False)
|
|
|
|
f = StringIO()
|
|
|
|
with redirect_stdout(f):
|
|
|
|
parser.print_help()
|
|
|
|
assert f.getvalue() == output
|
|
|
|
|
|
|
|
|
2019-04-02 19:01:17 +02:00
|
|
|
def test_readme_help_modif_positional():
|
2019-04-02 08:49:36 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2019-04-02 19:01:17 +02:00
|
|
|
def test_readme_help_modif():
|
|
|
|
output = """usage: prog.py str --str toto [-h] [-v]
|
|
|
|
|
|
|
|
optional arguments:
|
|
|
|
-h, --help show this help message and exit
|
|
|
|
-v, --verbosity increase output verbosity
|
|
|
|
"""
|
|
|
|
parser = TiramisuCmdlineParser(get_config(), 'prog.py')
|
|
|
|
f = StringIO()
|
|
|
|
with redirect_stdout(f):
|
|
|
|
try:
|
|
|
|
parser.parse_args(['str', '--str', 'toto', '--help'])
|
|
|
|
except SystemExit as err:
|
|
|
|
assert str(err) == "0"
|
|
|
|
else:
|
|
|
|
raise Exception('must raises')
|
|
|
|
assert f.getvalue() == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_readme_help_modif_short():
|
|
|
|
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', '-v', '--help'])
|
|
|
|
except SystemExit as err:
|
|
|
|
assert str(err) == "0"
|
|
|
|
else:
|
|
|
|
raise Exception('must raises')
|
|
|
|
assert f.getvalue() == output
|
|
|
|
|
|
|
|
|
2018-12-01 09:53:31 +01:00
|
|
|
def test_readme_positional_mandatory():
|
2019-02-27 07:32:32 +01:00
|
|
|
output = """usage: prog.py [-h] [-v] {str,list,int,none}
|
2018-12-01 09:53:31 +01:00
|
|
|
prog.py: error: the following arguments are required: cmd
|
|
|
|
"""
|
2019-02-27 07:32:32 +01:00
|
|
|
parser = TiramisuCmdlineParser(get_config(), 'prog.py')
|
2018-12-01 09:53:31 +01:00
|
|
|
f = StringIO()
|
|
|
|
with redirect_stderr(f):
|
|
|
|
try:
|
|
|
|
parser.parse_args([])
|
|
|
|
except SystemExit as err:
|
|
|
|
assert str(err) == "2"
|
|
|
|
else:
|
|
|
|
raise Exception('must raises')
|
|
|
|
assert f.getvalue() == output
|
|
|
|
|
|
|
|
|
2019-04-01 21:08:41 +02:00
|
|
|
def test_readme_positional_mandatory_tree():
|
|
|
|
output = """usage: prog.py [-h] [-v] {str,list,int,none}
|
|
|
|
prog.py: error: the following arguments are required: root.cmd
|
|
|
|
"""
|
|
|
|
parser = TiramisuCmdlineParser(get_config(True), 'prog.py')
|
|
|
|
f = StringIO()
|
|
|
|
with redirect_stderr(f):
|
|
|
|
try:
|
|
|
|
parser.parse_args([])
|
|
|
|
except SystemExit as err:
|
|
|
|
assert str(err) == "2"
|
|
|
|
else:
|
|
|
|
raise Exception('must raises')
|
|
|
|
assert f.getvalue() == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_readme_positional_mandatory_tree_flatten():
|
|
|
|
output = """usage: prog.py [-h] [-v] {str,list,int,none}
|
|
|
|
prog.py: error: the following arguments are required: cmd
|
|
|
|
"""
|
|
|
|
parser = TiramisuCmdlineParser(get_config(True), 'prog.py', fullpath=False)
|
|
|
|
f = StringIO()
|
|
|
|
with redirect_stderr(f):
|
|
|
|
try:
|
|
|
|
parser.parse_args([])
|
|
|
|
except SystemExit as err:
|
|
|
|
assert str(err) == "2"
|
|
|
|
else:
|
|
|
|
raise Exception('must raises')
|
|
|
|
assert f.getvalue() == output
|
|
|
|
|
|
|
|
|
2018-12-01 09:53:31 +01:00
|
|
|
def test_readme_mandatory():
|
2019-04-02 08:49:36 +02:00
|
|
|
output = """usage: prog.py str [-h] [-v] --str STR
|
2018-12-01 09:53:31 +01:00
|
|
|
prog.py: error: the following arguments are required: --str
|
|
|
|
"""
|
2019-02-27 07:32:32 +01:00
|
|
|
parser = TiramisuCmdlineParser(get_config(), 'prog.py')
|
2018-12-01 09:53:31 +01:00
|
|
|
f = StringIO()
|
|
|
|
with redirect_stderr(f):
|
|
|
|
try:
|
|
|
|
parser.parse_args(['str'])
|
|
|
|
except SystemExit as err:
|
|
|
|
assert str(err) == "2"
|
|
|
|
else:
|
|
|
|
raise Exception('must raises')
|
|
|
|
assert f.getvalue() == output
|
|
|
|
|
|
|
|
|
2019-04-01 21:08:41 +02:00
|
|
|
def test_readme_mandatory_tree():
|
2019-04-02 08:49:36 +02:00
|
|
|
output = """usage: prog.py str [-h] [-v] --root.str STR
|
2019-04-01 21:08:41 +02:00
|
|
|
prog.py: error: the following arguments are required: --root.str
|
|
|
|
"""
|
|
|
|
parser = TiramisuCmdlineParser(get_config(True), 'prog.py')
|
|
|
|
f = StringIO()
|
|
|
|
with redirect_stderr(f):
|
|
|
|
try:
|
|
|
|
parser.parse_args(['str'])
|
|
|
|
except SystemExit as err:
|
|
|
|
assert str(err) == "2"
|
|
|
|
else:
|
|
|
|
raise Exception('must raises')
|
|
|
|
assert f.getvalue() == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_readme_mandatory_tree_flatten():
|
2019-04-02 08:49:36 +02:00
|
|
|
output = """usage: prog.py str [-h] [-v] --str STR
|
2019-04-01 21:08:41 +02:00
|
|
|
prog.py: error: the following arguments are required: --str
|
|
|
|
"""
|
|
|
|
parser = TiramisuCmdlineParser(get_config(True), 'prog.py', fullpath=False)
|
|
|
|
f = StringIO()
|
|
|
|
with redirect_stderr(f):
|
|
|
|
try:
|
|
|
|
parser.parse_args(['str'])
|
|
|
|
except SystemExit as err:
|
|
|
|
assert str(err) == "2"
|
|
|
|
else:
|
|
|
|
raise Exception('must raises')
|
|
|
|
assert f.getvalue() == output
|
|
|
|
|
|
|
|
|
2018-12-01 09:53:31 +01:00
|
|
|
def test_readme_cross():
|
2019-04-02 08:49:36 +02:00
|
|
|
output = """usage: prog.py none [-h] [-v]
|
2018-12-01 09:53:31 +01:00
|
|
|
prog.py: error: unrecognized arguments: --int
|
|
|
|
"""
|
2019-02-27 07:32:32 +01:00
|
|
|
parser = TiramisuCmdlineParser(get_config(), 'prog.py')
|
2018-12-01 09:53:31 +01:00
|
|
|
f = StringIO()
|
|
|
|
with redirect_stderr(f):
|
|
|
|
try:
|
2019-02-27 07:32:32 +01:00
|
|
|
parser.parse_args(['none', '--int'])
|
2018-12-01 09:53:31 +01:00
|
|
|
except SystemExit as err:
|
|
|
|
assert str(err) == "2"
|
|
|
|
else:
|
|
|
|
raise Exception('must raises')
|
|
|
|
assert f.getvalue() == output
|
|
|
|
|
|
|
|
|
2019-04-01 21:08:41 +02:00
|
|
|
def test_readme_cross_tree():
|
2019-04-02 08:49:36 +02:00
|
|
|
output = """usage: prog.py none [-h] [-v]
|
2019-04-01 21:08:41 +02:00
|
|
|
prog.py: error: unrecognized arguments: --int
|
|
|
|
"""
|
|
|
|
parser = TiramisuCmdlineParser(get_config(True), 'prog.py')
|
|
|
|
f = StringIO()
|
|
|
|
with redirect_stderr(f):
|
|
|
|
try:
|
|
|
|
parser.parse_args(['none', '--int'])
|
|
|
|
except SystemExit as err:
|
|
|
|
assert str(err) == "2"
|
|
|
|
else:
|
|
|
|
raise Exception('must raises')
|
|
|
|
assert f.getvalue() == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_readme_cross_tree_flatten():
|
2019-04-02 08:49:36 +02:00
|
|
|
output = """usage: prog.py none [-h] [-v]
|
2019-04-01 21:08:41 +02:00
|
|
|
prog.py: error: unrecognized arguments: --int
|
|
|
|
"""
|
|
|
|
parser = TiramisuCmdlineParser(get_config(True), 'prog.py', fullpath=False)
|
|
|
|
f = StringIO()
|
|
|
|
with redirect_stderr(f):
|
|
|
|
try:
|
|
|
|
parser.parse_args(['none', '--int'])
|
|
|
|
except SystemExit as err:
|
|
|
|
assert str(err) == "2"
|
|
|
|
else:
|
|
|
|
raise Exception('must raises')
|
|
|
|
assert f.getvalue() == output
|
|
|
|
|
|
|
|
|
2018-12-01 09:53:31 +01:00
|
|
|
def test_readme_int():
|
|
|
|
output = {'cmd': 'int',
|
|
|
|
'int': 3,
|
|
|
|
'verbosity': False,
|
|
|
|
'v': False}
|
|
|
|
config = get_config()
|
2019-02-27 07:32:32 +01:00
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
2018-12-01 09:53:31 +01:00
|
|
|
parser.parse_args(['int', '--int', '3'])
|
2019-04-01 21:08:41 +02:00
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_readme_int_tree():
|
|
|
|
output = {'root.cmd': 'int',
|
|
|
|
'root.int': 3,
|
|
|
|
'root.verbosity': False,
|
|
|
|
'root.v': False}
|
|
|
|
config = get_config(True)
|
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
|
|
|
parser.parse_args(['int', '--root.int', '3'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_readme_int_tree_flatten():
|
|
|
|
output = {'root.cmd': 'int',
|
|
|
|
'root.int': 3,
|
|
|
|
'root.verbosity': False,
|
|
|
|
'root.v': False}
|
|
|
|
config = get_config(True)
|
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
|
|
|
parser.parse_args(['int', '--int', '3'])
|
|
|
|
assert config.value.dict() == output
|
2018-12-01 09:53:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_readme_int_verbosity():
|
|
|
|
output = {'cmd': 'int',
|
|
|
|
'int': 3,
|
|
|
|
'verbosity': True,
|
|
|
|
'v': True}
|
|
|
|
config = get_config()
|
2019-02-27 07:32:32 +01:00
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
2018-12-01 09:53:31 +01:00
|
|
|
parser.parse_args(['int', '--int', '3', '--verbosity'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
2019-04-01 21:08:41 +02:00
|
|
|
def test_readme_int_verbosity_tree():
|
|
|
|
output = {'root.cmd': 'int',
|
|
|
|
'root.int': 3,
|
|
|
|
'root.verbosity': True,
|
|
|
|
'root.v': True}
|
|
|
|
config = get_config(True)
|
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
|
|
|
parser.parse_args(['int', '--root.int', '3', '--root.verbosity'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_readme_int_verbosity_tree_flatten():
|
|
|
|
output = {'root.cmd': 'int',
|
|
|
|
'root.int': 3,
|
|
|
|
'root.verbosity': True,
|
|
|
|
'root.v': True}
|
|
|
|
config = get_config(True)
|
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
|
|
|
parser.parse_args(['int', '--int', '3', '--verbosity'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
2018-12-01 09:53:31 +01:00
|
|
|
def test_readme_int_verbosity_short():
|
|
|
|
output = {'cmd': 'int',
|
|
|
|
'int': 3,
|
|
|
|
'verbosity': True,
|
|
|
|
'v': True}
|
|
|
|
config = get_config()
|
2019-02-27 07:32:32 +01:00
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
2018-12-01 09:53:31 +01:00
|
|
|
parser.parse_args(['int', '--int', '3', '-v'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
2019-04-01 21:08:41 +02:00
|
|
|
def test_readme_int_verbosity_short_tree():
|
|
|
|
output = {'root.cmd': 'int',
|
|
|
|
'root.int': 3,
|
|
|
|
'root.verbosity': True,
|
|
|
|
'root.v': True}
|
|
|
|
config = get_config(True)
|
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
|
|
|
parser.parse_args(['int', '--root.int', '3', '-v'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_readme_int_verbosity_short_tree_flatten():
|
|
|
|
output = {'root.cmd': 'int',
|
|
|
|
'root.int': 3,
|
|
|
|
'root.verbosity': True,
|
|
|
|
'root.v': True}
|
|
|
|
config = get_config(True)
|
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
|
|
|
parser.parse_args(['int', '--int', '3', '-v'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
2018-12-01 09:53:31 +01:00
|
|
|
def test_readme_str():
|
|
|
|
output = {'cmd': 'str',
|
|
|
|
'str': 'value',
|
|
|
|
'verbosity': False,
|
|
|
|
'v': False}
|
|
|
|
config = get_config()
|
2019-02-27 07:32:32 +01:00
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
2018-12-01 09:53:31 +01:00
|
|
|
parser.parse_args(['str', '--str', 'value'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
2019-04-01 21:08:41 +02:00
|
|
|
def test_readme_str_tree():
|
|
|
|
output = {'root.cmd': 'str',
|
|
|
|
'root.str': 'value',
|
|
|
|
'root.verbosity': False,
|
|
|
|
'root.v': False}
|
|
|
|
config = get_config(True)
|
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
|
|
|
parser.parse_args(['str', '--root.str', 'value'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_readme_str_tree_flatten():
|
|
|
|
output = {'root.cmd': 'str',
|
|
|
|
'root.str': 'value',
|
|
|
|
'root.verbosity': False,
|
|
|
|
'root.v': False}
|
|
|
|
config = get_config(True)
|
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
|
|
|
parser.parse_args(['str', '--str', 'value'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
2018-12-01 09:53:31 +01:00
|
|
|
def test_readme_str_int():
|
|
|
|
output = {'cmd': 'str',
|
|
|
|
'str': '3',
|
|
|
|
'verbosity': False,
|
|
|
|
'v': False}
|
|
|
|
config = get_config()
|
2019-02-27 07:32:32 +01:00
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
2018-12-01 09:53:31 +01:00
|
|
|
parser.parse_args(['str', '--str', '3'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
2019-04-01 21:08:41 +02:00
|
|
|
def test_readme_str_int_tree():
|
|
|
|
output = {'root.cmd': 'str',
|
|
|
|
'root.str': '3',
|
|
|
|
'root.verbosity': False,
|
|
|
|
'root.v': False}
|
|
|
|
config = get_config(True)
|
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
|
|
|
parser.parse_args(['str', '--root.str', '3'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_readme_str_int_tree_flatten():
|
|
|
|
output = {'root.cmd': 'str',
|
|
|
|
'root.str': '3',
|
|
|
|
'root.verbosity': False,
|
|
|
|
'root.v': False}
|
|
|
|
config = get_config(True)
|
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
|
|
|
parser.parse_args(['str', '--str', '3'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
2018-12-01 09:53:31 +01:00
|
|
|
def test_readme_list():
|
|
|
|
output = {'cmd': 'list',
|
|
|
|
'list': ['a', 'b', 'c'],
|
|
|
|
'verbosity': False,
|
|
|
|
'v': False}
|
|
|
|
config = get_config()
|
2019-02-27 07:32:32 +01:00
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
2018-12-01 09:53:31 +01:00
|
|
|
parser.parse_args(['list', '--list', 'a', 'b', 'c'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
2019-04-01 21:08:41 +02:00
|
|
|
def test_readme_list_tree():
|
|
|
|
output = {'root.cmd': 'list',
|
|
|
|
'root.list': ['a', 'b', 'c'],
|
|
|
|
'root.verbosity': False,
|
|
|
|
'root.v': False}
|
|
|
|
config = get_config(True)
|
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
|
|
|
parser.parse_args(['list', '--root.list', 'a', 'b', 'c'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_readme_list_tree_flatten():
|
|
|
|
output = {'root.cmd': 'list',
|
|
|
|
'root.list': ['a', 'b', 'c'],
|
|
|
|
'root.verbosity': False,
|
|
|
|
'root.v': False}
|
|
|
|
config = get_config(True)
|
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
|
|
|
parser.parse_args(['list', '--list', 'a', 'b', 'c'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
2018-12-01 09:53:31 +01:00
|
|
|
def test_readme_list_uniq():
|
|
|
|
output = {'cmd': 'list',
|
|
|
|
'list': ['a'],
|
|
|
|
'verbosity': False,
|
|
|
|
'v': False}
|
|
|
|
config = get_config()
|
2019-02-27 07:32:32 +01:00
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
2018-12-01 09:53:31 +01:00
|
|
|
parser.parse_args(['list', '--list', 'a'])
|
|
|
|
assert config.value.dict() == output
|
2019-04-01 21:08:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_readme_list_uniq_tree():
|
|
|
|
output = {'root.cmd': 'list',
|
|
|
|
'root.list': ['a'],
|
|
|
|
'root.verbosity': False,
|
|
|
|
'root.v': False}
|
|
|
|
config = get_config(True)
|
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
|
|
|
parser.parse_args(['list', '--root.list', 'a'])
|
|
|
|
assert config.value.dict() == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_readme_list_uniq_tree_flatten():
|
|
|
|
output = {'root.cmd': 'list',
|
|
|
|
'root.list': ['a'],
|
|
|
|
'root.verbosity': False,
|
|
|
|
'root.v': False}
|
|
|
|
config = get_config(True)
|
|
|
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
|
|
|
parser.parse_args(['list', '--list', 'a'])
|
|
|
|
assert config.value.dict() == output
|