Compare commits
10 commits
e6a9a37607
...
54c84713ee
| Author | SHA1 | Date | |
|---|---|---|---|
| 54c84713ee | |||
|
|
891668c00f | ||
|
|
c9a911870d | ||
|
|
7f95b1bfb0 | ||
|
|
c13da02553 | ||
|
|
505af25995 | ||
|
|
1bcfa0618a | ||
|
|
c26da98525 | ||
|
|
ed54090710 | ||
|
|
46866f1e38 |
11 changed files with 574 additions and 311 deletions
2
setup.py
2
setup.py
|
|
@ -15,7 +15,7 @@ setup(
|
|||
description="command-line parser using Tiramisu.",
|
||||
url='https://framagit.org/tiramisu/tiramisu-cmdline-parser',
|
||||
license='GNU Library or Lesser General Public License (LGPL)',
|
||||
install_requires=["tiramisu_api>=0.1"],
|
||||
install_requires=["tiramisu>=5.0"],
|
||||
classifiers=[
|
||||
"Programming Language :: Python :: 3",
|
||||
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
|
||||
|
|
|
|||
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
196
tests/test_choice.py
Normal file
196
tests/test_choice.py
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
from io import StringIO
|
||||
from contextlib import redirect_stdout, redirect_stderr
|
||||
import pytest
|
||||
|
||||
|
||||
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||
from tiramisu import ChoiceOption, OptionDescription, Config
|
||||
try:
|
||||
from tiramisu_api import Config as JsonConfig
|
||||
#params = ['tiramisu', 'tiramisu-json']
|
||||
params = ['tiramisu']
|
||||
except:
|
||||
params = ['tiramisu']
|
||||
|
||||
from .utils import TestHelpFormatter, to_dict
|
||||
|
||||
|
||||
def get_config(json):
|
||||
positional = ChoiceOption('positional',
|
||||
'choice the sub argument',
|
||||
('str', 'list', 'int', 'none'),
|
||||
properties=('positional', 'mandatory'))
|
||||
positional_int = ChoiceOption('positional_int',
|
||||
'choice the sub argument',
|
||||
(1, 2, 3),
|
||||
properties=('positional', 'mandatory'))
|
||||
str_ = ChoiceOption('str',
|
||||
'choice the sub argument',
|
||||
('str1', 'str2', 'str3'))
|
||||
int_ = ChoiceOption('int',
|
||||
'choice the sub argument',
|
||||
(1, 2, 3))
|
||||
int_multi = ChoiceOption('int_multi',
|
||||
'choice the sub argument',
|
||||
(1, 2, 3),
|
||||
multi=True)
|
||||
od = OptionDescription('od',
|
||||
'od',
|
||||
[positional, positional_int, str_, int_, int_multi])
|
||||
config = Config(od)
|
||||
config.property.read_write()
|
||||
if json == 'tiramisu':
|
||||
return config
|
||||
jconfig = JsonConfig(config.option.get())
|
||||
return jconfig
|
||||
|
||||
|
||||
@pytest.fixture(params=params)
|
||||
def json(request):
|
||||
return request.param
|
||||
|
||||
|
||||
def test_choice_positional(json):
|
||||
output1 = '''usage: prog.py "str" "1" [-h] [--str {str1,str2,str3}] [--int {1,2,3}] [--int_multi [{1,2,3} ...]] {str,list,int,none} {1,2,3}
|
||||
prog.py: error: argument positional: invalid choice: 'error' (choose from 'str', 'list', 'int', 'none')
|
||||
'''
|
||||
output2 = '''usage: prog.py "str" "1" [-h] [--str {str1,str2,str3}] [--int {1,2,3}] [--int_multi [{1,2,3} ...]] {str,list,int,none} {1,2,3}
|
||||
prog.py: error: argument positional_int: invalid choice: '4' (choose from '1', '2', '3')
|
||||
'''
|
||||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||
parser.parse_args(['str', '1'])
|
||||
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||
'positional_int': 1,
|
||||
'str': None,
|
||||
'int': None,
|
||||
'int_multi': []}
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['error', '1'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
raise Exception('must raises')
|
||||
assert f.getvalue() == output1
|
||||
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['str', '4'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
raise Exception('must raises')
|
||||
assert f.getvalue() == output2
|
||||
|
||||
|
||||
def test_choice_str(json):
|
||||
output = """usage: prog.py "str" "1" --str "str3" [-h] [--str {str1,str2,str3}] [--int {1,2,3}] [--int_multi [{1,2,3} ...]] {str,list,int,none} {1,2,3}
|
||||
prog.py: error: argument --str: invalid choice: 'error' (choose from 'str1', 'str2', 'str3')
|
||||
"""
|
||||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||
parser.parse_args(['str', '1', '--str', 'str1'])
|
||||
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||
'positional_int': 1,
|
||||
'str': 'str1',
|
||||
'int': None,
|
||||
'int_multi': []}
|
||||
parser.parse_args(['str', '1', '--str', 'str2'])
|
||||
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||
'positional_int': 1,
|
||||
'str': 'str2',
|
||||
'int': None,
|
||||
'int_multi': []}
|
||||
parser.parse_args(['str', '1', '--str', 'str3'])
|
||||
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||
'positional_int': 1,
|
||||
'str': 'str3',
|
||||
'int': None,
|
||||
'int_multi': []}
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['str', '1', '--str', 'error'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
raise Exception('must raises')
|
||||
assert f.getvalue() == output
|
||||
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||
'positional_int': 1,
|
||||
'str': 'str3',
|
||||
'int': None,
|
||||
'int_multi': []}
|
||||
|
||||
|
||||
def test_choice_int(json):
|
||||
output = """usage: prog.py "str" "1" --int "1" [-h] [--str {str1,str2,str3}] [--int {1,2,3}] [--int_multi [{1,2,3} ...]] {str,list,int,none} {1,2,3}
|
||||
prog.py: error: argument --int: invalid choice: '4' (choose from '1', '2', '3')
|
||||
"""
|
||||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||
parser.parse_args(['str', '1', '--int', '1'])
|
||||
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||
'positional_int': 1,
|
||||
'str': None,
|
||||
'int': 1,
|
||||
'int_multi': []}
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['str', '1', '--int', '4'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
raise Exception('must raises')
|
||||
assert f.getvalue() == output
|
||||
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||
'positional_int': 1,
|
||||
'str': None,
|
||||
'int': 1,
|
||||
'int_multi': []}
|
||||
|
||||
|
||||
def test_choice_int_multi(json):
|
||||
output = """usage: prog.py "str" "1" --int_multi "1" "2" [-h] [--str {str1,str2,str3}] [--int {1,2,3}] [--int_multi [{1,2,3} ...]] {str,list,int,none} {1,2,3}
|
||||
prog.py: error: argument --int_multi: invalid choice: '4' (choose from '1', '2', '3')
|
||||
"""
|
||||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||
parser.parse_args(['str', '1', '--int_multi', '1', '2'])
|
||||
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||
'positional_int': 1,
|
||||
'str': None,
|
||||
'int': None,
|
||||
'int_multi': [1, 2]}
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['str', '1', '--int_multi', '4'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
raise Exception('must raises')
|
||||
assert f.getvalue() == output
|
||||
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||
'positional_int': 1,
|
||||
'str': None,
|
||||
'int': None,
|
||||
'int_multi': [1, 2]}
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['str', '1', '--int_multi', '1', '4'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
raise Exception('must raises')
|
||||
assert f.getvalue() == output
|
||||
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||
'positional_int': 1,
|
||||
'str': None,
|
||||
'int': None,
|
||||
'int_multi': [1, 2]}
|
||||
|
|
@ -6,8 +6,14 @@ from argparse import RawDescriptionHelpFormatter
|
|||
|
||||
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||
from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
||||
SymLinkOption, OptionDescription, Config
|
||||
from tiramisu_api import Config as JsonConfig
|
||||
OptionDescription, Config
|
||||
try:
|
||||
from tiramisu_api import Config as JsonConfig
|
||||
#params = ['tiramisu', 'tiramisu-json']
|
||||
params = ['tiramisu']
|
||||
except:
|
||||
params = ['tiramisu']
|
||||
from .utils import TestHelpFormatter
|
||||
|
||||
|
||||
|
||||
|
|
@ -31,7 +37,7 @@ def get_config(json):
|
|||
return jconfig
|
||||
|
||||
|
||||
@pytest.fixture(params=['tiramisu', 'tiramisu-json'])
|
||||
@pytest.fixture(params=params)
|
||||
def json(request):
|
||||
return request.param
|
||||
|
||||
|
|
@ -39,15 +45,13 @@ def json(request):
|
|||
def test_help(json):
|
||||
output = """usage: prog.py [-h] {str,list,int,none}
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
|
||||
od:
|
||||
od
|
||||
|
||||
{str,list,int,none} choice the sub argument
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
parser.print_help()
|
||||
|
|
@ -57,17 +61,15 @@ od:
|
|||
def test_help_epilog(json):
|
||||
output = """usage: prog.py [-h] {str,list,int,none}
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
|
||||
od:
|
||||
od
|
||||
|
||||
{str,list,int,none} choice the sub argument
|
||||
|
||||
two line
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', epilog="\ntwo\nline")
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', epilog="\ntwo\nline", formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
parser.print_help()
|
||||
|
|
@ -77,12 +79,10 @@ two line
|
|||
def test_help_epilog_raw(json):
|
||||
output = """usage: prog.py [-h] {str,list,int,none}
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
|
||||
od:
|
||||
od
|
||||
|
||||
{str,list,int,none} choice the sub argument
|
||||
|
||||
two
|
||||
|
|
|
|||
|
|
@ -5,8 +5,15 @@ import pytest
|
|||
|
||||
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||
from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
||||
SymLinkOption, OptionDescription, Leadership, Config, submulti
|
||||
from tiramisu_api import Config as JsonConfig
|
||||
OptionDescription, Leadership, Config, submulti
|
||||
try:
|
||||
from tiramisu_api import Config as JsonConfig
|
||||
# params = ['tiramisu', 'tiramisu-json']
|
||||
params = ['tiramisu']
|
||||
except:
|
||||
params = ['tiramisu']
|
||||
|
||||
from .utils import TestHelpFormatter, to_dict
|
||||
|
||||
|
||||
def get_config(json, with_mandatory=False):
|
||||
|
|
@ -31,29 +38,19 @@ def get_config(json, with_mandatory=False):
|
|||
return jconfig
|
||||
|
||||
|
||||
@pytest.fixture(params=['tiramisu', 'tiramisu-api'])
|
||||
@pytest.fixture(params=params)
|
||||
def json(request):
|
||||
return request.param
|
||||
|
||||
|
||||
def test_leadership_help(json):
|
||||
output = """usage: prog.py [-h] [--leader.leader [LEADER [LEADER ...]]]
|
||||
[--leader.pop-leader INDEX]
|
||||
[--leader.follower INDEX [FOLLOWER]] --leader.follower_submulti
|
||||
INDEX [FOLLOWER_SUBMULTI ...]
|
||||
[--leader.follower_integer INDEX [FOLLOWER_INTEGER]]
|
||||
[--leader.follower_boolean INDEX]
|
||||
[--leader.no-follower_boolean INDEX]
|
||||
[--leader.follower_choice INDEX [{opt1,opt2}]]
|
||||
--leader.follower_mandatory INDEX FOLLOWER_MANDATORY
|
||||
output = """usage: prog.py [-h] [--leader.leader [LEADER ...]] [--leader.pop-leader INDEX] [--leader.follower INDEX [FOLLOWER]] --leader.follower_submulti INDEX [FOLLOWER_SUBMULTI ...] [--leader.follower_integer INDEX [FOLLOWER_INTEGER]] [--leader.follower_boolean INDEX] [--leader.no-follower_boolean INDEX] [--leader.follower_choice INDEX [{opt1,opt2}]] --leader.follower_mandatory INDEX FOLLOWER_MANDATORY
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
|
||||
leader:
|
||||
leader
|
||||
|
||||
--leader.leader [LEADER [LEADER ...]]
|
||||
--leader.leader [LEADER ...]
|
||||
Leader var
|
||||
--leader.pop-leader INDEX
|
||||
--leader.follower INDEX [FOLLOWER]
|
||||
|
|
@ -70,7 +67,7 @@ leader:
|
|||
--leader.follower_mandatory INDEX FOLLOWER_MANDATORY
|
||||
Follower mandatory
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json, with_mandatory=True), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json, with_mandatory=True), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
parser.print_help()
|
||||
|
|
@ -88,7 +85,7 @@ def test_leadership_modif_leader(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['--leader.leader', '192.168.1.1'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_leadership_modif_follower(json):
|
||||
|
|
@ -102,23 +99,16 @@ def test_leadership_modif_follower(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['--leader.follower', '0', '255.255.255.0'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_leadership_modif_follower_not_submulti(json):
|
||||
output = """usage: prog.py [-h] [--leader.leader [LEADER [LEADER ...]]]
|
||||
[--leader.pop-leader INDEX]
|
||||
[--leader.follower INDEX [FOLLOWER]]
|
||||
[--leader.follower_submulti INDEX [FOLLOWER_SUBMULTI ...]]
|
||||
[--leader.follower_integer INDEX [FOLLOWER_INTEGER]]
|
||||
[--leader.follower_boolean INDEX]
|
||||
[--leader.no-follower_boolean INDEX]
|
||||
[--leader.follower_choice INDEX [{opt1,opt2}]]
|
||||
output = """usage: prog.py [-h] [--leader.leader [LEADER ...]] [--leader.pop-leader INDEX] [--leader.follower INDEX [FOLLOWER]] [--leader.follower_submulti INDEX [FOLLOWER_SUBMULTI ...]] [--leader.follower_integer INDEX [FOLLOWER_INTEGER]] [--leader.follower_boolean INDEX] [--leader.no-follower_boolean INDEX] [--leader.follower_choice INDEX [{opt1,opt2}]]
|
||||
prog.py: error: unrecognized arguments: 255.255.255.0
|
||||
"""
|
||||
|
||||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
|
|
@ -141,7 +131,7 @@ def test_leadership_modif_follower_submulti(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['--leader.follower_submulti', '0', '255.255.255.0'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_leadership_modif_follower_submulti_multi(json):
|
||||
|
|
@ -155,7 +145,7 @@ def test_leadership_modif_follower_submulti_multi(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['--leader.follower_submulti', '0', '255.255.255.0', '255.255.255.128'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_leadership_modif_follower_bool_true(json):
|
||||
|
|
@ -169,7 +159,7 @@ def test_leadership_modif_follower_bool_true(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['--leader.follower_boolean', '0'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_leadership_modif_follower_bool_false(json):
|
||||
|
|
@ -183,7 +173,7 @@ def test_leadership_modif_follower_bool_false(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['--leader.no-follower_boolean', '0'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_leadership_modif_follower_bool_true_fullname(json):
|
||||
|
|
@ -197,7 +187,7 @@ def test_leadership_modif_follower_bool_true_fullname(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||
parser.parse_args(['--follower_boolean', '0'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_leadership_modif_follower_bool_false_fullname(json):
|
||||
|
|
@ -211,7 +201,7 @@ def test_leadership_modif_follower_bool_false_fullname(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||
parser.parse_args(['--no-follower_boolean', '0'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_leadership_modif_follower_choice(json):
|
||||
|
|
@ -225,22 +215,15 @@ def test_leadership_modif_follower_choice(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['--leader.follower_choice', '0', 'opt1'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_leadership_modif_follower_choice_unknown(json):
|
||||
output = """usage: prog.py [-h] [--leader.leader [LEADER [LEADER ...]]]
|
||||
[--leader.pop-leader INDEX]
|
||||
[--leader.follower INDEX [FOLLOWER]]
|
||||
[--leader.follower_submulti INDEX [FOLLOWER_SUBMULTI ...]]
|
||||
[--leader.follower_integer INDEX [FOLLOWER_INTEGER]]
|
||||
[--leader.follower_boolean INDEX]
|
||||
[--leader.no-follower_boolean INDEX]
|
||||
[--leader.follower_choice INDEX [{opt1,opt2}]]
|
||||
output = """usage: prog.py [-h] [--leader.leader [LEADER ...]] [--leader.pop-leader INDEX] [--leader.follower INDEX [FOLLOWER]] [--leader.follower_submulti INDEX [FOLLOWER_SUBMULTI ...]] [--leader.follower_integer INDEX [FOLLOWER_INTEGER]] [--leader.follower_boolean INDEX] [--leader.no-follower_boolean INDEX] [--leader.follower_choice INDEX [{opt1,opt2}]]
|
||||
prog.py: error: argument --leader.follower_choice: invalid choice: 'opt_unknown' (choose from 'opt1', 'opt2')
|
||||
"""
|
||||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
|
|
@ -253,19 +236,12 @@ prog.py: error: argument --leader.follower_choice: invalid choice: 'opt_unknown'
|
|||
|
||||
|
||||
def test_leadership_modif_follower_not_number(json):
|
||||
output = """usage: prog.py [-h] [--leader.leader [LEADER [LEADER ...]]]
|
||||
[--leader.pop-leader INDEX]
|
||||
[--leader.follower INDEX [FOLLOWER]]
|
||||
[--leader.follower_submulti INDEX [FOLLOWER_SUBMULTI ...]]
|
||||
[--leader.follower_integer INDEX [FOLLOWER_INTEGER]]
|
||||
[--leader.follower_boolean INDEX]
|
||||
[--leader.no-follower_boolean INDEX]
|
||||
[--leader.follower_choice INDEX [{opt1,opt2}]]
|
||||
output = """usage: prog.py [-h] [--leader.leader [LEADER ...]] [--leader.pop-leader INDEX] [--leader.follower INDEX [FOLLOWER]] [--leader.follower_submulti INDEX [FOLLOWER_SUBMULTI ...]] [--leader.follower_integer INDEX [FOLLOWER_INTEGER]] [--leader.follower_boolean INDEX] [--leader.no-follower_boolean INDEX] [--leader.follower_choice INDEX [{opt1,opt2}]]
|
||||
prog.py: error: index must be a number, not a
|
||||
"""
|
||||
|
||||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
|
|
@ -290,7 +266,7 @@ def test_leadership_modif_multi(json):
|
|||
parser.parse_args(['--leader.leader', '192.168.1.1', '10.253.10.1', '192.168.253.1',
|
||||
'--leader.follower', '0', '255.255.255.128',
|
||||
'--leader.follower', '2', '255.255.255.0'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_leadership_modif_multi_reduce(json):
|
||||
|
|
@ -307,7 +283,7 @@ def test_leadership_modif_multi_reduce(json):
|
|||
'--leader.follower', '0', '255.255.255.128',
|
||||
'--leader.follower', '2', '255.255.255.0',
|
||||
'--leader.pop-leader', '1'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_leadership_modif_mandatory(json):
|
||||
|
|
@ -318,22 +294,11 @@ def test_leadership_modif_mandatory(json):
|
|||
'leader.follower_choice': [None],
|
||||
'leader.follower_integer': [None],
|
||||
'leader.follower_submulti': [['255.255.255.128']]}
|
||||
output2 = """usage: prog.py --leader.leader "192.168.1.1" [-h]
|
||||
[--leader.leader [LEADER [LEADER ...]]]
|
||||
[--leader.pop-leader INDEX]
|
||||
[--leader.follower INDEX [FOLLOWER]]
|
||||
--leader.follower_submulti INDEX
|
||||
[FOLLOWER_SUBMULTI ...]
|
||||
[--leader.follower_integer INDEX [FOLLOWER_INTEGER]]
|
||||
[--leader.follower_boolean INDEX]
|
||||
[--leader.no-follower_boolean INDEX]
|
||||
[--leader.follower_choice INDEX [{opt1,opt2}]]
|
||||
--leader.follower_mandatory INDEX
|
||||
FOLLOWER_MANDATORY
|
||||
output2 = """usage: prog.py --leader.leader "192.168.1.1" [-h] [--leader.leader [LEADER ...]] [--leader.pop-leader INDEX] [--leader.follower INDEX [FOLLOWER]] --leader.follower_submulti INDEX [FOLLOWER_SUBMULTI ...] [--leader.follower_integer INDEX [FOLLOWER_INTEGER]] [--leader.follower_boolean INDEX] [--leader.no-follower_boolean INDEX] [--leader.follower_choice INDEX [{opt1,opt2}]] --leader.follower_mandatory INDEX FOLLOWER_MANDATORY
|
||||
prog.py: error: the following arguments are required: --leader.follower_submulti"""
|
||||
|
||||
config = get_config(json, with_mandatory=True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
|
|
@ -356,7 +321,7 @@ prog.py: error: the following arguments are required: --leader.follower_submulti
|
|||
parser.parse_args(['--leader.leader', '192.168.1.1',
|
||||
'--leader.follower_submulti', '0', '255.255.255.128',
|
||||
'--leader.follower_mandatory', '0', '255.255.255.128'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_leadership_modif_mandatory_remove(json):
|
||||
|
|
@ -367,20 +332,11 @@ def test_leadership_modif_mandatory_remove(json):
|
|||
'leader.follower_choice': [None],
|
||||
'leader.follower_integer': [None],
|
||||
'leader.follower_submulti': [['255.255.255.128']]}
|
||||
output2 = """usage: prog.py --leader.leader "192.168.1.1" [-h] [--leader.pop-leader INDEX]
|
||||
[--leader.follower INDEX [FOLLOWER]]
|
||||
--leader.follower_submulti INDEX
|
||||
[FOLLOWER_SUBMULTI ...]
|
||||
[--leader.follower_integer INDEX [FOLLOWER_INTEGER]]
|
||||
[--leader.follower_boolean INDEX]
|
||||
[--leader.no-follower_boolean INDEX]
|
||||
[--leader.follower_choice INDEX [{opt1,opt2}]]
|
||||
--leader.follower_mandatory INDEX
|
||||
FOLLOWER_MANDATORY
|
||||
output2 = """usage: prog.py --leader.leader "192.168.1.1" [-h] [--leader.pop-leader INDEX] [--leader.follower INDEX [FOLLOWER]] --leader.follower_submulti INDEX [FOLLOWER_SUBMULTI ...] [--leader.follower_integer INDEX [FOLLOWER_INTEGER]] [--leader.follower_boolean INDEX] [--leader.no-follower_boolean INDEX] [--leader.follower_choice INDEX [{opt1,opt2}]] --leader.follower_mandatory INDEX FOLLOWER_MANDATORY
|
||||
prog.py: error: the following arguments are required: --leader.follower_submulti"""
|
||||
|
||||
config = get_config(json, with_mandatory=True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', display_modified_value=False)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', display_modified_value=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
|
|
@ -403,7 +359,7 @@ prog.py: error: the following arguments are required: --leader.follower_submulti
|
|||
parser.parse_args(['--leader.leader', '192.168.1.1',
|
||||
'--leader.follower_submulti', '0', '255.255.255.128',
|
||||
'--leader.follower_mandatory', '0', '255.255.255.128'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_leadership_modif_mandatory_unvalidate(json):
|
||||
|
|
@ -417,4 +373,4 @@ def test_leadership_modif_mandatory_unvalidate(json):
|
|||
config = get_config(json, with_mandatory=True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['--leader.leader', '192.168.1.1'], valid_mandatory=False)
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
|
|
|||
|
|
@ -6,7 +6,13 @@ import pytest
|
|||
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||
from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
||||
SymLinkOption, OptionDescription, Config
|
||||
from tiramisu_api import Config as JsonConfig
|
||||
try:
|
||||
from tiramisu_api import Config as JsonConfig
|
||||
#params = ['tiramisu', 'tiramisu-json']
|
||||
params = ['tiramisu']
|
||||
except:
|
||||
params = ['tiramisu']
|
||||
from .utils import TestHelpFormatter
|
||||
|
||||
|
||||
def get_config(json, has_tree=False, default_verbosity=False, add_long=False, add_store_false=False, empty_optiondescription=False):
|
||||
|
|
@ -59,17 +65,15 @@ def get_config(json, has_tree=False, default_verbosity=False, add_long=False, ad
|
|||
return jconfig
|
||||
|
||||
|
||||
@pytest.fixture(params=['tiramisu', 'tiramisu-json'])
|
||||
@pytest.fixture(params=params)
|
||||
def json(request):
|
||||
return request.param
|
||||
|
||||
|
||||
def test_optiondescription_help(json):
|
||||
output = """usage: prog.py [-h] [-v] [-nv] --od2.subtree.str STR --od2.before BEFORE
|
||||
--od2.after AFTER
|
||||
{str,list,int,none}
|
||||
output = """usage: prog.py [-h] [-v] [-nv] --od2.subtree.str STR --od2.before BEFORE --od2.after AFTER {str,list,int,none}
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
|
||||
od1:
|
||||
|
|
@ -93,7 +97,7 @@ od2.subtree:
|
|||
--od2.subtree.str STR
|
||||
string option 2
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
parser.print_help()
|
||||
|
|
@ -101,11 +105,9 @@ od2.subtree:
|
|||
|
||||
|
||||
def test_optiondescription_help_remove_empty_od(json):
|
||||
output = """usage: prog.py [-h] [-v] [-nv] --od2.subtree.str STR --od2.before BEFORE
|
||||
--od2.after AFTER
|
||||
{str,list,int,none}
|
||||
output = """usage: prog.py [-h] [-v] [-nv] --od2.subtree.str STR --od2.before BEFORE --od2.after AFTER {str,list,int,none}
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
|
||||
od1.od0:
|
||||
|
|
@ -126,7 +128,7 @@ od2.subtree:
|
|||
--od2.subtree.str STR
|
||||
string option 2
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', remove_empty_od=True)
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', remove_empty_od=True, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
parser.print_help()
|
||||
|
|
@ -134,11 +136,9 @@ od2.subtree:
|
|||
|
||||
|
||||
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}
|
||||
output = """usage: prog.py [-h] [-v] [-nv] --od2.subtree.str STR --od2.before BEFORE --od2.after AFTER {str,list,int,none}
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
|
||||
od1.od0:
|
||||
|
|
@ -159,7 +159,7 @@ od2.subtree:
|
|||
--od2.subtree.str STR
|
||||
string option 2
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json, empty_optiondescription=True), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json, empty_optiondescription=True), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
parser.print_help()
|
||||
|
|
@ -167,10 +167,9 @@ od2.subtree:
|
|||
|
||||
|
||||
def test_optiondescription_help_subtree(json):
|
||||
output = """usage: prog.py [-h] --od2.subtree.str STR --od2.before BEFORE --od2.after
|
||||
AFTER
|
||||
output = """usage: prog.py [-h] --od2.subtree.str STR --od2.before BEFORE --od2.after AFTER
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
--od2.before BEFORE Before
|
||||
--od2.after AFTER After
|
||||
|
|
@ -182,7 +181,7 @@ od2.subtree:
|
|||
string option 2
|
||||
"""
|
||||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', root='od2')
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', root='od2', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
parser.print_help()
|
||||
|
|
|
|||
|
|
@ -5,8 +5,15 @@ import pytest
|
|||
|
||||
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||
from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
||||
SymLinkOption, OptionDescription, Config
|
||||
from tiramisu_api import Config as JsonConfig
|
||||
SymLinkOption, OptionDescription, Config, calc_value, \
|
||||
Calculation, ParamValue, ParamOption, Params
|
||||
try:
|
||||
from tiramisu_api import Config as JsonConfig
|
||||
#params = ['tiramisu', 'tiramisu-json']
|
||||
params = ['tiramisu']
|
||||
except:
|
||||
params = ['tiramisu']
|
||||
from .utils import TestHelpFormatter, to_dict
|
||||
|
||||
|
||||
def get_config(json, has_tree=False, default_verbosity=False, add_long=False, add_store_false=False):
|
||||
|
|
@ -21,26 +28,35 @@ def get_config(json, has_tree=False, default_verbosity=False, add_long=False, ad
|
|||
short_booloption = SymLinkOption('v', booloption)
|
||||
str_ = StrOption('str',
|
||||
'string option',
|
||||
properties=('mandatory',),
|
||||
requires=[{'option': choiceoption,
|
||||
'expected': 'str',
|
||||
'action': 'disabled',
|
||||
'inverse': True}])
|
||||
properties=('mandatory',
|
||||
Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(choiceoption),
|
||||
'reverse_condition': ParamValue(True),
|
||||
'expected': ParamValue('str')})),
|
||||
),
|
||||
)
|
||||
list_ = StrOption('list',
|
||||
'list string option',
|
||||
multi=True,
|
||||
properties=('mandatory',),
|
||||
requires=[{'option': choiceoption,
|
||||
'expected': 'list',
|
||||
'action': 'disabled',
|
||||
'inverse': True}])
|
||||
properties=('mandatory',
|
||||
Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(choiceoption),
|
||||
'reverse_condition': ParamValue(True),
|
||||
'expected': ParamValue('list')})),
|
||||
),
|
||||
)
|
||||
int_ = IntOption('int',
|
||||
'int option',
|
||||
properties=('mandatory',),
|
||||
requires=[{'option': choiceoption,
|
||||
'expected': 'int',
|
||||
'action': 'disabled',
|
||||
'inverse': True}])
|
||||
properties=('mandatory',
|
||||
Calculation(calc_value,
|
||||
Params(ParamValue('disabled'),
|
||||
kwargs={'condition': ParamOption(choiceoption),
|
||||
'reverse_condition': ParamValue(True),
|
||||
'expected': ParamValue('int')})),
|
||||
),
|
||||
)
|
||||
|
||||
root = OptionDescription('root',
|
||||
'root',
|
||||
|
|
@ -67,7 +83,7 @@ def get_config(json, has_tree=False, default_verbosity=False, add_long=False, ad
|
|||
return jconfig
|
||||
|
||||
|
||||
@pytest.fixture(params=['tiramisu', 'tiramisu-json'])
|
||||
@pytest.fixture(params=params)
|
||||
def json(request):
|
||||
return request.param
|
||||
|
||||
|
|
@ -78,12 +94,12 @@ def test_readme_help(json):
|
|||
positional arguments:
|
||||
{str,list,int,none} choice the sub argument
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
-v, --verbosity increase output verbosity
|
||||
-nv, --no-verbosity
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
parser.print_help()
|
||||
|
|
@ -93,17 +109,15 @@ optional arguments:
|
|||
def test_readme_help_tree(json):
|
||||
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
|
||||
root:
|
||||
root
|
||||
|
||||
{str,list,int,none} choice the sub argument
|
||||
-v, --root.verbosity increase output verbosity
|
||||
-nv, --root.no-verbosity
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
parser.print_help()
|
||||
|
|
@ -113,17 +127,15 @@ root:
|
|||
def test_readme_help_tree_flatten(json):
|
||||
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
|
||||
root:
|
||||
root
|
||||
|
||||
{str,list,int,none} choice the sub argument
|
||||
-v, --verbosity increase output verbosity
|
||||
-nv, --no-verbosity
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', fullpath=False)
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', fullpath=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
parser.print_help()
|
||||
|
|
@ -136,13 +148,13 @@ def test_readme_help_modif_positional(json):
|
|||
positional arguments:
|
||||
{str,list,int,none} choice the sub argument
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
-v, --verbosity increase output verbosity
|
||||
-nv, --no-verbosity
|
||||
--str STR string option
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
try:
|
||||
|
|
@ -157,13 +169,13 @@ optional arguments:
|
|||
def test_readme_help_modif_positional_remove(json):
|
||||
output = """usage: prog.py "str" [-h] [-v] [-nv] --str STR
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
-v, --verbosity increase output verbosity
|
||||
-nv, --no-verbosity
|
||||
--str STR string option
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', display_modified_value=False)
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', display_modified_value=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
try:
|
||||
|
|
@ -176,19 +188,18 @@ optional arguments:
|
|||
|
||||
|
||||
def test_readme_help_modif(json):
|
||||
output = """usage: prog.py "str" --str "toto" [-h] [-v] [-nv] --str STR
|
||||
{str,list,int,none}
|
||||
output = """usage: prog.py "str" --str "toto" [-h] [-v] [-nv] --str STR {str,list,int,none}
|
||||
|
||||
positional arguments:
|
||||
{str,list,int,none} choice the sub argument
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
-v, --verbosity increase output verbosity
|
||||
-nv, --no-verbosity
|
||||
--str STR string option
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
try:
|
||||
|
|
@ -203,12 +214,12 @@ optional arguments:
|
|||
def test_readme_help_modif_remove(json):
|
||||
output = """usage: prog.py "str" --str "toto" [-h] [-v] [-nv]
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
-v, --verbosity increase output verbosity
|
||||
-nv, --no-verbosity
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', display_modified_value=False)
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', display_modified_value=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
try:
|
||||
|
|
@ -226,13 +237,13 @@ def test_readme_help_modif_short(json):
|
|||
positional arguments:
|
||||
{str,list,int,none} choice the sub argument
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
-v, --verbosity increase output verbosity
|
||||
-nv, --no-verbosity
|
||||
--str STR string option
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
try:
|
||||
|
|
@ -248,12 +259,12 @@ def test_readme_help_modif_short_remove(json):
|
|||
# FIXME -v -nv ?? pas de description
|
||||
output = """usage: prog.py "str" -v [-h] [-nv] --str STR
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
-nv, --no-verbosity increase output verbosity
|
||||
--str STR string option
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', display_modified_value=False)
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', display_modified_value=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
try:
|
||||
|
|
@ -271,13 +282,13 @@ def test_readme_help_modif_short_no1(json):
|
|||
positional arguments:
|
||||
{str,list,int,none} choice the sub argument
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
-v, --verbosity increase output verbosity
|
||||
-nv, --no-verbosity
|
||||
--str STR string option
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
try:
|
||||
|
|
@ -292,12 +303,12 @@ optional arguments:
|
|||
def test_readme_help_modif_short_no_remove(json):
|
||||
output = """usage: prog.py "str" -v [-h] [-v] --str STR
|
||||
|
||||
optional arguments:
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
-v, --verbosity increase output verbosity
|
||||
--str STR string option
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', display_modified_value=False)
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', display_modified_value=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stdout(f):
|
||||
try:
|
||||
|
|
@ -313,7 +324,7 @@ def test_readme_positional_mandatory(json):
|
|||
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
||||
prog.py: error: the following arguments are required: cmd
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
|
|
@ -329,7 +340,7 @@ def test_readme_positional_mandatory_tree(json):
|
|||
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(json, True), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
|
|
@ -345,7 +356,7 @@ def test_readme_positional_mandatory_tree_flatten(json):
|
|||
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
||||
prog.py: error: the following arguments are required: cmd
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', fullpath=False)
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', fullpath=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
|
|
@ -361,7 +372,7 @@ def test_readme_mandatory(json):
|
|||
output = """usage: prog.py "str" [-h] [-v] [-nv] --str STR {str,list,int,none}
|
||||
prog.py: error: the following arguments are required: --str
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
|
|
@ -377,7 +388,7 @@ def test_readme_mandatory_remove(json):
|
|||
output = """usage: prog.py "str" [-h] [-v] [-nv] --str STR
|
||||
prog.py: error: the following arguments are required: --str
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', display_modified_value=False)
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', display_modified_value=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
|
|
@ -393,7 +404,7 @@ def test_readme_mandatory_tree(json):
|
|||
output = """usage: prog.py "str" [-h] [-v] [-nv] --root.str STR {str,list,int,none}
|
||||
prog.py: error: the following arguments are required: --root.str
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
|
|
@ -409,7 +420,7 @@ def test_readme_mandatory_tree_remove(json):
|
|||
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(json, True), 'prog.py', display_modified_value=False)
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', display_modified_value=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
|
|
@ -425,7 +436,7 @@ def test_readme_mandatory_tree_flatten(json):
|
|||
output = """usage: prog.py "str" [-h] [-v] [-nv] --str STR {str,list,int,none}
|
||||
prog.py: error: the following arguments are required: --str
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', fullpath=False)
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', fullpath=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
|
|
@ -441,7 +452,7 @@ def test_readme_mandatory_tree_flatten_remove(json):
|
|||
output = """usage: prog.py "str" [-h] [-v] [-nv] --str STR
|
||||
prog.py: error: the following arguments are required: --str
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', fullpath=False, display_modified_value=False)
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', fullpath=False, display_modified_value=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
|
|
@ -457,11 +468,11 @@ def test_readme_cross(json):
|
|||
output = """usage: prog.py "none" [-h] [-v] [-nv] {str,list,int,none}
|
||||
prog.py: error: unrecognized arguments: --int
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['none', '--int'])
|
||||
parser.parse_args(['none', '--int', '1'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
|
|
@ -473,11 +484,11 @@ def test_readme_cross_remove(json):
|
|||
output = """usage: prog.py "none" [-h] [-v] [-nv]
|
||||
prog.py: error: unrecognized arguments: --int
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', display_modified_value=False)
|
||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', display_modified_value=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['none', '--int'])
|
||||
parser.parse_args(['none', '--int', '1'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
|
|
@ -487,13 +498,13 @@ prog.py: error: unrecognized arguments: --int
|
|||
|
||||
def test_readme_cross_tree(json):
|
||||
output = """usage: prog.py "none" [-h] [-v] [-nv] {str,list,int,none}
|
||||
prog.py: error: unrecognized arguments: --int
|
||||
prog.py: error: unrecognized arguments: --root.int
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py')
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['none', '--int'])
|
||||
parser.parse_args(['none', '--root.int', '1'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
|
|
@ -503,13 +514,13 @@ prog.py: error: unrecognized arguments: --int
|
|||
|
||||
def test_readme_cross_tree_remove(json):
|
||||
output = """usage: prog.py "none" [-h] [-v] [-nv]
|
||||
prog.py: error: unrecognized arguments: --int
|
||||
prog.py: error: unrecognized arguments: --root.int
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', display_modified_value=False)
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', display_modified_value=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['none', '--int'])
|
||||
parser.parse_args(['none', '--root.int', '1'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
|
|
@ -521,11 +532,11 @@ def test_readme_cross_tree_flatten(json):
|
|||
output = """usage: prog.py "none" [-h] [-v] [-nv] {str,list,int,none}
|
||||
prog.py: error: unrecognized arguments: --int
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', fullpath=False)
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', fullpath=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['none', '--int'])
|
||||
parser.parse_args(['none', '--int', '1'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
|
|
@ -537,11 +548,11 @@ def test_readme_cross_tree_flatten_remove(json):
|
|||
output = """usage: prog.py "none" [-h] [-v] [-nv]
|
||||
prog.py: error: unrecognized arguments: --int
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', fullpath=False, display_modified_value=False)
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', fullpath=False, display_modified_value=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['none', '--int'])
|
||||
parser.parse_args(['none', '--int', '1'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
|
|
@ -553,7 +564,7 @@ def test_readme_unknown(json):
|
|||
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
||||
prog.py: error: argument root.cmd: invalid choice: 'unknown' (choose from 'str', 'list', 'int', 'none')
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', fullpath=False)
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', fullpath=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
|
|
@ -573,7 +584,7 @@ def test_readme_int(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['int', '--int', '3'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_int_tree(json):
|
||||
|
|
@ -584,7 +595,7 @@ def test_readme_int_tree(json):
|
|||
config = get_config(json, True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['int', '--root.int', '3'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_int_tree_flatten(json):
|
||||
|
|
@ -595,7 +606,7 @@ def test_readme_int_tree_flatten(json):
|
|||
config = get_config(json, True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||
parser.parse_args(['int', '--int', '3'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_int_verbosity(json):
|
||||
|
|
@ -606,7 +617,7 @@ def test_readme_int_verbosity(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['int', '--int', '3', '--verbosity'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_int_verbosity_tree(json):
|
||||
|
|
@ -617,7 +628,7 @@ def test_readme_int_verbosity_tree(json):
|
|||
config = get_config(json, True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['int', '--root.int', '3', '--root.verbosity'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_int_verbosity_tree_flatten(json):
|
||||
|
|
@ -628,7 +639,7 @@ def test_readme_int_verbosity_tree_flatten(json):
|
|||
config = get_config(json, True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||
parser.parse_args(['int', '--int', '3', '--verbosity'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_int_verbosity_short(json):
|
||||
|
|
@ -639,7 +650,7 @@ def test_readme_int_verbosity_short(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['int', '--int', '3', '-v'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_int_verbosity_short_store_false(json):
|
||||
|
|
@ -654,13 +665,13 @@ def test_readme_int_verbosity_short_store_false(json):
|
|||
'int': 3,
|
||||
'verbosity': False,
|
||||
'v': False}
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
parser.parse_args(['int', '--int', '3', '-nv'])
|
||||
output = {'cmd': 'int',
|
||||
'int': 3,
|
||||
'verbosity': True,
|
||||
'v': True}
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_int_verbosity_short_no(json):
|
||||
|
|
@ -671,7 +682,7 @@ def test_readme_int_verbosity_short_no(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['int', '--int', '3', '-nv'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_int_verbosity_short_tree(json):
|
||||
|
|
@ -682,7 +693,7 @@ def test_readme_int_verbosity_short_tree(json):
|
|||
config = get_config(json, True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['int', '--root.int', '3', '-v'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_int_verbosity_short_tree_flatten(json):
|
||||
|
|
@ -693,7 +704,7 @@ def test_readme_int_verbosity_short_tree_flatten(json):
|
|||
config = get_config(json, True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||
parser.parse_args(['int', '--int', '3', '-v'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_int_verbosity_short_and_not(json):
|
||||
|
|
@ -704,7 +715,7 @@ def test_readme_int_verbosity_short_and_not(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['int', '--int', '3', '-v', '-nv'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_str(json):
|
||||
|
|
@ -715,7 +726,7 @@ def test_readme_str(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['str', '--str', 'value'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_str_tree(json):
|
||||
|
|
@ -726,7 +737,7 @@ def test_readme_str_tree(json):
|
|||
config = get_config(json, True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['str', '--root.str', 'value'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_str_tree_flatten(json):
|
||||
|
|
@ -737,7 +748,7 @@ def test_readme_str_tree_flatten(json):
|
|||
config = get_config(json, True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||
parser.parse_args(['str', '--str', 'value'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_str_int(json):
|
||||
|
|
@ -748,7 +759,7 @@ def test_readme_str_int(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['str', '--str', '3'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_str_int_tree(json):
|
||||
|
|
@ -759,7 +770,7 @@ def test_readme_str_int_tree(json):
|
|||
config = get_config(json, True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['str', '--root.str', '3'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_str_int_tree_flatten(json):
|
||||
|
|
@ -770,7 +781,7 @@ def test_readme_str_int_tree_flatten(json):
|
|||
config = get_config(json, True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||
parser.parse_args(['str', '--str', '3'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_list_single(json):
|
||||
|
|
@ -781,7 +792,7 @@ def test_readme_list_single(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['list', '--list', 'a'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_list(json):
|
||||
|
|
@ -792,7 +803,7 @@ def test_readme_list(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['list', '--list', 'a', 'b', 'c'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_list_tree(json):
|
||||
|
|
@ -803,7 +814,7 @@ def test_readme_list_tree(json):
|
|||
config = get_config(json, True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['list', '--root.list', 'a', 'b', 'c'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_list_tree_flatten(json):
|
||||
|
|
@ -814,7 +825,7 @@ def test_readme_list_tree_flatten(json):
|
|||
config = get_config(json, True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||
parser.parse_args(['list', '--list', 'a', 'b', 'c'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_list_uniq(json):
|
||||
|
|
@ -825,7 +836,7 @@ def test_readme_list_uniq(json):
|
|||
config = get_config(json)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['list', '--list', 'a'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_list_uniq_tree(json):
|
||||
|
|
@ -836,7 +847,7 @@ def test_readme_list_uniq_tree(json):
|
|||
config = get_config(json, True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['list', '--root.list', 'a'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_list_uniq_tree_flatten(json):
|
||||
|
|
@ -847,7 +858,7 @@ def test_readme_list_uniq_tree_flatten(json):
|
|||
config = get_config(json, True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||
parser.parse_args(['list', '--list', 'a'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_longargument(json):
|
||||
|
|
@ -858,4 +869,33 @@ def test_readme_longargument(json):
|
|||
config = get_config(json, add_long=True)
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['list', '--list', 'a', '--v'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_readme_unknown_key(json):
|
||||
output1 = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
||||
prog.py: error: unrecognized arguments: --unknown
|
||||
"""
|
||||
output2 = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
||||
prog.py: error: unrecognized arguments: --root.unknown
|
||||
"""
|
||||
parser = TiramisuCmdlineParser(get_config(json, True), 'prog.py', fullpath=False, formatter_class=TestHelpFormatter)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['--unknown'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
raise Exception('must raises')
|
||||
assert f.getvalue() == output1
|
||||
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['--root.unknown'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
raise Exception('must raises')
|
||||
assert f.getvalue() == output2
|
||||
|
|
|
|||
|
|
@ -6,10 +6,17 @@ from contextlib import redirect_stderr
|
|||
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||
from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
||||
SymLinkOption, OptionDescription, Config
|
||||
from tiramisu_api import Config as JsonConfig
|
||||
try:
|
||||
from tiramisu_api import Config as JsonConfig
|
||||
params = ['tiramisu']
|
||||
#params = ['tiramisu', 'tiramisu-json']
|
||||
except:
|
||||
params = ['tiramisu']
|
||||
|
||||
from .utils import to_dict
|
||||
|
||||
|
||||
@pytest.fixture(params=['tiramisu', 'tiramisu-json'])
|
||||
@pytest.fixture(params=params)
|
||||
def json(request):
|
||||
return request.param
|
||||
|
||||
|
|
@ -34,19 +41,19 @@ def test_short(json):
|
|||
config = get_config()
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args([])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
#
|
||||
output = {'list': 'a', 'l': 'a'}
|
||||
config = get_config()
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['--list', 'a'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
#
|
||||
output = {'list': 'a', 'l': 'a'}
|
||||
config = get_config()
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['-l', 'a'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
#
|
||||
assert config.option('list').value.get() == config.option('l').value.get()
|
||||
assert config.option('list').owner.get() == config.option('l').owner.get()
|
||||
|
|
@ -89,13 +96,13 @@ prog.py: error: the following arguments are required: --list
|
|||
config = get_config()
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['--list', 'a'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
#
|
||||
output = {'list': 'a', 'l': 'a'}
|
||||
config = get_config()
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['-l', 'a'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_short_multi(json):
|
||||
|
|
@ -119,31 +126,31 @@ def test_short_multi(json):
|
|||
config = get_config()
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args([])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
#
|
||||
output = {'list': ['a'], 'l': ['a']}
|
||||
config = get_config()
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['--list', 'a'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
#
|
||||
output = {'list': ['a', 'b'], 'l': ['a', 'b']}
|
||||
config = get_config()
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['--list', 'a', 'b'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
#
|
||||
output = {'list': ['a'], 'l': ['a']}
|
||||
config = get_config()
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['-l', 'a'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
#
|
||||
output = {'list': ['a', 'b'], 'l': ['a', 'b']}
|
||||
config = get_config()
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['-l', 'a', 'b'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
||||
|
||||
def test_short_multi_mandatory(json):
|
||||
|
|
@ -183,22 +190,22 @@ prog.py: error: the following arguments are required: --list
|
|||
config = get_config()
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['--list', 'a'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
#
|
||||
output = {'list': ['a', 'b'], 'l': ['a', 'b']}
|
||||
config = get_config()
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['--list', 'a', 'b'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
#
|
||||
output = {'list': ['a'], 'l': ['a']}
|
||||
config = get_config()
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['-l', 'a'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
#
|
||||
output = {'list': ['a', 'b'], 'l': ['a', 'b']}
|
||||
config = get_config()
|
||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['-l', 'a', 'b'])
|
||||
assert config.value.dict() == output
|
||||
assert to_dict(config.value.get()) == output
|
||||
|
|
|
|||
35
tests/utils.py
Normal file
35
tests/utils.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
from argparse import HelpFormatter
|
||||
from tiramisu_cmdline_parser.api import TiramisuHelpFormatter
|
||||
|
||||
|
||||
def _leadership_to_dict(dico, ret):
|
||||
leader, *followers = list(dico)
|
||||
ret[leader.path()] = dico[leader]
|
||||
for follower in followers:
|
||||
follower_path = follower.path()
|
||||
ret.setdefault(follower_path, []).append(dico[follower])
|
||||
|
||||
|
||||
def _to_dict(dico, ret):
|
||||
for key, value in dico.items():
|
||||
if key.isoptiondescription():
|
||||
if key.isleadership():
|
||||
_leadership_to_dict(value, ret)
|
||||
else:
|
||||
_to_dict(value, ret)
|
||||
else:
|
||||
ret[key.path()] = value
|
||||
|
||||
|
||||
def to_dict(dico):
|
||||
ret = {}
|
||||
_to_dict(dico, ret)
|
||||
return ret
|
||||
|
||||
|
||||
class TestHelpFormatter(TiramisuHelpFormatter, HelpFormatter):
|
||||
def __init__(self,
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
return super().__init__(*args, **kwargs, width=5000)
|
||||
|
|
@ -1,4 +1,9 @@
|
|||
from .api import TiramisuCmdlineParser
|
||||
try:
|
||||
from .api import TiramisuCmdlineParser
|
||||
except ImportError as err:
|
||||
import warnings
|
||||
warnings.warn("cannot not import TiramisuCmdlineParser {err}", ImportWarning)
|
||||
TiramisuCmdlineParser = None
|
||||
|
||||
__version__ = "0.2"
|
||||
__version__ = "0.5"
|
||||
__all__ = ('TiramisuCmdlineParser',)
|
||||
|
|
|
|||
|
|
@ -17,30 +17,33 @@ from argparse import ArgumentParser, Namespace, SUPPRESS, _HelpAction, HelpForma
|
|||
from copy import copy
|
||||
from gettext import gettext as _
|
||||
|
||||
#try:
|
||||
from tiramisu import Config
|
||||
from tiramisu.error import PropertiesOptionError, LeadershipError
|
||||
#except ImportError:
|
||||
# Config = None
|
||||
# from tiramisu_api.error import PropertiesOptionError
|
||||
# LeadershipError = ValueError
|
||||
try:
|
||||
from tiramisu import Config
|
||||
from tiramisu.error import PropertiesOptionError, RequirementError, LeadershipError
|
||||
except (ModuleNotFoundError, ImportError):
|
||||
Config = None
|
||||
from tiramisu_api.error import PropertiesOptionError
|
||||
RequirementError = PropertiesOptionError
|
||||
LeadershipError = ValueError
|
||||
try:
|
||||
from tiramisu__api import Config as ConfigJson
|
||||
from tiramisu_api import Config as ConfigJson
|
||||
if Config is None:
|
||||
Config = ConfigJson
|
||||
except ModuleNotFoundError:
|
||||
except ImportError:
|
||||
ConfigJson = Config
|
||||
|
||||
|
||||
def get_choice_list(obj, properties, display):
|
||||
choices = obj.value.list()
|
||||
if choices[0] == '':
|
||||
def get_choice_list(config, properties, display):
|
||||
def convert(choice):
|
||||
if isinstance(choice, int):
|
||||
return str(choice)
|
||||
return choice
|
||||
choices = [convert(choice) for choice in config.value.list()]
|
||||
if choices and choices[0] == '':
|
||||
del choices[0]
|
||||
if display:
|
||||
choices = '{{{}}}'.format(','.join(choices))
|
||||
if 'mandatory' not in properties:
|
||||
choices = f'[{choices}]'
|
||||
choices = '[{}]'.format(choices)
|
||||
return choices
|
||||
|
||||
|
||||
|
|
@ -61,18 +64,21 @@ class TiramisuNamespace(Namespace):
|
|||
config = self._config
|
||||
else:
|
||||
config = self._config.option(self._root)
|
||||
for tiramisu_key, tiramisu_value in config.value.dict(fullpath=True).items():
|
||||
option = self._config.option(tiramisu_key)
|
||||
if not option.option.issymlinkoption():
|
||||
if tiramisu_value == [] and \
|
||||
option.option.ismulti(): # and \
|
||||
# option.owner.isdefault():
|
||||
tiramisu_value = None
|
||||
super().__setattr__(tiramisu_key, tiramisu_value)
|
||||
self._parse(config.value.get())
|
||||
|
||||
def _parse(self, subconfig):
|
||||
for option, value in subconfig.items():
|
||||
if option.isoptiondescription():
|
||||
self._parse(value)
|
||||
elif not option.issymlinkoption():
|
||||
if value == [] and option.ismulti():
|
||||
value = None
|
||||
super().__setattr__(option.path(), value)
|
||||
|
||||
def __setattr__(self,
|
||||
key: str,
|
||||
value: Any) -> None:
|
||||
value: Any,
|
||||
) -> None:
|
||||
if key in self.list_force_no:
|
||||
true_key = self.list_force_no[key]
|
||||
elif key in self.list_force_del:
|
||||
|
|
@ -80,13 +86,17 @@ class TiramisuNamespace(Namespace):
|
|||
else:
|
||||
true_key = key
|
||||
option = self._config.option(true_key)
|
||||
if option.option.isfollower():
|
||||
if option.isfollower():
|
||||
_setattr = self._setattr_follower
|
||||
if not value[0].isdecimal():
|
||||
raise ValueError('index must be a number, not {}'.format(value[0]))
|
||||
index = int(value[0])
|
||||
option = self._config.option(true_key, index)
|
||||
true_value = ','.join(value[1:])
|
||||
else:
|
||||
_setattr = self._setattr
|
||||
true_value = value
|
||||
if option.option.type() == 'choice':
|
||||
if option.type() == 'choice':
|
||||
# HACK if integer in choice
|
||||
values = option.value.list()
|
||||
if isinstance(value, list):
|
||||
|
|
@ -108,9 +118,9 @@ class TiramisuNamespace(Namespace):
|
|||
else:
|
||||
_setattr(option, true_key, key, value)
|
||||
except ValueError as err:
|
||||
if option.option.type() == 'choice':
|
||||
choices = get_choice_list(option, option.property.get(), False)
|
||||
if option.type() == 'choice':
|
||||
values = option.value.list()
|
||||
display_value = ''
|
||||
if isinstance(true_value, list):
|
||||
for val in value:
|
||||
if val not in values:
|
||||
|
|
@ -118,6 +128,7 @@ class TiramisuNamespace(Namespace):
|
|||
break
|
||||
else:
|
||||
display_value = true_value
|
||||
choices = get_choice_list(option, option.property.get(), False)
|
||||
raise ValueError("argument {}: invalid choice: '{}' (choose from {})".format(self.arguments[key], display_value, ', '.join([f"'{val}'" for val in choices])))
|
||||
else:
|
||||
raise err
|
||||
|
|
@ -127,23 +138,24 @@ class TiramisuNamespace(Namespace):
|
|||
true_key: str,
|
||||
key: str,
|
||||
value: Any) -> None:
|
||||
if option.option.ismulti() and \
|
||||
if option.ismulti() and \
|
||||
value is not None and \
|
||||
not isinstance(value, list):
|
||||
value = [value]
|
||||
try:
|
||||
option.value.set(value)
|
||||
except PropertiesOptionError:
|
||||
raise AttributeError('unrecognized arguments: {}'.format(self.arguments[key]))
|
||||
|
||||
def _setattr_follower(self,
|
||||
option: 'Option',
|
||||
true_key: str,
|
||||
key: str,
|
||||
value: Any) -> None:
|
||||
if not value[0].isdecimal():
|
||||
raise ValueError('index must be a number, not {}'.format(value[0]))
|
||||
index = int(value[0])
|
||||
if option.option.type() == 'boolean':
|
||||
if option.type() == 'boolean':
|
||||
value = key not in self.list_force_no
|
||||
elif option.option.issubmulti():
|
||||
elif option.issubmulti():
|
||||
value = value[1:]
|
||||
else:
|
||||
value = value[1]
|
||||
|
|
@ -193,7 +205,7 @@ class _BuildKwargs:
|
|||
self.force_no = force_no
|
||||
self.force_del = force_del
|
||||
if (not self.force_no or (not_display and not display_modified_value)) and not self.force_del:
|
||||
description = option.doc()
|
||||
description = option.description()
|
||||
if not description:
|
||||
description = description.replace('%', '%%')
|
||||
self.kwargs['help'] = description
|
||||
|
|
@ -271,21 +283,29 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
remove_empty_od: bool=False,
|
||||
display_modified_value: bool=True,
|
||||
formatter_class=HelpFormatter,
|
||||
unrestraint: bool=False,
|
||||
_forhelp: bool=False,
|
||||
**kwargs):
|
||||
if not _forhelp:
|
||||
unrestraint = True
|
||||
self.fullpath = fullpath
|
||||
self.config = config
|
||||
self.root = root
|
||||
self.remove_empty_od = remove_empty_od
|
||||
self.unrestraint = unrestraint
|
||||
self.display_modified_value = display_modified_value
|
||||
if TiramisuHelpFormatter not in formatter_class.__mro__:
|
||||
formatter_class = type('TiramisuHelpFormatter', (TiramisuHelpFormatter, formatter_class), {})
|
||||
formatter_class.remove_empty_od = self.remove_empty_od
|
||||
kwargs['formatter_class'] = formatter_class
|
||||
if self.root is None:
|
||||
subconfig = self.config.option
|
||||
if not _forhelp and self.unrestraint:
|
||||
subconfig = self.config.unrestraint
|
||||
else:
|
||||
subconfig = self.config.option(self.root)
|
||||
subconfig = self.config
|
||||
if self.root is None:
|
||||
subconfig = subconfig
|
||||
else:
|
||||
subconfig = subconfig.option(self.root)
|
||||
self.namespace = TiramisuNamespace(self.config, self.root)
|
||||
super().__init__(*args, **kwargs)
|
||||
self.register('action', 'help', _TiramisuHelpAction)
|
||||
|
|
@ -326,7 +346,7 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
def _parse_known_args(self, args=None, namespace=None):
|
||||
try:
|
||||
namespace_, args_ = super()._parse_known_args(args, namespace)
|
||||
except (ValueError, LeadershipError) as err:
|
||||
except (ValueError, LeadershipError, AttributeError) as err:
|
||||
self.error(err)
|
||||
if args != args_ and args_ and args_[0].startswith(self.prefix_chars):
|
||||
# option that was disabled are no more disable
|
||||
|
|
@ -339,6 +359,7 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
formatter_class=self.formatter_class,
|
||||
epilog=self.epilog,
|
||||
description=self.description,
|
||||
unrestraint=self.unrestraint,
|
||||
fullpath=self.fullpath)
|
||||
namespace_, args_ = new_parser._parse_known_args(args_, new_parser.namespace)
|
||||
else:
|
||||
|
|
@ -372,38 +393,41 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
if type != 'boolean':
|
||||
if isinstance(value, list):
|
||||
for val in value:
|
||||
self.prog += f' "{val}"'
|
||||
self.prog += ' "{}"'.format(val)
|
||||
else:
|
||||
self.prog += f' "{value}"'
|
||||
self.prog += ' "{}"'.format(value)
|
||||
|
||||
def _config_list(self,
|
||||
config: Config,
|
||||
prefix: Optional[str],
|
||||
_forhelp: bool,
|
||||
group, level):
|
||||
for obj in config.list(type='all'):
|
||||
for obj in config:
|
||||
# do not display frozen option
|
||||
if 'frozen' in obj.option.properties():
|
||||
if 'frozen' in obj.property.get():
|
||||
continue
|
||||
if obj.option.isoptiondescription():
|
||||
if obj.isoptiondescription():
|
||||
if _forhelp:
|
||||
newgroup = self.add_argument_group(obj.option.path(), obj.option.description())
|
||||
description = obj.description()
|
||||
if description == obj.name():
|
||||
description = None
|
||||
newgroup = self.add_argument_group(obj.path(), description)
|
||||
else:
|
||||
newgroup = group
|
||||
if prefix:
|
||||
prefix_ = prefix + '.' + obj.option.name()
|
||||
prefix_ = prefix + '.' + obj.name()
|
||||
else:
|
||||
prefix_ = obj.option.path()
|
||||
prefix_ = obj.path()
|
||||
self._config_to_argparser(_forhelp, obj, prefix_, newgroup, level + 1)
|
||||
elif obj.option.type() == 'boolean' and not obj.option.issymlinkoption():
|
||||
if not obj.option.isleader():
|
||||
elif obj.type() == 'boolean' and not obj.issymlinkoption():
|
||||
if not obj.isleader():
|
||||
yield obj, False, None
|
||||
yield obj, True, None
|
||||
else:
|
||||
yield obj, False, False
|
||||
yield obj, False, True
|
||||
yield obj, True, None
|
||||
elif obj.option.isleader():
|
||||
elif obj.isleader():
|
||||
yield obj, None, False
|
||||
yield obj, None, True
|
||||
else:
|
||||
|
|
@ -420,13 +444,12 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
actions = {}
|
||||
leadership_len = None
|
||||
options_is_not_default = {}
|
||||
for obj, force_no, force_del in self._config_list(config, prefix, _forhelp, group, level):
|
||||
option = obj.option
|
||||
for option, force_no, force_del in self._config_list(config, prefix, _forhelp, group, level):
|
||||
name = option.name()
|
||||
if name.startswith(self.prefix_chars):
|
||||
raise ValueError(_('name cannot startswith "{}"').format(self.prefix_chars))
|
||||
if option.issymlinkoption():
|
||||
symlink_name = option.name(follow_symlink=True)
|
||||
symlink_name = option.option().name()
|
||||
if symlink_name in options_is_not_default:
|
||||
options_is_not_default[symlink_name]['name'] = name
|
||||
if symlink_name in actions:
|
||||
|
|
@ -436,21 +459,21 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
if force_del:
|
||||
value = None
|
||||
elif option.isleader():
|
||||
value = obj.value.get()
|
||||
value = option.value.get()
|
||||
leadership_len = len(value)
|
||||
elif option.isfollower():
|
||||
value = []
|
||||
try:
|
||||
for index in range(leadership_len):
|
||||
value.append(self.config.option(obj.option.path(), index).value.get())
|
||||
value.append(self.config.option(option.path(), index).value.get())
|
||||
except:
|
||||
value = None
|
||||
else:
|
||||
value = obj.value.get()
|
||||
value = option.value.get()
|
||||
if self.fullpath and prefix:
|
||||
name = prefix + '.' + name
|
||||
if option.isfollower():
|
||||
properties = obj.option.properties()
|
||||
else:
|
||||
properties = obj.property.get()
|
||||
not_display = not option.isfollower() and not obj.owner.isdefault() and value is not None
|
||||
properties = option.property.get()
|
||||
not_display = not option.isfollower() and not option.owner.isdefault() and value is not None
|
||||
kwargs = _BuildKwargs(name, option, self, properties, force_no, force_del, self.display_modified_value, not_display)
|
||||
if _forhelp and not_display and ((value is not False and not force_no) or (value is False and force_no)):
|
||||
options_is_not_default[option.name()] = {'properties': properties,
|
||||
|
|
@ -465,7 +488,7 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
if not 'mandatory' in properties:
|
||||
raise ValueError('"positional" argument must be "mandatory" too')
|
||||
if _forhelp:
|
||||
kwargs['default'] = obj.value.default()
|
||||
kwargs['default'] = option.value.default()
|
||||
else:
|
||||
kwargs['default'] = value
|
||||
kwargs['nargs'] = '?'
|
||||
|
|
@ -490,7 +513,7 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
if option.type() != 'boolean' or force_del:
|
||||
if not force_del:
|
||||
if _forhelp:
|
||||
value = obj.value.default()
|
||||
value = option.value.default()
|
||||
if value not in [None, []]:
|
||||
#kwargs['default'] = kwargs['const'] = option.default()
|
||||
#kwargs['action'] = 'store_const'
|
||||
|
|
@ -508,10 +531,10 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
else:
|
||||
kwargs['nargs'] = 2
|
||||
if _forhelp and 'mandatory' not in properties:
|
||||
metavar = f'[{metavar}]'
|
||||
if option.type() == 'choice' and _forhelp:
|
||||
metavar = '[{}]'.format(metavar)
|
||||
if option.type() == 'choice':
|
||||
# do not manage choice with argparse there is problem with integer problem
|
||||
kwargs['metavar'] = ('INDEX', get_choice_list(obj, properties, True))
|
||||
kwargs['metavar'] = ('INDEX', get_choice_list(option, properties, True))
|
||||
else:
|
||||
kwargs['metavar'] = ('INDEX', metavar)
|
||||
if force_del:
|
||||
|
|
@ -525,9 +548,11 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
if _forhelp and option.type() == 'boolean':
|
||||
kwargs['metavar'] = 'INDEX'
|
||||
kwargs['nargs'] = 1
|
||||
elif option.type() == 'choice' and not option.isfollower() and _forhelp:
|
||||
elif option.type() == 'choice' and not option.isfollower():
|
||||
# do not manage choice with argparse there is problem with integer problem
|
||||
kwargs['choices'] = get_choice_list(obj, properties, False)
|
||||
kwargs['choices'] = get_choice_list(option, properties, False)
|
||||
elif option.type() == 'float':
|
||||
kwargs['type'] = float
|
||||
else:
|
||||
pass
|
||||
actions.setdefault(option.name(), []).append(kwargs)
|
||||
|
|
@ -561,23 +586,23 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
self.error('unrecognized arguments: {}'.format(name))
|
||||
if valid_mandatory:
|
||||
errors = []
|
||||
for key in self.config.value.mandatory():
|
||||
properties = self.config.option(key).option.properties()
|
||||
if not self.config.option(key).option.isfollower():
|
||||
for option in self.config.value.mandatory():
|
||||
properties = option.property.get()
|
||||
if not option.isfollower():
|
||||
if 'positional' not in properties:
|
||||
if self.fullpath or '.' not in key:
|
||||
name = key
|
||||
if self.fullpath:
|
||||
name = option.path()
|
||||
else:
|
||||
name = key.rsplit('.', 1)[1]
|
||||
is_short_name = self._is_short_name(name, 'longargument' in self.config.option(key).property.get())
|
||||
name = option.name()
|
||||
is_short_name = self._is_short_name(name, 'longargument' in option.property.get())
|
||||
args = self._gen_argument(name, is_short_name)
|
||||
else:
|
||||
args = key
|
||||
args = option.path()
|
||||
else:
|
||||
if 'positional' not in properties:
|
||||
args = self._gen_argument(key, False)
|
||||
args = self._gen_argument(option.path(), False)
|
||||
else:
|
||||
args = key
|
||||
args = option.path()
|
||||
if not self.fullpath and '.' in args:
|
||||
args = args.rsplit('.', 1)[1]
|
||||
if 'positional' not in properties:
|
||||
|
|
|
|||
Loading…
Reference in a new issue