2025-05-14 08:27:11 +02:00
|
|
|
import os
|
2025-04-29 22:54:52 +02:00
|
|
|
from pathlib import Path
|
2025-05-12 19:23:27 +02:00
|
|
|
from contextlib import chdir
|
|
|
|
|
from json import dumps, loads
|
2025-04-29 22:54:52 +02:00
|
|
|
|
|
|
|
|
from rougail.cli.__main__ import main
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test_dir = Path(__file__).parent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_cli():
|
2025-05-12 19:23:27 +02:00
|
|
|
with 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)
|
2025-04-29 22:54:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_cli_boolean():
|
2025-05-12 19:23:27 +02:00
|
|
|
with 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_no():
|
|
|
|
|
with 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_cli_version():
|
|
|
|
|
with chdir(test_dir / 'cli'):
|
|
|
|
|
ret = main(['--cli.version'], do_not_print=True)
|
|
|
|
|
filename = Path('versions.txt')
|
|
|
|
|
if not filename.is_file():
|
|
|
|
|
with filename.open('w') as fh:
|
|
|
|
|
fh.write(dumps(ret))
|
|
|
|
|
with filename.open() as fh:
|
|
|
|
|
data = loads(fh.read())
|
|
|
|
|
assert ret == data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_cli_version_user_data_disabled():
|
|
|
|
|
with chdir(test_dir / 'cli'):
|
|
|
|
|
ret = main(['--cli.version', '--step.output', 'doc'], do_not_print=True)
|
|
|
|
|
filename = Path('versions.txt')
|
|
|
|
|
if not filename.is_file():
|
|
|
|
|
with filename.open('w') as fh:
|
|
|
|
|
fh.write(dumps(ret))
|
|
|
|
|
with filename.open() as fh:
|
|
|
|
|
data = loads(fh.read())
|
|
|
|
|
assert ret == data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_cli_version_user_data_disabled():
|
|
|
|
|
with chdir(test_dir / 'second_step'):
|
|
|
|
|
ret = main(['--main_dictionaries', 'structures', '--step.output', 'doc'], do_not_print=True)
|
|
|
|
|
filename = Path('yaml.txt')
|
|
|
|
|
if not filename.is_file():
|
|
|
|
|
with filename.open('w') as fh:
|
|
|
|
|
fh.write(dumps(ret[1]))
|
|
|
|
|
with filename.open() as fh:
|
|
|
|
|
data = loads(fh.read())
|
|
|
|
|
assert ret == (True, data)
|
2025-05-14 08:27:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_cli_rougailcli():
|
|
|
|
|
with chdir(test_dir / 'rougailcli_file'):
|
|
|
|
|
ret = main([], do_not_print=True)
|
|
|
|
|
filename = Path('yaml.txt')
|
|
|
|
|
if not filename.is_file():
|
|
|
|
|
with filename.open('w') as fh:
|
|
|
|
|
fh.write(dumps(ret[1]))
|
|
|
|
|
with filename.open() as fh:
|
|
|
|
|
data = loads(fh.read())
|
|
|
|
|
assert ret == (True, data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_cli_alt_rougailcli():
|
|
|
|
|
with chdir(test_dir / 'rougailcli_file'):
|
|
|
|
|
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'alt_rougailcli.yml'
|
|
|
|
|
ret = main([], do_not_print=True)
|
|
|
|
|
filename = Path('console.txt')
|
|
|
|
|
if not filename.is_file():
|
|
|
|
|
with filename.open('w') as fh:
|
|
|
|
|
fh.write(dumps(ret[1]))
|
|
|
|
|
with filename.open() as fh:
|
|
|
|
|
data = loads(fh.read())
|
|
|
|
|
assert ret == (True, data)
|