fix: add first test + remove add_extra_options option in tiramisu-cmdline-parser
This commit is contained in:
parent
05fcb14364
commit
0102eede49
4 changed files with 62 additions and 7 deletions
|
|
@ -37,7 +37,7 @@ except ImportError:
|
|||
from .i18n import _
|
||||
|
||||
|
||||
def _main():
|
||||
def _main(arguments, do_not_print):
|
||||
rougailconfig = get_rougail_config(
|
||||
backward_compatibility=False, add_extra_options=False
|
||||
)
|
||||
|
|
@ -69,10 +69,10 @@ def _main():
|
|||
raise Exception(user_data["warnings"][0])
|
||||
parser = TiramisuCmdlineParser(
|
||||
cmd_config,
|
||||
add_extra_options=False,
|
||||
# add_extra_options=False,
|
||||
short_name_max_len=2,
|
||||
)
|
||||
parser.parse_args()
|
||||
parser.parse_args(arguments)
|
||||
global print_traceback
|
||||
print_traceback = rougailconfig["cli.debug"]
|
||||
cmd_config.property.setdefault(origin_prop, 'read_write', 'append')
|
||||
|
|
@ -163,21 +163,24 @@ def _main():
|
|||
_('cannot find cli file for "output_name" module "{0}"').format(output_name)
|
||||
)
|
||||
module = load_modules("rougail.output_" + output_name, str(path))
|
||||
ret = module.RougailOutput(
|
||||
output = module.RougailOutput(
|
||||
config=config,
|
||||
rougailconfig=rougailconfig,
|
||||
user_data_errors=err_warn["errors"],
|
||||
user_data_warnings=err_warn["warnings"],
|
||||
).print()
|
||||
)
|
||||
if do_not_print:
|
||||
return output.run()
|
||||
ret = output.print()
|
||||
if ret is False:
|
||||
exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
def main(arguments=None, do_not_print=False):
|
||||
global print_traceback
|
||||
print_traceback = True
|
||||
try:
|
||||
_main()
|
||||
return _main(arguments, do_not_print)
|
||||
except Exception as err:
|
||||
if print_traceback:
|
||||
import traceback
|
||||
|
|
|
|||
5
tests/cli/result.txt
Normal file
5
tests/cli/result.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
╭─────── Caption ────────╮
|
||||
│ Variable [38;5;220mDefault value[0m │
|
||||
╰────────────────────────╯
|
||||
Variables:
|
||||
[94m┗━━ [0m📓 my_variable: [38;5;220mmy_value[0m
|
||||
4
tests/cli/structures/file.yml
Normal file
4
tests/cli/structures/file.yml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
version: 1.1
|
||||
|
||||
my_variable: my_value
|
||||
43
tests/test_load.py
Normal file
43
tests/test_load.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
from pathlib import Path
|
||||
from os import chdir
|
||||
|
||||
from rougail.cli.__main__ import main
|
||||
|
||||
|
||||
test_dir = Path(__file__).parent
|
||||
|
||||
|
||||
def test_cli():
|
||||
chdir(test_dir / 'cli')
|
||||
ret = main(['--main_dictionaries', 'structures'], do_not_print=True)
|
||||
filename = Path('result.txt')
|
||||
if not filename.is_file():
|
||||
with filename.open('w') as fh:
|
||||
fh.write(ret[1])
|
||||
with filename.open() as fh:
|
||||
data = fh.read()
|
||||
assert ret == (True, data)
|
||||
|
||||
|
||||
def test_cli_boolean():
|
||||
chdir(test_dir / 'cli')
|
||||
ret = main(['--main_dictionaries', 'structures', '--console.mandatory'], do_not_print=True)
|
||||
filename = Path('result.txt')
|
||||
if not filename.is_file():
|
||||
with filename.open('w') as fh:
|
||||
fh.write(ret[1])
|
||||
with filename.open() as fh:
|
||||
data = fh.read()
|
||||
assert ret == (True, data)
|
||||
|
||||
|
||||
def test_cli_boolean_2():
|
||||
chdir(test_dir / 'cli')
|
||||
ret = main(['--main_dictionaries', 'structures', '--console.no-mandatory'], do_not_print=True)
|
||||
filename = Path('result.txt')
|
||||
if not filename.is_file():
|
||||
with filename.open('w') as fh:
|
||||
fh.write(ret[1])
|
||||
with filename.open() as fh:
|
||||
data = fh.read()
|
||||
assert ret == (True, data)
|
||||
Loading…
Reference in a new issue