Compare commits
12 commits
9851d246bf
...
5e7c0572c9
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e7c0572c9 | |||
| be7b71ecb2 | |||
| e0ca484170 | |||
| 506f5d77a8 | |||
| 061577fba7 | |||
| b2936a53db | |||
| 41bb650d5b | |||
| 15598724bc | |||
| 002e98d801 | |||
| 91a00df905 | |||
| 39d3d33e5e | |||
| 497ffd290f |
15 changed files with 1015 additions and 650 deletions
22
CHANGELOG.md
Normal file
22
CHANGELOG.md
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
## 0.6.1rc0 (2024-11-06)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- update tiramisu dependency
|
||||||
|
|
||||||
|
## 0.6.0 (2024-11-01)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- black
|
||||||
|
|
||||||
|
## 0.6.0rc0 (2024-10-31)
|
||||||
|
|
||||||
|
### Feat
|
||||||
|
|
||||||
|
- pyproject.toml
|
||||||
|
- portage to tiramisu 5.0
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- only first value
|
||||||
110
README.md
110
README.md
|
|
@ -11,7 +11,9 @@ Let us start with a simple example
|
||||||
|
|
||||||
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||||
from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
||||||
SymLinkOption, OptionDescription, Config
|
SymLinkOption, OptionDescription, \
|
||||||
|
Config, Calculation, Params, ParamValue, ParamOption, \
|
||||||
|
calc_value
|
||||||
# build a Config with:
|
# build a Config with:
|
||||||
# * a choice for select a sub argument (str, list, int)
|
# * a choice for select a sub argument (str, list, int)
|
||||||
choiceoption = ChoiceOption('cmd',
|
choiceoption = ChoiceOption('cmd',
|
||||||
|
|
@ -27,28 +29,37 @@ short_booloption = SymLinkOption('v', booloption)
|
||||||
# * a string option if cmd is 'str'
|
# * a string option if cmd is 'str'
|
||||||
str_ = StrOption('str',
|
str_ = StrOption('str',
|
||||||
'string option',
|
'string option',
|
||||||
properties=('mandatory',),
|
properties=('mandatory',
|
||||||
requires=[{'option': choiceoption,
|
Calculation(calc_value,
|
||||||
'expected': 'str',
|
Params(ParamValue('disabled'),
|
||||||
'action': 'disabled',
|
kwargs={'condition': ParamOption(choiceoption),
|
||||||
'inverse': True}])
|
'reverse_condition': ParamValue(True),
|
||||||
|
'expected': ParamValue('str')})),
|
||||||
|
),
|
||||||
|
)
|
||||||
# * a list of strings option if cmd is 'list'
|
# * a list of strings option if cmd is 'list'
|
||||||
list_ = StrOption('list',
|
list_ = StrOption('list',
|
||||||
'list string option',
|
'list string option',
|
||||||
multi=True,
|
multi=True,
|
||||||
properties=('mandatory',),
|
properties=('mandatory',
|
||||||
requires=[{'option': choiceoption,
|
Calculation(calc_value,
|
||||||
'expected': 'list',
|
Params(ParamValue('disabled'),
|
||||||
'action': 'disabled',
|
kwargs={'condition': ParamOption(choiceoption),
|
||||||
'inverse': True}])
|
'reverse_condition': ParamValue(True),
|
||||||
|
'expected': ParamValue('list')})),
|
||||||
|
),
|
||||||
|
)
|
||||||
# * an integer option if cmd is 'int'
|
# * an integer option if cmd is 'int'
|
||||||
int_ = IntOption('int',
|
int_ = IntOption('int',
|
||||||
'int option',
|
'int option',
|
||||||
properties=('mandatory',),
|
properties=('mandatory',
|
||||||
requires=[{'option': choiceoption,
|
Calculation(calc_value,
|
||||||
'expected': 'int',
|
Params(ParamValue('disabled'),
|
||||||
'action': 'disabled',
|
kwargs={'condition': ParamOption(choiceoption),
|
||||||
'inverse': True}])
|
'reverse_condition': ParamValue(True),
|
||||||
|
'expected': ParamValue('int')})),
|
||||||
|
),
|
||||||
|
)
|
||||||
# Now build Config
|
# Now build Config
|
||||||
config = Config(OptionDescription('root',
|
config = Config(OptionDescription('root',
|
||||||
'root',
|
'root',
|
||||||
|
|
@ -67,62 +78,75 @@ parser.parse_args()
|
||||||
# now, print the result
|
# now, print the result
|
||||||
print('result:')
|
print('result:')
|
||||||
config.property.read_only()
|
config.property.read_only()
|
||||||
for key, value in config.value.dict().items():
|
def display(data):
|
||||||
print('- {} ({}): {}'.format(key,
|
for key, value in data.items():
|
||||||
config.option(key).option.doc(),
|
if key.isoptiondescription():
|
||||||
value))
|
display(value)
|
||||||
|
else:
|
||||||
|
print(f'- {key.path()} ({key.description()}): {value}')
|
||||||
|
display(config.value.get())
|
||||||
```
|
```
|
||||||
|
|
||||||
Let's print help:
|
Let's print help:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
[gnunux@localhost tiramisu-parser]$ python3 prog.py str -h
|
$ python3 prog.py -h
|
||||||
usage: prog.py [-h] [-v] --str STR --list LIST [LIST ...] --int INT
|
usage: prog.py [-h] [-v] [-nv] {str,list,int}
|
||||||
{str,list,int}
|
|
||||||
|
|
||||||
positional arguments:
|
positional arguments:
|
||||||
{str,list,int} choice the sub argument
|
{str,list,int} choice the sub argument
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-v, --verbosity increase output verbosity
|
-v, --verbosity increase output verbosity
|
||||||
--str STR string option
|
-nv, --no-verbosity
|
||||||
--list LIST [LIST ...]
|
|
||||||
list string option
|
|
||||||
--int INT int option
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The positional argument 'cmd' is mandatory:
|
The positional argument 'cmd' is mandatory:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
[gnunux@localhost tiramisu-parser]$ python3 prog.py
|
$ python3 prog.py
|
||||||
usage: prog.py [-h] [-v] --str STR --list LIST [LIST ...] --int INT
|
usage: prog.py [-h] [-v] [-nv] {str,list,int}
|
||||||
{str,list,int}
|
|
||||||
prog.py: error: the following arguments are required: cmd
|
prog.py: error: the following arguments are required: cmd
|
||||||
```
|
```
|
||||||
|
|
||||||
If 'cmd' is 'str', --str become mandatory:
|
If 'cmd' is 'str', --str become mandatory:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
[gnunux@localhost tiramisu-parser]$ python3 prog.py str
|
$ python3 prog.py str
|
||||||
usage: prog.py [-h] [-v] --str STR --list LIST [LIST ...] --int INT
|
usage: prog.py [-h] [-v] --str STR --list LIST [LIST ...] --int INT
|
||||||
{str,list,int}
|
{str,list,int}
|
||||||
prog.py: error: the following arguments are required: --str
|
prog.py: error: the following arguments are required: --str
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Here is help:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ python3 prog.py str -h
|
||||||
|
usage: prog.py "str" [-h] [-v] [-nv] --str STR {str,list,int}
|
||||||
|
|
||||||
|
positional arguments:
|
||||||
|
{str,list,int} choice the sub argument
|
||||||
|
|
||||||
|
options:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
-v, --verbosity increase output verbosity
|
||||||
|
-nv, --no-verbosity
|
||||||
|
--str STR string option
|
||||||
|
```
|
||||||
|
|
||||||
If 'cmd' is 'str', cannot set --int argument:
|
If 'cmd' is 'str', cannot set --int argument:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
[gnunux@localhost tiramisu-parser]$ python3 prog.py str --int 3
|
$ python3 prog.py str --int 3
|
||||||
usage: prog.py [-h] [-v] --str STR --list LIST [LIST ...] --int INT
|
usage: prog.py "str" [-h] [-v] [-nv] --str STR {str,list,int}
|
||||||
{str,list,int}
|
|
||||||
prog.py: error: unrecognized arguments: --int
|
prog.py: error: unrecognized arguments: --int
|
||||||
```
|
```
|
||||||
|
|
||||||
With all mandatories arguments:
|
With all mandatories arguments:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
[gnunux@localhost tiramisu-parser]$ python3 prog.py str --str value
|
$ python3 prog.py str --str value
|
||||||
result:
|
result:
|
||||||
- cmd (choice the sub argument): str
|
- cmd (choice the sub argument): str
|
||||||
- verbosity (increase output verbosity): False
|
- verbosity (increase output verbosity): False
|
||||||
|
|
@ -131,7 +155,7 @@ result:
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
[gnunux@localhost tiramisu-parser]$ python3 prog.py int --int 3
|
$ python3 prog.py int --int 3
|
||||||
result:
|
result:
|
||||||
- cmd (choice the sub argument): int
|
- cmd (choice the sub argument): int
|
||||||
- verbosity (increase output verbosity): False
|
- verbosity (increase output verbosity): False
|
||||||
|
|
@ -140,7 +164,7 @@ result:
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
[gnunux@localhost tiramisu-parser]$ python3 prog.py list --list a b c
|
$ python3 prog.py list --list a b c
|
||||||
result:
|
result:
|
||||||
- cmd (choice the sub argument): list
|
- cmd (choice the sub argument): list
|
||||||
- verbosity (increase output verbosity): False
|
- verbosity (increase output verbosity): False
|
||||||
|
|
@ -151,13 +175,13 @@ result:
|
||||||
Add --verbosity argument:
|
Add --verbosity argument:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
[gnunux@localhost tiramisu-parser]$ python3 prog.py list --list a b c -v
|
$ python3 prog.py list --list a b c -v
|
||||||
result:
|
result:
|
||||||
- cmd (choice the sub argument): list
|
- cmd (choice the sub argument): list
|
||||||
- verbosity (increase output verbosity): True
|
- verbosity (increase output verbosity): True
|
||||||
- v (increase output verbosity): True
|
- v (increase output verbosity): True
|
||||||
- list (list string option): ['a', 'b', 'c']
|
- list (list string option): ['a', 'b', 'c']
|
||||||
[gnunux@localhost tiramisu-parser]$ python3 prog.py list --list a b c --verbosity
|
$ python3 prog.py list --list a b c --verbosity
|
||||||
result:
|
result:
|
||||||
- cmd (choice the sub argument): list
|
- cmd (choice the sub argument): list
|
||||||
- verbosity (increase output verbosity): True
|
- verbosity (increase output verbosity): True
|
||||||
|
|
|
||||||
41
pyproject.toml
Normal file
41
pyproject.toml
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
[build-system]
|
||||||
|
build-backend = "flit_core.buildapi"
|
||||||
|
requires = ["flit_core >=3.8.0,<4"]
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "tiramisu_cmdline_parser"
|
||||||
|
version = "0.6.1"
|
||||||
|
authors = [{name = "Emmanuel Garette", email = "gnunux@gnunux.info"}]
|
||||||
|
readme = "README.md"
|
||||||
|
description = "command-line parser using Tiramisu"
|
||||||
|
requires-python = ">=3.8"
|
||||||
|
license = {file = "LICENSE"}
|
||||||
|
classifiers = [
|
||||||
|
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
|
||||||
|
"Programming Language :: Python",
|
||||||
|
"Programming Language :: Python :: 3.8",
|
||||||
|
"Programming Language :: Python :: 3.9",
|
||||||
|
"Programming Language :: Python :: 3.10",
|
||||||
|
"Programming Language :: Python :: 3.11",
|
||||||
|
"Programming Language :: Python :: 3.12",
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
"Natural Language :: English",
|
||||||
|
"Natural Language :: French",
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
"tiramisu >= 5.0,<6",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
Home = "https://forge.cloud.silique.fr/stove/tiramisu-cmdline-parser"
|
||||||
|
|
||||||
|
[tool.commitizen]
|
||||||
|
name = "cz_conventional_commits"
|
||||||
|
tag_format = "$version"
|
||||||
|
version_scheme = "pep440"
|
||||||
|
version_provider = "pep621"
|
||||||
|
#update_changelog_on_bump = true
|
||||||
|
changelog_merge_prerelease = true
|
||||||
34
setup.py
34
setup.py
|
|
@ -1,34 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from setuptools import setup, find_packages
|
|
||||||
import os
|
|
||||||
from tiramisu_cmdline_parser import __version__
|
|
||||||
|
|
||||||
|
|
||||||
PACKAGE_NAME = os.environ.get('PACKAGE_DST', 'tiramisu_cmdline_parser')
|
|
||||||
|
|
||||||
setup(
|
|
||||||
version=__version__,
|
|
||||||
author="Tiramisu's team",
|
|
||||||
author_email='gnunux@gnunux.info',
|
|
||||||
name=PACKAGE_NAME,
|
|
||||||
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"],
|
|
||||||
classifiers=[
|
|
||||||
"Programming Language :: Python :: 3",
|
|
||||||
"License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)",
|
|
||||||
"Operating System :: OS Independent",
|
|
||||||
"Natural Language :: English",
|
|
||||||
"Natural Language :: French",
|
|
||||||
],
|
|
||||||
long_description="""\
|
|
||||||
tiramisu-cmdline-parser
|
|
||||||
---------------------------------
|
|
||||||
|
|
||||||
Python3 parser for command-line options and arguments using Tiramisu engine.
|
|
||||||
""",
|
|
||||||
include_package_data=True,
|
|
||||||
packages=find_packages(include=['tiramisu_cmdline_parser'])
|
|
||||||
)
|
|
||||||
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
|
|
@ -7,10 +7,12 @@ from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||||
from tiramisu import ChoiceOption, OptionDescription, Config
|
from tiramisu import ChoiceOption, OptionDescription, Config
|
||||||
try:
|
try:
|
||||||
from tiramisu_api import Config as JsonConfig
|
from tiramisu_api import Config as JsonConfig
|
||||||
params = ['tiramisu', 'tiramisu-json']
|
#params = ['tiramisu', 'tiramisu-json']
|
||||||
|
params = ['tiramisu']
|
||||||
except:
|
except:
|
||||||
params = ['tiramisu']
|
params = ['tiramisu']
|
||||||
|
|
||||||
|
from .utils import TestHelpFormatter, to_dict
|
||||||
|
|
||||||
|
|
||||||
def get_config(json):
|
def get_config(json):
|
||||||
|
|
@ -24,7 +26,7 @@ def get_config(json):
|
||||||
properties=('positional', 'mandatory'))
|
properties=('positional', 'mandatory'))
|
||||||
str_ = ChoiceOption('str',
|
str_ = ChoiceOption('str',
|
||||||
'choice the sub argument',
|
'choice the sub argument',
|
||||||
('str1', 'str2', 'str3'))
|
('str1', 'str2', 'str3', None))
|
||||||
int_ = ChoiceOption('int',
|
int_ = ChoiceOption('int',
|
||||||
'choice the sub argument',
|
'choice the sub argument',
|
||||||
(1, 2, 3))
|
(1, 2, 3))
|
||||||
|
|
@ -39,7 +41,7 @@ def get_config(json):
|
||||||
config.property.read_write()
|
config.property.read_write()
|
||||||
if json == 'tiramisu':
|
if json == 'tiramisu':
|
||||||
return config
|
return config
|
||||||
jconfig = JsonConfig(config.option.dict())
|
jconfig = JsonConfig(config.option.get())
|
||||||
return jconfig
|
return jconfig
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -49,20 +51,16 @@ def json(request):
|
||||||
|
|
||||||
|
|
||||||
def test_choice_positional(json):
|
def test_choice_positional(json):
|
||||||
output1 = '''usage: prog.py "str" "1" [-h] [--str {str1,str2,str3}] [--int {1,2,3}]
|
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}
|
||||||
[--int_multi [{1,2,3} [{1,2,3} ...]]]
|
|
||||||
{str,list,int,none} {1,2,3}
|
|
||||||
prog.py: error: argument positional: invalid choice: 'error' (choose from 'str', 'list', 'int', 'none')
|
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}]
|
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}
|
||||||
[--int_multi [{1,2,3} [{1,2,3} ...]]]
|
|
||||||
{str,list,int,none} {1,2,3}
|
|
||||||
prog.py: error: argument positional_int: invalid choice: '4' (choose from '1', '2', '3')
|
prog.py: error: argument positional_int: invalid choice: '4' (choose from '1', '2', '3')
|
||||||
'''
|
'''
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
parser.parse_args(['str', '1'])
|
parser.parse_args(['str', '1'])
|
||||||
assert config.value.dict() == {'positional': 'str',
|
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||||
'positional_int': 1,
|
'positional_int': 1,
|
||||||
'str': None,
|
'str': None,
|
||||||
'int': None,
|
'int': None,
|
||||||
|
|
@ -89,28 +87,25 @@ prog.py: error: argument positional_int: invalid choice: '4' (choose from '1', '
|
||||||
|
|
||||||
|
|
||||||
def test_choice_str(json):
|
def test_choice_str(json):
|
||||||
output = """usage: prog.py "str" "1" --str "str3" [-h] [--str {str1,str2,str3}]
|
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}
|
||||||
[--int {1,2,3}]
|
|
||||||
[--int_multi [{1,2,3} [{1,2,3} ...]]]
|
|
||||||
{str,list,int,none} {1,2,3}
|
|
||||||
prog.py: error: argument --str: invalid choice: 'error' (choose from 'str1', 'str2', 'str3')
|
prog.py: error: argument --str: invalid choice: 'error' (choose from 'str1', 'str2', 'str3')
|
||||||
"""
|
"""
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
parser.parse_args(['str', '1', '--str', 'str1'])
|
parser.parse_args(['str', '1', '--str', 'str1'])
|
||||||
assert config.value.dict() == {'positional': 'str',
|
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||||
'positional_int': 1,
|
'positional_int': 1,
|
||||||
'str': 'str1',
|
'str': 'str1',
|
||||||
'int': None,
|
'int': None,
|
||||||
'int_multi': []}
|
'int_multi': []}
|
||||||
parser.parse_args(['str', '1', '--str', 'str2'])
|
parser.parse_args(['str', '1', '--str', 'str2'])
|
||||||
assert config.value.dict() == {'positional': 'str',
|
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||||
'positional_int': 1,
|
'positional_int': 1,
|
||||||
'str': 'str2',
|
'str': 'str2',
|
||||||
'int': None,
|
'int': None,
|
||||||
'int_multi': []}
|
'int_multi': []}
|
||||||
parser.parse_args(['str', '1', '--str', 'str3'])
|
parser.parse_args(['str', '1', '--str', 'str3'])
|
||||||
assert config.value.dict() == {'positional': 'str',
|
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||||
'positional_int': 1,
|
'positional_int': 1,
|
||||||
'str': 'str3',
|
'str': 'str3',
|
||||||
'int': None,
|
'int': None,
|
||||||
|
|
@ -124,7 +119,7 @@ prog.py: error: argument --str: invalid choice: 'error' (choose from 'str1', 'st
|
||||||
else:
|
else:
|
||||||
raise Exception('must raises')
|
raise Exception('must raises')
|
||||||
assert f.getvalue() == output
|
assert f.getvalue() == output
|
||||||
assert config.value.dict() == {'positional': 'str',
|
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||||
'positional_int': 1,
|
'positional_int': 1,
|
||||||
'str': 'str3',
|
'str': 'str3',
|
||||||
'int': None,
|
'int': None,
|
||||||
|
|
@ -132,16 +127,13 @@ prog.py: error: argument --str: invalid choice: 'error' (choose from 'str1', 'st
|
||||||
|
|
||||||
|
|
||||||
def test_choice_int(json):
|
def test_choice_int(json):
|
||||||
output = """usage: prog.py "str" "1" --int "1" [-h] [--str {str1,str2,str3}]
|
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}
|
||||||
[--int {1,2,3}]
|
|
||||||
[--int_multi [{1,2,3} [{1,2,3} ...]]]
|
|
||||||
{str,list,int,none} {1,2,3}
|
|
||||||
prog.py: error: argument --int: invalid choice: '4' (choose from '1', '2', '3')
|
prog.py: error: argument --int: invalid choice: '4' (choose from '1', '2', '3')
|
||||||
"""
|
"""
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
parser.parse_args(['str', '1', '--int', '1'])
|
parser.parse_args(['str', '1', '--int', '1'])
|
||||||
assert config.value.dict() == {'positional': 'str',
|
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||||
'positional_int': 1,
|
'positional_int': 1,
|
||||||
'str': None,
|
'str': None,
|
||||||
'int': 1,
|
'int': 1,
|
||||||
|
|
@ -155,7 +147,7 @@ prog.py: error: argument --int: invalid choice: '4' (choose from '1', '2', '3')
|
||||||
else:
|
else:
|
||||||
raise Exception('must raises')
|
raise Exception('must raises')
|
||||||
assert f.getvalue() == output
|
assert f.getvalue() == output
|
||||||
assert config.value.dict() == {'positional': 'str',
|
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||||
'positional_int': 1,
|
'positional_int': 1,
|
||||||
'str': None,
|
'str': None,
|
||||||
'int': 1,
|
'int': 1,
|
||||||
|
|
@ -163,16 +155,13 @@ prog.py: error: argument --int: invalid choice: '4' (choose from '1', '2', '3')
|
||||||
|
|
||||||
|
|
||||||
def test_choice_int_multi(json):
|
def test_choice_int_multi(json):
|
||||||
output = """usage: prog.py "str" "1" --int_multi "1" "2" [-h] [--str {str1,str2,str3}]
|
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}
|
||||||
[--int {1,2,3}]
|
|
||||||
[--int_multi [{1,2,3} [{1,2,3} ...]]]
|
|
||||||
{str,list,int,none} {1,2,3}
|
|
||||||
prog.py: error: argument --int_multi: invalid choice: '4' (choose from '1', '2', '3')
|
prog.py: error: argument --int_multi: invalid choice: '4' (choose from '1', '2', '3')
|
||||||
"""
|
"""
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
parser.parse_args(['str', '1', '--int_multi', '1', '2'])
|
parser.parse_args(['str', '1', '--int_multi', '1', '2'])
|
||||||
assert config.value.dict() == {'positional': 'str',
|
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||||
'positional_int': 1,
|
'positional_int': 1,
|
||||||
'str': None,
|
'str': None,
|
||||||
'int': None,
|
'int': None,
|
||||||
|
|
@ -186,7 +175,7 @@ prog.py: error: argument --int_multi: invalid choice: '4' (choose from '1', '2',
|
||||||
else:
|
else:
|
||||||
raise Exception('must raises')
|
raise Exception('must raises')
|
||||||
assert f.getvalue() == output
|
assert f.getvalue() == output
|
||||||
assert config.value.dict() == {'positional': 'str',
|
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||||
'positional_int': 1,
|
'positional_int': 1,
|
||||||
'str': None,
|
'str': None,
|
||||||
'int': None,
|
'int': None,
|
||||||
|
|
@ -200,7 +189,7 @@ prog.py: error: argument --int_multi: invalid choice: '4' (choose from '1', '2',
|
||||||
else:
|
else:
|
||||||
raise Exception('must raises')
|
raise Exception('must raises')
|
||||||
assert f.getvalue() == output
|
assert f.getvalue() == output
|
||||||
assert config.value.dict() == {'positional': 'str',
|
assert to_dict(config.value.get()) == {'positional': 'str',
|
||||||
'positional_int': 1,
|
'positional_int': 1,
|
||||||
'str': None,
|
'str': None,
|
||||||
'int': None,
|
'int': None,
|
||||||
|
|
|
||||||
107
tests/test_default.py
Normal file
107
tests/test_default.py
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
from io import StringIO
|
||||||
|
from contextlib import redirect_stdout, redirect_stderr
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||||
|
from tiramisu import IntOption, StrOption, BoolOption, 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, has_tree=False, default_verbosity=False, add_long=False, add_store_false=False):
|
||||||
|
choiceoption = ChoiceOption('cmd',
|
||||||
|
'choice the sub argument',
|
||||||
|
('str', 'list', 'int', 'none'),
|
||||||
|
properties=('mandatory',))
|
||||||
|
booloption = BoolOption('verbosity',
|
||||||
|
'increase output verbosity',
|
||||||
|
default=default_verbosity,
|
||||||
|
)
|
||||||
|
str_ = StrOption('str',
|
||||||
|
'string option',
|
||||||
|
default='default'
|
||||||
|
)
|
||||||
|
list_ = StrOption('list',
|
||||||
|
'list string option',
|
||||||
|
multi=True,
|
||||||
|
default=['default'],
|
||||||
|
)
|
||||||
|
int_ = IntOption('int',
|
||||||
|
'int option',
|
||||||
|
default=10,
|
||||||
|
)
|
||||||
|
|
||||||
|
root = OptionDescription('root',
|
||||||
|
'root',
|
||||||
|
[choiceoption,
|
||||||
|
booloption,
|
||||||
|
str_,
|
||||||
|
list_,
|
||||||
|
int_
|
||||||
|
])
|
||||||
|
if has_tree:
|
||||||
|
root = OptionDescription('root',
|
||||||
|
'root',
|
||||||
|
[root])
|
||||||
|
config = Config(root)
|
||||||
|
config.property.read_write()
|
||||||
|
if add_store_false:
|
||||||
|
config.option('verbosity').property.add('storefalse')
|
||||||
|
if add_long:
|
||||||
|
config.option('verbosity').property.add('longargument')
|
||||||
|
if json == 'tiramisu':
|
||||||
|
return config
|
||||||
|
jconfig = JsonConfig(config.option.dict())
|
||||||
|
return jconfig
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(params=params)
|
||||||
|
def json(request):
|
||||||
|
return request.param
|
||||||
|
|
||||||
|
|
||||||
|
def test_readme_help(json):
|
||||||
|
output = """usage: prog.py [-h] --cmd {str,list,int,none} [--verbosity] [--no-verbosity] [--str [STR]] [--list [LIST ...]] [--int [INT]]
|
||||||
|
|
||||||
|
options:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
--cmd {str,list,int,none}
|
||||||
|
choice the sub argument
|
||||||
|
--verbosity increase output verbosity (default: False)
|
||||||
|
--no-verbosity
|
||||||
|
--str [STR] string option (default: default)
|
||||||
|
--list [LIST ...] list string option (default: default)
|
||||||
|
--int [INT] int option (default: 10)
|
||||||
|
"""
|
||||||
|
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
|
f = StringIO()
|
||||||
|
with redirect_stdout(f):
|
||||||
|
parser.print_help()
|
||||||
|
assert f.getvalue() == output
|
||||||
|
|
||||||
|
|
||||||
|
def test_readme_help2(json):
|
||||||
|
output = """usage: prog.py [-h] --cmd {str,list,int,none} [--verbosity] [--no-verbosity] [--str [STR]] [--list [LIST ...]] [--int [INT]]
|
||||||
|
|
||||||
|
options:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
--cmd {str,list,int,none}
|
||||||
|
choice the sub argument
|
||||||
|
--verbosity increase output verbosity (default: True)
|
||||||
|
--no-verbosity
|
||||||
|
--str [STR] string option (default: default)
|
||||||
|
--list [LIST ...] list string option (default: default)
|
||||||
|
--int [INT] int option (default: 10)
|
||||||
|
"""
|
||||||
|
parser = TiramisuCmdlineParser(get_config(json, default_verbosity=True), 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
|
f = StringIO()
|
||||||
|
with redirect_stdout(f):
|
||||||
|
parser.print_help()
|
||||||
|
assert f.getvalue() == output
|
||||||
|
|
@ -6,12 +6,14 @@ from argparse import RawDescriptionHelpFormatter
|
||||||
|
|
||||||
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||||
from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
||||||
SymLinkOption, OptionDescription, Config
|
OptionDescription, Config
|
||||||
try:
|
try:
|
||||||
from tiramisu_api import Config as JsonConfig
|
from tiramisu_api import Config as JsonConfig
|
||||||
params = ['tiramisu', 'tiramisu-json']
|
#params = ['tiramisu', 'tiramisu-json']
|
||||||
|
params = ['tiramisu']
|
||||||
except:
|
except:
|
||||||
params = ['tiramisu']
|
params = ['tiramisu']
|
||||||
|
from .utils import TestHelpFormatter
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -43,15 +45,13 @@ def json(request):
|
||||||
def test_help(json):
|
def test_help(json):
|
||||||
output = """usage: prog.py [-h] {str,list,int,none}
|
output = """usage: prog.py [-h] {str,list,int,none}
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
|
||||||
od:
|
od:
|
||||||
od
|
|
||||||
|
|
||||||
{str,list,int,none} choice the sub argument
|
{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()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
@ -61,17 +61,15 @@ od:
|
||||||
def test_help_epilog(json):
|
def test_help_epilog(json):
|
||||||
output = """usage: prog.py [-h] {str,list,int,none}
|
output = """usage: prog.py [-h] {str,list,int,none}
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
|
||||||
od:
|
od:
|
||||||
od
|
|
||||||
|
|
||||||
{str,list,int,none} choice the sub argument
|
{str,list,int,none} choice the sub argument
|
||||||
|
|
||||||
two line
|
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()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
@ -81,12 +79,10 @@ two line
|
||||||
def test_help_epilog_raw(json):
|
def test_help_epilog_raw(json):
|
||||||
output = """usage: prog.py [-h] {str,list,int,none}
|
output = """usage: prog.py [-h] {str,list,int,none}
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
|
||||||
od:
|
od:
|
||||||
od
|
|
||||||
|
|
||||||
{str,list,int,none} choice the sub argument
|
{str,list,int,none} choice the sub argument
|
||||||
|
|
||||||
two
|
two
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,25 @@ import pytest
|
||||||
|
|
||||||
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||||
from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
||||||
SymLinkOption, OptionDescription, Leadership, Config, submulti
|
OptionDescription, Leadership, SymLinkOption, Config, submulti
|
||||||
try:
|
try:
|
||||||
from tiramisu_api import Config as JsonConfig
|
from tiramisu_api import Config as JsonConfig
|
||||||
params = ['tiramisu', 'tiramisu-json']
|
# params = ['tiramisu', 'tiramisu-json']
|
||||||
|
params = ['tiramisu']
|
||||||
except:
|
except:
|
||||||
params = ['tiramisu']
|
params = ['tiramisu']
|
||||||
|
|
||||||
|
from .utils import TestHelpFormatter, to_dict
|
||||||
|
|
||||||
def get_config(json, with_mandatory=False):
|
|
||||||
leader = StrOption('leader', "Leader var", ['192.168.0.1'], multi=True)
|
def get_config(json, with_mandatory=False, with_symlink=False, with_default_value=True):
|
||||||
|
if with_default_value:
|
||||||
|
default = ['192.168.0.1']
|
||||||
|
else:
|
||||||
|
default = []
|
||||||
|
leader = StrOption('leader', "Leader var", default, multi=True)
|
||||||
|
if with_symlink:
|
||||||
|
link_leader = SymLinkOption('l', leader)
|
||||||
follower = StrOption('follower', "Follower", multi=True)
|
follower = StrOption('follower', "Follower", multi=True)
|
||||||
if with_mandatory:
|
if with_mandatory:
|
||||||
properties = ('mandatory',)
|
properties = ('mandatory',)
|
||||||
|
|
@ -22,9 +31,14 @@ def get_config(json, with_mandatory=False):
|
||||||
properties = None
|
properties = None
|
||||||
follower_submulti = StrOption('follower_submulti', "Follower submulti", multi=submulti, properties=properties)
|
follower_submulti = StrOption('follower_submulti', "Follower submulti", multi=submulti, properties=properties)
|
||||||
follower_integer = IntOption('follower_integer', "Follower integer", multi=True)
|
follower_integer = IntOption('follower_integer', "Follower integer", multi=True)
|
||||||
|
if with_symlink:
|
||||||
|
link_follower = SymLinkOption('i', follower_integer)
|
||||||
follower_boolean = BoolOption('follower_boolean', "Follower boolean", multi=True)
|
follower_boolean = BoolOption('follower_boolean', "Follower boolean", multi=True)
|
||||||
follower_choice = ChoiceOption('follower_choice', "Follower choice", ('opt1', 'opt2'), multi=True)
|
follower_choice = ChoiceOption('follower_choice', "Follower choice", ('opt1', 'opt2'), multi=True)
|
||||||
opt_list = [leader, follower, follower_submulti, follower_integer, follower_boolean, follower_choice]
|
opt_list = [leader, follower, follower_submulti, follower_integer, follower_boolean, follower_choice]
|
||||||
|
if with_symlink:
|
||||||
|
opt_list.append(link_leader)
|
||||||
|
opt_list.append(link_follower)
|
||||||
if with_mandatory:
|
if with_mandatory:
|
||||||
opt_list.append(StrOption('follower_mandatory', "Follower mandatory", multi=True, properties=('mandatory',)))
|
opt_list.append(StrOption('follower_mandatory', "Follower mandatory", multi=True, properties=('mandatory',)))
|
||||||
leadership = Leadership('leader', 'leader', opt_list)
|
leadership = Leadership('leader', 'leader', opt_list)
|
||||||
|
|
@ -41,23 +55,13 @@ def json(request):
|
||||||
|
|
||||||
|
|
||||||
def test_leadership_help(json):
|
def test_leadership_help(json):
|
||||||
output = """usage: prog.py [-h] [--leader.leader [LEADER [LEADER ...]]]
|
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
|
||||||
[--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
|
-h, --help show this help message and exit
|
||||||
|
|
||||||
leader:
|
leader:
|
||||||
leader
|
--leader.leader [LEADER ...]
|
||||||
|
|
||||||
--leader.leader [LEADER [LEADER ...]]
|
|
||||||
Leader var
|
Leader var
|
||||||
--leader.pop-leader INDEX
|
--leader.pop-leader INDEX
|
||||||
--leader.follower INDEX [FOLLOWER]
|
--leader.follower INDEX [FOLLOWER]
|
||||||
|
|
@ -74,7 +78,82 @@ leader:
|
||||||
--leader.follower_mandatory INDEX FOLLOWER_MANDATORY
|
--leader.follower_mandatory INDEX FOLLOWER_MANDATORY
|
||||||
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()
|
||||||
|
assert f.getvalue() == output
|
||||||
|
|
||||||
|
|
||||||
|
def test_leadership_help_no_pop(json):
|
||||||
|
output = """usage: prog.py [-h] [--leader.leader [LEADER ...]] [--leader.follower INDEX [FOLLOWER]] --leader.follower_submulti INDEX [FOLLOWER_SUBMULTI ...] [--leader.follower_integer INDEX [FOLLOWER_INTEGER]] [--leader.follower_boolean INDEX] [--leader.follower_choice INDEX [{opt1,opt2}]] --leader.follower_mandatory INDEX FOLLOWER_MANDATORY
|
||||||
|
|
||||||
|
options:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
|
||||||
|
leader:
|
||||||
|
--leader.leader [LEADER ...]
|
||||||
|
Leader var
|
||||||
|
--leader.follower INDEX [FOLLOWER]
|
||||||
|
Follower
|
||||||
|
--leader.follower_submulti INDEX [FOLLOWER_SUBMULTI ...]
|
||||||
|
Follower submulti
|
||||||
|
--leader.follower_integer INDEX [FOLLOWER_INTEGER]
|
||||||
|
Follower integer
|
||||||
|
--leader.follower_boolean INDEX
|
||||||
|
Follower boolean
|
||||||
|
--leader.follower_choice INDEX [{opt1,opt2}]
|
||||||
|
Follower choice
|
||||||
|
--leader.follower_mandatory INDEX FOLLOWER_MANDATORY
|
||||||
|
Follower mandatory
|
||||||
|
"""
|
||||||
|
parser = TiramisuCmdlineParser(get_config(json, with_mandatory=True), 'prog.py', add_extra_options=False, formatter_class=TestHelpFormatter)
|
||||||
|
f = StringIO()
|
||||||
|
with redirect_stdout(f):
|
||||||
|
parser.print_help()
|
||||||
|
assert f.getvalue() == output
|
||||||
|
|
||||||
|
|
||||||
|
def test_leadership_help_short_no_default(json):
|
||||||
|
output = """usage: prog.py [-h] [-l [LEADER ...]]
|
||||||
|
|
||||||
|
options:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
|
||||||
|
leader:
|
||||||
|
-l [LEADER ...], --leader.leader [LEADER ...]
|
||||||
|
Leader var
|
||||||
|
"""
|
||||||
|
parser = TiramisuCmdlineParser(get_config(json, with_mandatory=True, with_symlink=True, with_default_value=False), 'prog.py', add_extra_options=False, formatter_class=TestHelpFormatter)
|
||||||
|
f = StringIO()
|
||||||
|
with redirect_stdout(f):
|
||||||
|
parser.print_help()
|
||||||
|
assert f.getvalue() == output
|
||||||
|
|
||||||
|
|
||||||
|
def test_leadership_help_short(json):
|
||||||
|
output = """usage: prog.py [-h] [-l [LEADER ...]] [--leader.follower INDEX [FOLLOWER]] --leader.follower_submulti INDEX [FOLLOWER_SUBMULTI ...] [-i INDEX [FOLLOWER_INTEGER]] [--leader.follower_boolean INDEX] [--leader.follower_choice INDEX [{opt1,opt2}]] --leader.follower_mandatory INDEX FOLLOWER_MANDATORY
|
||||||
|
|
||||||
|
options:
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
|
||||||
|
leader:
|
||||||
|
-l [LEADER ...], --leader.leader [LEADER ...]
|
||||||
|
Leader var
|
||||||
|
--leader.follower INDEX [FOLLOWER]
|
||||||
|
Follower
|
||||||
|
--leader.follower_submulti INDEX [FOLLOWER_SUBMULTI ...]
|
||||||
|
Follower submulti
|
||||||
|
-i INDEX [FOLLOWER_INTEGER], --leader.follower_integer INDEX [FOLLOWER_INTEGER]
|
||||||
|
Follower integer
|
||||||
|
--leader.follower_boolean INDEX
|
||||||
|
Follower boolean
|
||||||
|
--leader.follower_choice INDEX [{opt1,opt2}]
|
||||||
|
Follower choice
|
||||||
|
--leader.follower_mandatory INDEX FOLLOWER_MANDATORY
|
||||||
|
Follower mandatory
|
||||||
|
"""
|
||||||
|
parser = TiramisuCmdlineParser(get_config(json, with_mandatory=True, with_symlink=True), 'prog.py', add_extra_options=False, formatter_class=TestHelpFormatter)
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
@ -92,7 +171,7 @@ def test_leadership_modif_leader(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['--leader.leader', '192.168.1.1'])
|
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):
|
def test_leadership_modif_follower(json):
|
||||||
|
|
@ -106,23 +185,16 @@ def test_leadership_modif_follower(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['--leader.follower', '0', '255.255.255.0'])
|
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):
|
def test_leadership_modif_follower_not_submulti(json):
|
||||||
output = """usage: prog.py [-h] [--leader.leader [LEADER [LEADER ...]]]
|
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.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
|
prog.py: error: unrecognized arguments: 255.255.255.0
|
||||||
"""
|
"""
|
||||||
|
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -145,7 +217,7 @@ def test_leadership_modif_follower_submulti(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['--leader.follower_submulti', '0', '255.255.255.0'])
|
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):
|
def test_leadership_modif_follower_submulti_multi(json):
|
||||||
|
|
@ -159,7 +231,7 @@ def test_leadership_modif_follower_submulti_multi(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['--leader.follower_submulti', '0', '255.255.255.0', '255.255.255.128'])
|
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):
|
def test_leadership_modif_follower_bool_true(json):
|
||||||
|
|
@ -173,7 +245,7 @@ def test_leadership_modif_follower_bool_true(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['--leader.follower_boolean', '0'])
|
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):
|
def test_leadership_modif_follower_bool_false(json):
|
||||||
|
|
@ -187,7 +259,7 @@ def test_leadership_modif_follower_bool_false(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['--leader.no-follower_boolean', '0'])
|
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):
|
def test_leadership_modif_follower_bool_true_fullname(json):
|
||||||
|
|
@ -201,7 +273,7 @@ def test_leadership_modif_follower_bool_true_fullname(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||||
parser.parse_args(['--follower_boolean', '0'])
|
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):
|
def test_leadership_modif_follower_bool_false_fullname(json):
|
||||||
|
|
@ -215,7 +287,7 @@ def test_leadership_modif_follower_bool_false_fullname(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||||
parser.parse_args(['--no-follower_boolean', '0'])
|
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):
|
def test_leadership_modif_follower_choice(json):
|
||||||
|
|
@ -229,22 +301,15 @@ def test_leadership_modif_follower_choice(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['--leader.follower_choice', '0', 'opt1'])
|
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):
|
def test_leadership_modif_follower_choice_unknown(json):
|
||||||
output = """usage: prog.py [-h] [--leader.leader [LEADER [LEADER ...]]]
|
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.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')
|
prog.py: error: argument --leader.follower_choice: invalid choice: 'opt_unknown' (choose from 'opt1', 'opt2')
|
||||||
"""
|
"""
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -257,19 +322,12 @@ prog.py: error: argument --leader.follower_choice: invalid choice: 'opt_unknown'
|
||||||
|
|
||||||
|
|
||||||
def test_leadership_modif_follower_not_number(json):
|
def test_leadership_modif_follower_not_number(json):
|
||||||
output = """usage: prog.py [-h] [--leader.leader [LEADER [LEADER ...]]]
|
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.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
|
prog.py: error: index must be a number, not a
|
||||||
"""
|
"""
|
||||||
|
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -294,7 +352,7 @@ def test_leadership_modif_multi(json):
|
||||||
parser.parse_args(['--leader.leader', '192.168.1.1', '10.253.10.1', '192.168.253.1',
|
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', '0', '255.255.255.128',
|
||||||
'--leader.follower', '2', '255.255.255.0'])
|
'--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):
|
def test_leadership_modif_multi_reduce(json):
|
||||||
|
|
@ -311,7 +369,7 @@ def test_leadership_modif_multi_reduce(json):
|
||||||
'--leader.follower', '0', '255.255.255.128',
|
'--leader.follower', '0', '255.255.255.128',
|
||||||
'--leader.follower', '2', '255.255.255.0',
|
'--leader.follower', '2', '255.255.255.0',
|
||||||
'--leader.pop-leader', '1'])
|
'--leader.pop-leader', '1'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
|
|
||||||
|
|
||||||
def test_leadership_modif_mandatory(json):
|
def test_leadership_modif_mandatory(json):
|
||||||
|
|
@ -322,22 +380,11 @@ def test_leadership_modif_mandatory(json):
|
||||||
'leader.follower_choice': [None],
|
'leader.follower_choice': [None],
|
||||||
'leader.follower_integer': [None],
|
'leader.follower_integer': [None],
|
||||||
'leader.follower_submulti': [['255.255.255.128']]}
|
'leader.follower_submulti': [['255.255.255.128']]}
|
||||||
output2 = """usage: prog.py --leader.leader "192.168.1.1" [-h]
|
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
|
||||||
[--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
|
|
||||||
prog.py: error: the following arguments are required: --leader.follower_submulti"""
|
prog.py: error: the following arguments are required: --leader.follower_submulti"""
|
||||||
|
|
||||||
config = get_config(json, with_mandatory=True)
|
config = get_config(json, with_mandatory=True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -360,7 +407,7 @@ prog.py: error: the following arguments are required: --leader.follower_submulti
|
||||||
parser.parse_args(['--leader.leader', '192.168.1.1',
|
parser.parse_args(['--leader.leader', '192.168.1.1',
|
||||||
'--leader.follower_submulti', '0', '255.255.255.128',
|
'--leader.follower_submulti', '0', '255.255.255.128',
|
||||||
'--leader.follower_mandatory', '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):
|
def test_leadership_modif_mandatory_remove(json):
|
||||||
|
|
@ -371,20 +418,11 @@ def test_leadership_modif_mandatory_remove(json):
|
||||||
'leader.follower_choice': [None],
|
'leader.follower_choice': [None],
|
||||||
'leader.follower_integer': [None],
|
'leader.follower_integer': [None],
|
||||||
'leader.follower_submulti': [['255.255.255.128']]}
|
'leader.follower_submulti': [['255.255.255.128']]}
|
||||||
output2 = """usage: prog.py --leader.leader "192.168.1.1" [-h] [--leader.pop-leader INDEX]
|
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
|
||||||
[--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"""
|
prog.py: error: the following arguments are required: --leader.follower_submulti"""
|
||||||
|
|
||||||
config = get_config(json, with_mandatory=True)
|
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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -407,7 +445,7 @@ prog.py: error: the following arguments are required: --leader.follower_submulti
|
||||||
parser.parse_args(['--leader.leader', '192.168.1.1',
|
parser.parse_args(['--leader.leader', '192.168.1.1',
|
||||||
'--leader.follower_submulti', '0', '255.255.255.128',
|
'--leader.follower_submulti', '0', '255.255.255.128',
|
||||||
'--leader.follower_mandatory', '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):
|
def test_leadership_modif_mandatory_unvalidate(json):
|
||||||
|
|
@ -421,4 +459,4 @@ def test_leadership_modif_mandatory_unvalidate(json):
|
||||||
config = get_config(json, with_mandatory=True)
|
config = get_config(json, with_mandatory=True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['--leader.leader', '192.168.1.1'], valid_mandatory=False)
|
parser.parse_args(['--leader.leader', '192.168.1.1'], valid_mandatory=False)
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,11 @@ from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
||||||
SymLinkOption, OptionDescription, Config
|
SymLinkOption, OptionDescription, Config
|
||||||
try:
|
try:
|
||||||
from tiramisu_api import Config as JsonConfig
|
from tiramisu_api import Config as JsonConfig
|
||||||
params = ['tiramisu', 'tiramisu-json']
|
#params = ['tiramisu', 'tiramisu-json']
|
||||||
|
params = ['tiramisu']
|
||||||
except:
|
except:
|
||||||
params = ['tiramisu']
|
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):
|
def get_config(json, has_tree=False, default_verbosity=False, add_long=False, add_store_false=False, empty_optiondescription=False):
|
||||||
|
|
@ -69,11 +71,9 @@ def json(request):
|
||||||
|
|
||||||
|
|
||||||
def test_optiondescription_help(json):
|
def test_optiondescription_help(json):
|
||||||
output = """usage: prog.py [-h] [-v] [-nv] --od2.subtree.str STR --od2.before BEFORE
|
output = """usage: prog.py [-h] [-v] [-nv] --od2.subtree.str STR --od2.before BEFORE --od2.after AFTER {str,list,int,none}
|
||||||
--od2.after AFTER
|
|
||||||
{str,list,int,none}
|
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
|
||||||
od1:
|
od1:
|
||||||
|
|
@ -84,7 +84,7 @@ od1.od0:
|
||||||
|
|
||||||
{str,list,int,none} choice the sub argument
|
{str,list,int,none} choice the sub argument
|
||||||
-v, --od1.od0.verbosity
|
-v, --od1.od0.verbosity
|
||||||
increase output verbosity
|
increase output verbosity (default: False)
|
||||||
-nv, --od1.od0.no-verbosity
|
-nv, --od1.od0.no-verbosity
|
||||||
|
|
||||||
od2:
|
od2:
|
||||||
|
|
@ -97,7 +97,7 @@ od2.subtree:
|
||||||
--od2.subtree.str STR
|
--od2.subtree.str STR
|
||||||
string option 2
|
string option 2
|
||||||
"""
|
"""
|
||||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
@ -105,11 +105,9 @@ od2.subtree:
|
||||||
|
|
||||||
|
|
||||||
def test_optiondescription_help_remove_empty_od(json):
|
def test_optiondescription_help_remove_empty_od(json):
|
||||||
output = """usage: prog.py [-h] [-v] [-nv] --od2.subtree.str STR --od2.before BEFORE
|
output = """usage: prog.py [-h] [-v] [-nv] --od2.subtree.str STR --od2.before BEFORE --od2.after AFTER {str,list,int,none}
|
||||||
--od2.after AFTER
|
|
||||||
{str,list,int,none}
|
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
|
||||||
od1.od0:
|
od1.od0:
|
||||||
|
|
@ -117,7 +115,7 @@ od1.od0:
|
||||||
|
|
||||||
{str,list,int,none} choice the sub argument
|
{str,list,int,none} choice the sub argument
|
||||||
-v, --od1.od0.verbosity
|
-v, --od1.od0.verbosity
|
||||||
increase output verbosity
|
increase output verbosity (default: False)
|
||||||
-nv, --od1.od0.no-verbosity
|
-nv, --od1.od0.no-verbosity
|
||||||
|
|
||||||
od2:
|
od2:
|
||||||
|
|
@ -130,7 +128,7 @@ od2.subtree:
|
||||||
--od2.subtree.str STR
|
--od2.subtree.str STR
|
||||||
string option 2
|
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()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
@ -138,11 +136,9 @@ od2.subtree:
|
||||||
|
|
||||||
|
|
||||||
def test_optiondescription_help_remove_empty_description_od(json):
|
def test_optiondescription_help_remove_empty_description_od(json):
|
||||||
output = """usage: prog.py [-h] [-v] [-nv] --od2.subtree.str STR --od2.before BEFORE
|
output = """usage: prog.py [-h] [-v] [-nv] --od2.subtree.str STR --od2.before BEFORE --od2.after AFTER {str,list,int,none}
|
||||||
--od2.after AFTER
|
|
||||||
{str,list,int,none}
|
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
|
||||||
od1.od0:
|
od1.od0:
|
||||||
|
|
@ -150,7 +146,7 @@ od1.od0:
|
||||||
|
|
||||||
{str,list,int,none} choice the sub argument
|
{str,list,int,none} choice the sub argument
|
||||||
-v, --od1.od0.verbosity
|
-v, --od1.od0.verbosity
|
||||||
increase output verbosity
|
increase output verbosity (default: False)
|
||||||
-nv, --od1.od0.no-verbosity
|
-nv, --od1.od0.no-verbosity
|
||||||
|
|
||||||
od2:
|
od2:
|
||||||
|
|
@ -163,7 +159,7 @@ od2.subtree:
|
||||||
--od2.subtree.str STR
|
--od2.subtree.str STR
|
||||||
string option 2
|
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()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
@ -171,10 +167,9 @@ od2.subtree:
|
||||||
|
|
||||||
|
|
||||||
def test_optiondescription_help_subtree(json):
|
def test_optiondescription_help_subtree(json):
|
||||||
output = """usage: prog.py [-h] --od2.subtree.str STR --od2.before BEFORE --od2.after
|
output = """usage: prog.py [-h] --od2.subtree.str STR --od2.before BEFORE --od2.after AFTER
|
||||||
AFTER
|
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
--od2.before BEFORE Before
|
--od2.before BEFORE Before
|
||||||
--od2.after AFTER After
|
--od2.after AFTER After
|
||||||
|
|
@ -186,7 +181,7 @@ od2.subtree:
|
||||||
string option 2
|
string option 2
|
||||||
"""
|
"""
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py', root='od2')
|
parser = TiramisuCmdlineParser(config, 'prog.py', root='od2', formatter_class=TestHelpFormatter)
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,15 @@ import pytest
|
||||||
|
|
||||||
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||||
from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
||||||
SymLinkOption, OptionDescription, Config
|
SymLinkOption, OptionDescription, Config, calc_value, \
|
||||||
|
Calculation, ParamValue, ParamOption, Params
|
||||||
try:
|
try:
|
||||||
from tiramisu_api import Config as JsonConfig
|
from tiramisu_api import Config as JsonConfig
|
||||||
params = ['tiramisu', 'tiramisu-json']
|
#params = ['tiramisu', 'tiramisu-json']
|
||||||
|
params = ['tiramisu']
|
||||||
except:
|
except:
|
||||||
params = ['tiramisu']
|
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):
|
def get_config(json, has_tree=False, default_verbosity=False, add_long=False, add_store_false=False):
|
||||||
|
|
@ -25,26 +28,35 @@ def get_config(json, has_tree=False, default_verbosity=False, add_long=False, ad
|
||||||
short_booloption = SymLinkOption('v', booloption)
|
short_booloption = SymLinkOption('v', booloption)
|
||||||
str_ = StrOption('str',
|
str_ = StrOption('str',
|
||||||
'string option',
|
'string option',
|
||||||
properties=('mandatory',),
|
properties=('mandatory',
|
||||||
requires=[{'option': choiceoption,
|
Calculation(calc_value,
|
||||||
'expected': 'str',
|
Params(ParamValue('disabled'),
|
||||||
'action': 'disabled',
|
kwargs={'condition': ParamOption(choiceoption),
|
||||||
'inverse': True}])
|
'reverse_condition': ParamValue(True),
|
||||||
|
'expected': ParamValue('str')})),
|
||||||
|
),
|
||||||
|
)
|
||||||
list_ = StrOption('list',
|
list_ = StrOption('list',
|
||||||
'list string option',
|
'list string option',
|
||||||
multi=True,
|
multi=True,
|
||||||
properties=('mandatory',),
|
properties=('mandatory',
|
||||||
requires=[{'option': choiceoption,
|
Calculation(calc_value,
|
||||||
'expected': 'list',
|
Params(ParamValue('disabled'),
|
||||||
'action': 'disabled',
|
kwargs={'condition': ParamOption(choiceoption),
|
||||||
'inverse': True}])
|
'reverse_condition': ParamValue(True),
|
||||||
|
'expected': ParamValue('list')})),
|
||||||
|
),
|
||||||
|
)
|
||||||
int_ = IntOption('int',
|
int_ = IntOption('int',
|
||||||
'int option',
|
'int option',
|
||||||
properties=('mandatory',),
|
properties=('mandatory',
|
||||||
requires=[{'option': choiceoption,
|
Calculation(calc_value,
|
||||||
'expected': 'int',
|
Params(ParamValue('disabled'),
|
||||||
'action': 'disabled',
|
kwargs={'condition': ParamOption(choiceoption),
|
||||||
'inverse': True}])
|
'reverse_condition': ParamValue(True),
|
||||||
|
'expected': ParamValue('int')})),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
root = OptionDescription('root',
|
root = OptionDescription('root',
|
||||||
'root',
|
'root',
|
||||||
|
|
@ -82,12 +94,12 @@ def test_readme_help(json):
|
||||||
positional arguments:
|
positional arguments:
|
||||||
{str,list,int,none} choice the sub argument
|
{str,list,int,none} choice the sub argument
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-v, --verbosity increase output verbosity
|
-v, --verbosity increase output verbosity (default: False)
|
||||||
-nv, --no-verbosity
|
-nv, --no-verbosity
|
||||||
"""
|
"""
|
||||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
@ -97,17 +109,15 @@ optional arguments:
|
||||||
def test_readme_help_tree(json):
|
def test_readme_help_tree(json):
|
||||||
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
|
||||||
root:
|
root:
|
||||||
root
|
|
||||||
|
|
||||||
{str,list,int,none} choice the sub argument
|
{str,list,int,none} choice the sub argument
|
||||||
-v, --root.verbosity increase output verbosity
|
-v, --root.verbosity increase output verbosity (default: False)
|
||||||
-nv, --root.no-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()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
@ -117,17 +127,15 @@ root:
|
||||||
def test_readme_help_tree_flatten(json):
|
def test_readme_help_tree_flatten(json):
|
||||||
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
|
|
||||||
root:
|
root:
|
||||||
root
|
|
||||||
|
|
||||||
{str,list,int,none} choice the sub argument
|
{str,list,int,none} choice the sub argument
|
||||||
-v, --verbosity increase output verbosity
|
-v, --verbosity increase output verbosity (default: False)
|
||||||
-nv, --no-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()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
@ -140,13 +148,13 @@ def test_readme_help_modif_positional(json):
|
||||||
positional arguments:
|
positional arguments:
|
||||||
{str,list,int,none} choice the sub argument
|
{str,list,int,none} choice the sub argument
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-v, --verbosity increase output verbosity
|
-v, --verbosity increase output verbosity (default: False)
|
||||||
-nv, --no-verbosity
|
-nv, --no-verbosity
|
||||||
--str STR string option
|
--str STR string option
|
||||||
"""
|
"""
|
||||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -161,13 +169,13 @@ optional arguments:
|
||||||
def test_readme_help_modif_positional_remove(json):
|
def test_readme_help_modif_positional_remove(json):
|
||||||
output = """usage: prog.py "str" [-h] [-v] [-nv] --str STR
|
output = """usage: prog.py "str" [-h] [-v] [-nv] --str STR
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-v, --verbosity increase output verbosity
|
-v, --verbosity increase output verbosity (default: False)
|
||||||
-nv, --no-verbosity
|
-nv, --no-verbosity
|
||||||
--str STR string option
|
--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()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -180,19 +188,18 @@ optional arguments:
|
||||||
|
|
||||||
|
|
||||||
def test_readme_help_modif(json):
|
def test_readme_help_modif(json):
|
||||||
output = """usage: prog.py "str" --str "toto" [-h] [-v] [-nv] --str STR
|
output = """usage: prog.py "str" --str "toto" [-h] [-v] [-nv] --str STR {str,list,int,none}
|
||||||
{str,list,int,none}
|
|
||||||
|
|
||||||
positional arguments:
|
positional arguments:
|
||||||
{str,list,int,none} choice the sub argument
|
{str,list,int,none} choice the sub argument
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-v, --verbosity increase output verbosity
|
-v, --verbosity increase output verbosity (default: False)
|
||||||
-nv, --no-verbosity
|
-nv, --no-verbosity
|
||||||
--str STR string option
|
--str STR string option
|
||||||
"""
|
"""
|
||||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -207,12 +214,12 @@ optional arguments:
|
||||||
def test_readme_help_modif_remove(json):
|
def test_readme_help_modif_remove(json):
|
||||||
output = """usage: prog.py "str" --str "toto" [-h] [-v] [-nv]
|
output = """usage: prog.py "str" --str "toto" [-h] [-v] [-nv]
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-v, --verbosity increase output verbosity
|
-v, --verbosity increase output verbosity (default: False)
|
||||||
-nv, --no-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()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -230,13 +237,13 @@ def test_readme_help_modif_short(json):
|
||||||
positional arguments:
|
positional arguments:
|
||||||
{str,list,int,none} choice the sub argument
|
{str,list,int,none} choice the sub argument
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-v, --verbosity increase output verbosity
|
-v, --verbosity increase output verbosity (default: False)
|
||||||
-nv, --no-verbosity
|
-nv, --no-verbosity
|
||||||
--str STR string option
|
--str STR string option
|
||||||
"""
|
"""
|
||||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -252,12 +259,12 @@ def test_readme_help_modif_short_remove(json):
|
||||||
# FIXME -v -nv ?? pas de description
|
# FIXME -v -nv ?? pas de description
|
||||||
output = """usage: prog.py "str" -v [-h] [-nv] --str STR
|
output = """usage: prog.py "str" -v [-h] [-nv] --str STR
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-nv, --no-verbosity increase output verbosity
|
-nv, --no-verbosity increase output verbosity (default: False)
|
||||||
--str STR string option
|
--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()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -275,13 +282,13 @@ def test_readme_help_modif_short_no1(json):
|
||||||
positional arguments:
|
positional arguments:
|
||||||
{str,list,int,none} choice the sub argument
|
{str,list,int,none} choice the sub argument
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-v, --verbosity increase output verbosity
|
-v, --verbosity increase output verbosity (default: False)
|
||||||
-nv, --no-verbosity
|
-nv, --no-verbosity
|
||||||
--str STR string option
|
--str STR string option
|
||||||
"""
|
"""
|
||||||
parser = TiramisuCmdlineParser(get_config(json), 'prog.py')
|
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', formatter_class=TestHelpFormatter)
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -296,12 +303,12 @@ optional arguments:
|
||||||
def test_readme_help_modif_short_no_remove(json):
|
def test_readme_help_modif_short_no_remove(json):
|
||||||
output = """usage: prog.py "str" -v [-h] [-v] --str STR
|
output = """usage: prog.py "str" -v [-h] [-v] --str STR
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-v, --verbosity increase output verbosity
|
-v, --verbosity increase output verbosity (default: False)
|
||||||
--str STR string option
|
--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()
|
f = StringIO()
|
||||||
with redirect_stdout(f):
|
with redirect_stdout(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -317,7 +324,7 @@ def test_readme_positional_mandatory(json):
|
||||||
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
||||||
prog.py: error: the following arguments are required: cmd
|
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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -333,7 +340,7 @@ def test_readme_positional_mandatory_tree(json):
|
||||||
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
||||||
prog.py: error: the following arguments are required: root.cmd
|
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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -349,7 +356,7 @@ def test_readme_positional_mandatory_tree_flatten(json):
|
||||||
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
||||||
prog.py: error: the following arguments are required: cmd
|
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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -365,7 +372,7 @@ def test_readme_mandatory(json):
|
||||||
output = """usage: prog.py "str" [-h] [-v] [-nv] --str STR {str,list,int,none}
|
output = """usage: prog.py "str" [-h] [-v] [-nv] --str STR {str,list,int,none}
|
||||||
prog.py: error: the following arguments are required: --str
|
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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -381,7 +388,7 @@ def test_readme_mandatory_remove(json):
|
||||||
output = """usage: prog.py "str" [-h] [-v] [-nv] --str STR
|
output = """usage: prog.py "str" [-h] [-v] [-nv] --str STR
|
||||||
prog.py: error: the following arguments are required: --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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -397,7 +404,7 @@ def test_readme_mandatory_tree(json):
|
||||||
output = """usage: prog.py "str" [-h] [-v] [-nv] --root.str STR {str,list,int,none}
|
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
|
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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -413,7 +420,7 @@ def test_readme_mandatory_tree_remove(json):
|
||||||
output = """usage: prog.py "str" [-h] [-v] [-nv] --root.str STR
|
output = """usage: prog.py "str" [-h] [-v] [-nv] --root.str STR
|
||||||
prog.py: error: the following arguments are required: --root.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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -429,7 +436,7 @@ def test_readme_mandatory_tree_flatten(json):
|
||||||
output = """usage: prog.py "str" [-h] [-v] [-nv] --str STR {str,list,int,none}
|
output = """usage: prog.py "str" [-h] [-v] [-nv] --str STR {str,list,int,none}
|
||||||
prog.py: error: the following arguments are required: --str
|
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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -445,7 +452,7 @@ def test_readme_mandatory_tree_flatten_remove(json):
|
||||||
output = """usage: prog.py "str" [-h] [-v] [-nv] --str STR
|
output = """usage: prog.py "str" [-h] [-v] [-nv] --str STR
|
||||||
prog.py: error: the following arguments are required: --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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -461,7 +468,7 @@ def test_readme_cross(json):
|
||||||
output = """usage: prog.py "none" [-h] [-v] [-nv] {str,list,int,none}
|
output = """usage: prog.py "none" [-h] [-v] [-nv] {str,list,int,none}
|
||||||
prog.py: error: unrecognized arguments: --int
|
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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -477,7 +484,7 @@ def test_readme_cross_remove(json):
|
||||||
output = """usage: prog.py "none" [-h] [-v] [-nv]
|
output = """usage: prog.py "none" [-h] [-v] [-nv]
|
||||||
prog.py: error: unrecognized arguments: --int
|
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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -493,7 +500,7 @@ def test_readme_cross_tree(json):
|
||||||
output = """usage: prog.py "none" [-h] [-v] [-nv] {str,list,int,none}
|
output = """usage: prog.py "none" [-h] [-v] [-nv] {str,list,int,none}
|
||||||
prog.py: error: unrecognized arguments: --root.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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -509,7 +516,7 @@ def test_readme_cross_tree_remove(json):
|
||||||
output = """usage: prog.py "none" [-h] [-v] [-nv]
|
output = """usage: prog.py "none" [-h] [-v] [-nv]
|
||||||
prog.py: error: unrecognized arguments: --root.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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -525,7 +532,7 @@ def test_readme_cross_tree_flatten(json):
|
||||||
output = """usage: prog.py "none" [-h] [-v] [-nv] {str,list,int,none}
|
output = """usage: prog.py "none" [-h] [-v] [-nv] {str,list,int,none}
|
||||||
prog.py: error: unrecognized arguments: --int
|
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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -541,7 +548,7 @@ def test_readme_cross_tree_flatten_remove(json):
|
||||||
output = """usage: prog.py "none" [-h] [-v] [-nv]
|
output = """usage: prog.py "none" [-h] [-v] [-nv]
|
||||||
prog.py: error: unrecognized arguments: --int
|
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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -557,7 +564,7 @@ def test_readme_unknown(json):
|
||||||
output = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
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')
|
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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
@ -577,7 +584,7 @@ def test_readme_int(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['int', '--int', '3'])
|
parser.parse_args(['int', '--int', '3'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
|
|
||||||
|
|
||||||
def test_readme_int_tree(json):
|
def test_readme_int_tree(json):
|
||||||
|
|
@ -588,7 +595,7 @@ def test_readme_int_tree(json):
|
||||||
config = get_config(json, True)
|
config = get_config(json, True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['int', '--root.int', '3'])
|
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):
|
def test_readme_int_tree_flatten(json):
|
||||||
|
|
@ -599,7 +606,7 @@ def test_readme_int_tree_flatten(json):
|
||||||
config = get_config(json, True)
|
config = get_config(json, True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||||
parser.parse_args(['int', '--int', '3'])
|
parser.parse_args(['int', '--int', '3'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
|
|
||||||
|
|
||||||
def test_readme_int_verbosity(json):
|
def test_readme_int_verbosity(json):
|
||||||
|
|
@ -610,7 +617,7 @@ def test_readme_int_verbosity(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['int', '--int', '3', '--verbosity'])
|
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):
|
def test_readme_int_verbosity_tree(json):
|
||||||
|
|
@ -621,7 +628,7 @@ def test_readme_int_verbosity_tree(json):
|
||||||
config = get_config(json, True)
|
config = get_config(json, True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['int', '--root.int', '3', '--root.verbosity'])
|
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):
|
def test_readme_int_verbosity_tree_flatten(json):
|
||||||
|
|
@ -632,7 +639,7 @@ def test_readme_int_verbosity_tree_flatten(json):
|
||||||
config = get_config(json, True)
|
config = get_config(json, True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||||
parser.parse_args(['int', '--int', '3', '--verbosity'])
|
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):
|
def test_readme_int_verbosity_short(json):
|
||||||
|
|
@ -643,7 +650,7 @@ def test_readme_int_verbosity_short(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['int', '--int', '3', '-v'])
|
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):
|
def test_readme_int_verbosity_short_store_false(json):
|
||||||
|
|
@ -658,13 +665,13 @@ def test_readme_int_verbosity_short_store_false(json):
|
||||||
'int': 3,
|
'int': 3,
|
||||||
'verbosity': False,
|
'verbosity': False,
|
||||||
'v': False}
|
'v': False}
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
parser.parse_args(['int', '--int', '3', '-nv'])
|
parser.parse_args(['int', '--int', '3', '-nv'])
|
||||||
output = {'cmd': 'int',
|
output = {'cmd': 'int',
|
||||||
'int': 3,
|
'int': 3,
|
||||||
'verbosity': True,
|
'verbosity': True,
|
||||||
'v': True}
|
'v': True}
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
|
|
||||||
|
|
||||||
def test_readme_int_verbosity_short_no(json):
|
def test_readme_int_verbosity_short_no(json):
|
||||||
|
|
@ -675,7 +682,7 @@ def test_readme_int_verbosity_short_no(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['int', '--int', '3', '-nv'])
|
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):
|
def test_readme_int_verbosity_short_tree(json):
|
||||||
|
|
@ -686,7 +693,7 @@ def test_readme_int_verbosity_short_tree(json):
|
||||||
config = get_config(json, True)
|
config = get_config(json, True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['int', '--root.int', '3', '-v'])
|
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):
|
def test_readme_int_verbosity_short_tree_flatten(json):
|
||||||
|
|
@ -697,7 +704,7 @@ def test_readme_int_verbosity_short_tree_flatten(json):
|
||||||
config = get_config(json, True)
|
config = get_config(json, True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||||
parser.parse_args(['int', '--int', '3', '-v'])
|
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):
|
def test_readme_int_verbosity_short_and_not(json):
|
||||||
|
|
@ -708,7 +715,7 @@ def test_readme_int_verbosity_short_and_not(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['int', '--int', '3', '-v', '-nv'])
|
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):
|
def test_readme_str(json):
|
||||||
|
|
@ -719,7 +726,7 @@ def test_readme_str(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['str', '--str', 'value'])
|
parser.parse_args(['str', '--str', 'value'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
|
|
||||||
|
|
||||||
def test_readme_str_tree(json):
|
def test_readme_str_tree(json):
|
||||||
|
|
@ -730,7 +737,7 @@ def test_readme_str_tree(json):
|
||||||
config = get_config(json, True)
|
config = get_config(json, True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['str', '--root.str', 'value'])
|
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):
|
def test_readme_str_tree_flatten(json):
|
||||||
|
|
@ -741,7 +748,7 @@ def test_readme_str_tree_flatten(json):
|
||||||
config = get_config(json, True)
|
config = get_config(json, True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||||
parser.parse_args(['str', '--str', 'value'])
|
parser.parse_args(['str', '--str', 'value'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
|
|
||||||
|
|
||||||
def test_readme_str_int(json):
|
def test_readme_str_int(json):
|
||||||
|
|
@ -752,7 +759,7 @@ def test_readme_str_int(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['str', '--str', '3'])
|
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):
|
def test_readme_str_int_tree(json):
|
||||||
|
|
@ -763,7 +770,7 @@ def test_readme_str_int_tree(json):
|
||||||
config = get_config(json, True)
|
config = get_config(json, True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['str', '--root.str', '3'])
|
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):
|
def test_readme_str_int_tree_flatten(json):
|
||||||
|
|
@ -774,7 +781,7 @@ def test_readme_str_int_tree_flatten(json):
|
||||||
config = get_config(json, True)
|
config = get_config(json, True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||||
parser.parse_args(['str', '--str', '3'])
|
parser.parse_args(['str', '--str', '3'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
|
|
||||||
|
|
||||||
def test_readme_list_single(json):
|
def test_readme_list_single(json):
|
||||||
|
|
@ -785,7 +792,7 @@ def test_readme_list_single(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['list', '--list', 'a'])
|
parser.parse_args(['list', '--list', 'a'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
|
|
||||||
|
|
||||||
def test_readme_list(json):
|
def test_readme_list(json):
|
||||||
|
|
@ -796,7 +803,7 @@ def test_readme_list(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['list', '--list', 'a', 'b', 'c'])
|
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):
|
def test_readme_list_tree(json):
|
||||||
|
|
@ -807,7 +814,7 @@ def test_readme_list_tree(json):
|
||||||
config = get_config(json, True)
|
config = get_config(json, True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['list', '--root.list', 'a', 'b', 'c'])
|
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):
|
def test_readme_list_tree_flatten(json):
|
||||||
|
|
@ -818,7 +825,7 @@ def test_readme_list_tree_flatten(json):
|
||||||
config = get_config(json, True)
|
config = get_config(json, True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||||
parser.parse_args(['list', '--list', 'a', 'b', 'c'])
|
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):
|
def test_readme_list_uniq(json):
|
||||||
|
|
@ -829,7 +836,7 @@ def test_readme_list_uniq(json):
|
||||||
config = get_config(json)
|
config = get_config(json)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['list', '--list', 'a'])
|
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):
|
def test_readme_list_uniq_tree(json):
|
||||||
|
|
@ -840,7 +847,7 @@ def test_readme_list_uniq_tree(json):
|
||||||
config = get_config(json, True)
|
config = get_config(json, True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['list', '--root.list', 'a'])
|
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):
|
def test_readme_list_uniq_tree_flatten(json):
|
||||||
|
|
@ -851,7 +858,7 @@ def test_readme_list_uniq_tree_flatten(json):
|
||||||
config = get_config(json, True)
|
config = get_config(json, True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
parser = TiramisuCmdlineParser(config, 'prog.py', fullpath=False)
|
||||||
parser.parse_args(['list', '--list', 'a'])
|
parser.parse_args(['list', '--list', 'a'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
|
|
||||||
|
|
||||||
def test_readme_longargument(json):
|
def test_readme_longargument(json):
|
||||||
|
|
@ -862,7 +869,7 @@ def test_readme_longargument(json):
|
||||||
config = get_config(json, add_long=True)
|
config = get_config(json, add_long=True)
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['list', '--list', 'a', '--v'])
|
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):
|
def test_readme_unknown_key(json):
|
||||||
|
|
@ -872,7 +879,7 @@ prog.py: error: unrecognized arguments: --unknown
|
||||||
output2 = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
output2 = """usage: prog.py [-h] [-v] [-nv] {str,list,int,none}
|
||||||
prog.py: error: unrecognized arguments: --root.unknown
|
prog.py: error: unrecognized arguments: --root.unknown
|
||||||
"""
|
"""
|
||||||
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()
|
f = StringIO()
|
||||||
with redirect_stderr(f):
|
with redirect_stderr(f):
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,13 @@ from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
|
||||||
SymLinkOption, OptionDescription, Config
|
SymLinkOption, OptionDescription, Config
|
||||||
try:
|
try:
|
||||||
from tiramisu_api import Config as JsonConfig
|
from tiramisu_api import Config as JsonConfig
|
||||||
params = ['tiramisu', 'tiramisu-json']
|
params = ['tiramisu']
|
||||||
|
#params = ['tiramisu', 'tiramisu-json']
|
||||||
except:
|
except:
|
||||||
params = ['tiramisu']
|
params = ['tiramisu']
|
||||||
|
|
||||||
|
from .utils import to_dict
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=params)
|
@pytest.fixture(params=params)
|
||||||
def json(request):
|
def json(request):
|
||||||
|
|
@ -38,19 +41,19 @@ def test_short(json):
|
||||||
config = get_config()
|
config = get_config()
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args([])
|
parser.parse_args([])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
#
|
#
|
||||||
output = {'list': 'a', 'l': 'a'}
|
output = {'list': 'a', 'l': 'a'}
|
||||||
config = get_config()
|
config = get_config()
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['--list', 'a'])
|
parser.parse_args(['--list', 'a'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
#
|
#
|
||||||
output = {'list': 'a', 'l': 'a'}
|
output = {'list': 'a', 'l': 'a'}
|
||||||
config = get_config()
|
config = get_config()
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['-l', 'a'])
|
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').value.get() == config.option('l').value.get()
|
||||||
assert config.option('list').owner.get() == config.option('l').owner.get()
|
assert config.option('list').owner.get() == config.option('l').owner.get()
|
||||||
|
|
@ -93,13 +96,13 @@ prog.py: error: the following arguments are required: --list
|
||||||
config = get_config()
|
config = get_config()
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['--list', 'a'])
|
parser.parse_args(['--list', 'a'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
#
|
#
|
||||||
output = {'list': 'a', 'l': 'a'}
|
output = {'list': 'a', 'l': 'a'}
|
||||||
config = get_config()
|
config = get_config()
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['-l', 'a'])
|
parser.parse_args(['-l', 'a'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
|
|
||||||
|
|
||||||
def test_short_multi(json):
|
def test_short_multi(json):
|
||||||
|
|
@ -123,31 +126,31 @@ def test_short_multi(json):
|
||||||
config = get_config()
|
config = get_config()
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args([])
|
parser.parse_args([])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
#
|
#
|
||||||
output = {'list': ['a'], 'l': ['a']}
|
output = {'list': ['a'], 'l': ['a']}
|
||||||
config = get_config()
|
config = get_config()
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['--list', 'a'])
|
parser.parse_args(['--list', 'a'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
#
|
#
|
||||||
output = {'list': ['a', 'b'], 'l': ['a', 'b']}
|
output = {'list': ['a', 'b'], 'l': ['a', 'b']}
|
||||||
config = get_config()
|
config = get_config()
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['--list', 'a', 'b'])
|
parser.parse_args(['--list', 'a', 'b'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
#
|
#
|
||||||
output = {'list': ['a'], 'l': ['a']}
|
output = {'list': ['a'], 'l': ['a']}
|
||||||
config = get_config()
|
config = get_config()
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['-l', 'a'])
|
parser.parse_args(['-l', 'a'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
#
|
#
|
||||||
output = {'list': ['a', 'b'], 'l': ['a', 'b']}
|
output = {'list': ['a', 'b'], 'l': ['a', 'b']}
|
||||||
config = get_config()
|
config = get_config()
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['-l', 'a', 'b'])
|
parser.parse_args(['-l', 'a', 'b'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
|
|
||||||
|
|
||||||
def test_short_multi_mandatory(json):
|
def test_short_multi_mandatory(json):
|
||||||
|
|
@ -187,22 +190,22 @@ prog.py: error: the following arguments are required: --list
|
||||||
config = get_config()
|
config = get_config()
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['--list', 'a'])
|
parser.parse_args(['--list', 'a'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
#
|
#
|
||||||
output = {'list': ['a', 'b'], 'l': ['a', 'b']}
|
output = {'list': ['a', 'b'], 'l': ['a', 'b']}
|
||||||
config = get_config()
|
config = get_config()
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['--list', 'a', 'b'])
|
parser.parse_args(['--list', 'a', 'b'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
#
|
#
|
||||||
output = {'list': ['a'], 'l': ['a']}
|
output = {'list': ['a'], 'l': ['a']}
|
||||||
config = get_config()
|
config = get_config()
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['-l', 'a'])
|
parser.parse_args(['-l', 'a'])
|
||||||
assert config.value.dict() == output
|
assert to_dict(config.value.get()) == output
|
||||||
#
|
#
|
||||||
output = {'list': ['a', 'b'], 'l': ['a', 'b']}
|
output = {'list': ['a', 'b'], 'l': ['a', 'b']}
|
||||||
config = get_config()
|
config = get_config()
|
||||||
parser = TiramisuCmdlineParser(config, 'prog.py')
|
parser = TiramisuCmdlineParser(config, 'prog.py')
|
||||||
parser.parse_args(['-l', 'a', 'b'])
|
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 ArgumentDefaultsHelpFormatter
|
||||||
|
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, ArgumentDefaultsHelpFormatter):
|
||||||
|
def __init__(self,
|
||||||
|
*args,
|
||||||
|
**kwargs,
|
||||||
|
):
|
||||||
|
return super().__init__(*args, **kwargs, width=5000)
|
||||||
|
|
@ -1,9 +1,26 @@
|
||||||
|
# Copyright (C) 2018-2019 Team tiramisu (see AUTHORS for all contributors)
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
# Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
# option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||||
|
# details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
from typing import Union, List, Dict, Tuple, Optional, Any
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from .api import TiramisuCmdlineParser
|
from .api import TiramisuCmdlineParser
|
||||||
except ImportError as err:
|
except ImportError as err:
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
warnings.warn("cannot not import TiramisuCmdlineParser {err}", ImportWarning)
|
warnings.warn("cannot not import TiramisuCmdlineParser {err}", ImportWarning)
|
||||||
TiramisuCmdlineParser = None
|
TiramisuCmdlineParser = None
|
||||||
|
|
||||||
__version__ = "0.5"
|
__version__ = "0.5"
|
||||||
__all__ = ('TiramisuCmdlineParser',)
|
__all__ = ("TiramisuCmdlineParser",)
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue