python 3.5 support
This commit is contained in:
parent
46866f1e38
commit
ed54090710
|
@ -487,13 +487,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')
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['none', '--int'])
|
||||
parser.parse_args(['none', '--root.int'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
|
@ -503,13 +503,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)
|
||||
f = StringIO()
|
||||
with redirect_stderr(f):
|
||||
try:
|
||||
parser.parse_args(['none', '--int'])
|
||||
parser.parse_args(['none', '--root.int'])
|
||||
except SystemExit as err:
|
||||
assert str(err) == "2"
|
||||
else:
|
||||
|
@ -859,3 +859,32 @@ def test_readme_longargument(json):
|
|||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||
parser.parse_args(['list', '--list', 'a', '--v'])
|
||||
assert config.value.dict() == 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)
|
||||
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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from .api import TiramisuCmdlineParser
|
||||
|
||||
__version__ = "0.2"
|
||||
__version__ = "0.3"
|
||||
__all__ = ('TiramisuCmdlineParser',)
|
||||
|
|
|
@ -20,7 +20,7 @@ from gettext import gettext as _
|
|||
try:
|
||||
from tiramisu import Config
|
||||
from tiramisu.error import PropertiesOptionError, RequirementError, LeadershipError
|
||||
except (ModuleNotFoundError, ImportError):
|
||||
except ImportError:
|
||||
Config = None
|
||||
from tiramisu_api.error import PropertiesOptionError
|
||||
RequirementError = PropertiesOptionError
|
||||
|
@ -29,7 +29,7 @@ try:
|
|||
from tiramisu__api import Config as ConfigJson
|
||||
if Config is None:
|
||||
Config = ConfigJson
|
||||
except ModuleNotFoundError:
|
||||
except ImportError:
|
||||
ConfigJson = Config
|
||||
|
||||
|
||||
|
@ -44,7 +44,7 @@ def get_choice_list(obj, properties, display):
|
|||
if display:
|
||||
choices = '{{{}}}'.format(','.join(choices))
|
||||
if 'mandatory' not in properties:
|
||||
choices = f'[{choices}]'
|
||||
choices = '[{}]'.format(choices)
|
||||
return choices
|
||||
|
||||
|
||||
|
@ -376,9 +376,9 @@ 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,
|
||||
|
@ -512,7 +512,7 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
else:
|
||||
kwargs['nargs'] = 2
|
||||
if _forhelp and 'mandatory' not in properties:
|
||||
metavar = f'[{metavar}]'
|
||||
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))
|
||||
|
|
Loading…
Reference in New Issue