241 lines
9 KiB
Python
241 lines
9 KiB
Python
import os
|
|
import warnings
|
|
from pathlib import Path
|
|
from contextlib import chdir
|
|
from json import dumps, loads
|
|
|
|
from rougail.cli.__main__ import main
|
|
|
|
|
|
test_dir = Path(__file__).parent
|
|
os.environ['COLUMNS'] = '80'
|
|
|
|
|
|
def test_cli():
|
|
with chdir(test_dir / 'cli'):
|
|
ret = main(['--main_structural_directories', '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), str(filename.absolute())
|
|
|
|
|
|
def test_cli_boolean():
|
|
with chdir(test_dir / 'cli'):
|
|
ret = main(['--main_structural_directories', '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), str(filename.absolute())
|
|
|
|
|
|
def test_cli_boolean_no():
|
|
with chdir(test_dir / 'cli'):
|
|
ret = main(['--main_structural_directories', '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), str(filename.absolute())
|
|
|
|
|
|
def test_cli_version():
|
|
with chdir(test_dir / 'cli'):
|
|
ret = main(['--cli.version'], do_not_print=True)
|
|
ret = [r.rsplit(': ', 1)[0] for r in ret]
|
|
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, str(filename.absolute())
|
|
|
|
|
|
def test_cli_version_user_data_disabled():
|
|
with chdir(test_dir / 'cli'):
|
|
ret = main(['--cli.version', '--step.output', 'doc'], do_not_print=True)
|
|
ret = [r.rsplit(': ', 1)[0] for r in ret]
|
|
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, str(filename.absolute())
|
|
|
|
|
|
def test_cli_version_user_data_disabled_2():
|
|
with chdir(test_dir / 'second_step'):
|
|
ret = main(['--main_structural_directories', '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), str(filename.absolute())
|
|
|
|
|
|
def test_cli_user_data():
|
|
with chdir(test_dir / 'cli'):
|
|
ret = main(['--main_structural_directories', 'structures', '--step.user_data', 'yaml', '--yaml.filename', 'yaml/file.yml'], do_not_print=True)
|
|
filename = Path('result_user_data.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), str(filename.absolute())
|
|
|
|
|
|
def test_cli_user_datas():
|
|
save = os.environ.copy()
|
|
os.environ["MY_VARIABLE"] = "my env value"
|
|
with chdir(test_dir / 'cli'):
|
|
ret = main(['--main_structural_directories', 'structures', '--step.user_data', 'environment', 'yaml', '--yaml.filename', 'yaml/file.yml'], do_not_print=True)
|
|
filename = Path('result_user_datas.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), str(filename.absolute())
|
|
save = os.environ.copy()
|
|
|
|
|
|
def test_cli_user_datas_user_datas_layers():
|
|
save = os.environ.copy()
|
|
os.environ["ROUGAIL_MY_VARIABLE"] = "my env value"
|
|
with chdir(test_dir / 'cli'):
|
|
ret = main(['--main_structural_directories', 'structures', '--cli.layers', '--step.user_data', 'environment', 'yaml', '--yaml.filename', 'yaml/file.yml'], do_not_print=True)
|
|
filename = Path('result_user_datas_layers.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), str(filename.absolute())
|
|
save = os.environ.copy()
|
|
|
|
|
|
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), str(filename.absolute())
|
|
|
|
|
|
def test_cli_alt_rougailcli():
|
|
save = os.environ.copy()
|
|
with chdir(test_dir / 'rougailcli_file'):
|
|
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'alt_rougailcli.yml'
|
|
ret = main([], do_not_print=True)
|
|
filename = Path('alt_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), str(filename.absolute())
|
|
os.environ = save
|
|
|
|
|
|
def test_cli_rougailcli_mix():
|
|
save = os.environ.copy()
|
|
with chdir(test_dir / 'rougailcli_file'):
|
|
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'mix_rougailcli.yml'
|
|
ret = main(["-o", "doc", "--doc.output_format", "asciidoc"], do_not_print=True)
|
|
filename = Path('mix_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), str(filename.absolute())
|
|
os.environ = save
|
|
|
|
|
|
def test_cli_rougailcli_warning():
|
|
save = os.environ.copy()
|
|
with chdir(test_dir / 'rougailcli_file'):
|
|
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings.yml'
|
|
with warnings.catch_warnings(record=True) as rougail_wn:
|
|
warnings.simplefilter("always", UserWarning)
|
|
main(["-o", "doc", "--doc.output_format", "asciidoc"], do_not_print=True)
|
|
ret = [str(w.message) for w in rougail_wn]
|
|
filename = Path('warnings.txt')
|
|
if not filename.is_file():
|
|
with filename.open('w') as fh:
|
|
fh.write(dumps([str(w.message) for w in rougail_wn]))
|
|
with filename.open() as fh:
|
|
data = loads(fh.read())
|
|
assert ret == data, str(filename.absolute())
|
|
os.environ = save
|
|
|
|
|
|
def test_cli_rougailcli_not_warning():
|
|
save = os.environ.copy()
|
|
with chdir(test_dir / 'rougailcli_file'):
|
|
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings2.yml'
|
|
with warnings.catch_warnings(record=True) as rougail_wn:
|
|
warnings.simplefilter("always", UserWarning)
|
|
main(["-o", "doc", "--doc.output_format", "asciidoc"], do_not_print=True)
|
|
filename = Path('warnings2.txt')
|
|
ret = [str(w.message) for w in rougail_wn]
|
|
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, str(filename.absolute())
|
|
os.environ = save
|
|
|
|
|
|
def test_cli_rougailcli_warning2():
|
|
save = os.environ.copy()
|
|
with chdir(test_dir / 'rougailcli_file'):
|
|
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings3.yml'
|
|
with warnings.catch_warnings(record=True) as rougail_wn:
|
|
warnings.simplefilter("always", UserWarning)
|
|
main(["-o", "doc", "--doc.output_format", "asciidoc"], do_not_print=True)
|
|
ret = [str(w.message) for w in rougail_wn]
|
|
filename = Path('warnings3.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, str(filename.absolute())
|
|
os.environ = save
|
|
|
|
|
|
def test_cli_rougailcli_not_warning2():
|
|
save = os.environ.copy()
|
|
with chdir(test_dir / 'rougailcli_file'):
|
|
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings4.yml'
|
|
with warnings.catch_warnings(record=True) as rougail_wn:
|
|
warnings.simplefilter("always", UserWarning)
|
|
main(["-o", "doc", "--doc.output_format", "asciidoc"], do_not_print=True)
|
|
filename = Path('warnings4.txt')
|
|
ret = [str(w.message) for w in rougail_wn]
|
|
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, str(filename.absolute())
|
|
os.environ = save
|