feat: support layers
This commit is contained in:
parent
fe96019173
commit
ba0b326b56
9 changed files with 157 additions and 44 deletions
|
|
@ -24,9 +24,10 @@ from warnings import warn
|
||||||
|
|
||||||
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||||
from tiramisu.error import PropertiesOptionError
|
from tiramisu.error import PropertiesOptionError
|
||||||
from tiramisu import Config
|
from tiramisu import MetaConfig
|
||||||
|
|
||||||
from rougail import Rougail
|
from rougail import Rougail
|
||||||
|
from rougail.user_datas import UserDatas
|
||||||
from rougail.config import get_rougail_config
|
from rougail.config import get_rougail_config
|
||||||
from rougail.utils import load_modules
|
from rougail.utils import load_modules
|
||||||
from rougail.error import RougailWarning
|
from rougail.error import RougailWarning
|
||||||
|
|
@ -61,8 +62,8 @@ def _main(arguments, do_not_print):
|
||||||
for version in versions:
|
for version in versions:
|
||||||
print(version)
|
print(version)
|
||||||
exit()
|
exit()
|
||||||
config, err_warn = load_user_datas(rougailconfig)
|
metaconfig, config, err_warn = load_user_datas(rougailconfig)
|
||||||
output = get_output(rougailconfig, config, err_warn)
|
output = get_output(rougailconfig, metaconfig, config, err_warn)
|
||||||
if do_not_print:
|
if do_not_print:
|
||||||
return output.run()
|
return output.run()
|
||||||
ret = output.print()
|
ret = output.print()
|
||||||
|
|
@ -155,45 +156,68 @@ def manage_warnings(warnings):
|
||||||
filterwarnings("default", category=DeprecationWarning)
|
filterwarnings("default", category=DeprecationWarning)
|
||||||
filterwarnings("default", category=RougailWarning)
|
filterwarnings("default", category=RougailWarning)
|
||||||
|
|
||||||
|
|
||||||
def load_user_datas(rougailconfig):
|
def load_user_datas(rougailconfig):
|
||||||
|
if not rougailconfig["cli.load_config"]:
|
||||||
|
return None, {"errors": [], "warnings": []}
|
||||||
try:
|
try:
|
||||||
user_data_names = rougailconfig["step.user_data"]
|
user_data_names = rougailconfig["step.user_data"]
|
||||||
except PropertiesOptionError:
|
except PropertiesOptionError:
|
||||||
user_data_names = []
|
user_data_names = []
|
||||||
# structural
|
if rougailconfig["cli.layers"]:
|
||||||
if rougailconfig["cli.load_config"]:
|
layers = [[ud] for ud in user_data_names]
|
||||||
rougail = Rougail(rougailconfig)
|
last_layers = len(layers) - 1
|
||||||
config = rougail.run()
|
|
||||||
config.property.read_write()
|
|
||||||
else:
|
else:
|
||||||
config = None
|
layers = [user_data_names]
|
||||||
# data user
|
last_layers = 0
|
||||||
user_datas = []
|
rougail = Rougail(rougailconfig)
|
||||||
for user_data_name in user_data_names:
|
layer_name = "_".join(layers[-1])
|
||||||
path = (
|
config = rougail.run(name=layer_name)
|
||||||
Path(__file__).parent.parent
|
metaconfig = config
|
||||||
/ ("user_data_" + user_data_name)
|
if last_layers:
|
||||||
/ "__init__.py"
|
for layer in layers[:-1]:
|
||||||
)
|
layer_name = "_".join(layer)
|
||||||
if not path.is_file():
|
metaconfig = MetaConfig([metaconfig], name=layer_name)
|
||||||
raise Exception(
|
metaconfig.owner.set(metaconfig.path())
|
||||||
_('cannot find "user_data" module "{0}"').format(user_data_name)
|
subconfig = metaconfig
|
||||||
|
err_warn = {"errors": [], "warnings": []}
|
||||||
|
for idx, layer in enumerate(layers):
|
||||||
|
if idx:
|
||||||
|
subconfig = subconfig.config("_".join(layer))
|
||||||
|
config.owner.set(subconfig.path())
|
||||||
|
subconfig.property.read_write()
|
||||||
|
# data user
|
||||||
|
user_datas = []
|
||||||
|
for user_data_name in layer:
|
||||||
|
path = (
|
||||||
|
Path(__file__).parent.parent
|
||||||
|
/ ("user_data_" + user_data_name)
|
||||||
|
/ "__init__.py"
|
||||||
)
|
)
|
||||||
module = load_modules("rougail.user_data_" + user_data_name, str(path))
|
if not path.is_file():
|
||||||
user_datas.extend(
|
raise Exception(
|
||||||
module.RougailUserData(
|
_('cannot find "user_data" module "{0}"').format(user_data_name)
|
||||||
config,
|
)
|
||||||
rougailconfig=rougailconfig,
|
module = load_modules("rougail.user_data_" + user_data_name, str(path))
|
||||||
).run()
|
user_datas.extend(
|
||||||
)
|
module.RougailUserData(
|
||||||
if user_datas:
|
subconfig,
|
||||||
err_warn = rougail.user_datas(user_datas)
|
rougailconfig=rougailconfig,
|
||||||
else:
|
).run()
|
||||||
err_warn = {"errors": [], "warnings": []}
|
)
|
||||||
return config, err_warn
|
if user_datas:
|
||||||
|
new_err_warn = UserDatas(subconfig).user_datas(user_datas)
|
||||||
|
for level, datas in new_err_warn.items():
|
||||||
|
if datas:
|
||||||
|
err_warn[level].updates(datas)
|
||||||
|
subconfig = metaconfig
|
||||||
|
for idx, layer in enumerate(layers):
|
||||||
|
if idx:
|
||||||
|
subconfig = subconfig.config("_".join(layer))
|
||||||
|
return metaconfig, config, err_warn
|
||||||
|
|
||||||
|
|
||||||
def get_output(rougailconfig, config, err_warn):
|
def get_output(rougailconfig, metaconfig, config, err_warn):
|
||||||
# output
|
# output
|
||||||
if config and (not rougailconfig["cli.load_config"] or not rougailconfig["cli.read_write"]):
|
if config and (not rougailconfig["cli.load_config"] or not rougailconfig["cli.read_write"]):
|
||||||
config.property.read_only()
|
config.property.read_only()
|
||||||
|
|
@ -209,6 +233,8 @@ def get_output(rougailconfig, config, err_warn):
|
||||||
rougailconfig=rougailconfig,
|
rougailconfig=rougailconfig,
|
||||||
user_data_errors=err_warn["errors"],
|
user_data_errors=err_warn["errors"],
|
||||||
user_data_warnings=err_warn["warnings"],
|
user_data_warnings=err_warn["warnings"],
|
||||||
|
config_owner_is_path=True,
|
||||||
|
metaconfig=metaconfig,
|
||||||
)
|
)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,14 @@ cli:
|
||||||
|
|
||||||
versions: false # {_('Displays Rougail version and all its components')}
|
versions: false # {_('Displays Rougail version and all its components')}
|
||||||
|
|
||||||
|
layers:
|
||||||
|
description: {_('Open each user datas in separate layers')}
|
||||||
|
default: false
|
||||||
|
hidden:
|
||||||
|
jinja: |-
|
||||||
|
{{{{ __.step.user_data is propertyerror or __.step.user_data | length < 2 }}}}
|
||||||
|
return_type: boolean
|
||||||
|
|
||||||
load_config:
|
load_config:
|
||||||
default: true
|
default: true
|
||||||
hidden: true
|
hidden: true
|
||||||
|
|
|
||||||
7
tests/cli/result_user_data.txt
Normal file
7
tests/cli/result_user_data.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
╭────────────── Caption ───────────────╮
|
||||||
|
│ Variable Modified value │
|
||||||
|
│ ([32m⏳ Original default value[0m) │
|
||||||
|
╰──────────────────────────────────────╯
|
||||||
|
Variables:
|
||||||
|
[94m┗━━ [0m📓 a description: a yaml value ◀ loaded from the YAML file "yaml/file.yml"
|
||||||
|
[94m [0m(⏳ [32mmy_value[0m)
|
||||||
7
tests/cli/result_user_datas.txt
Normal file
7
tests/cli/result_user_datas.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
╭────────────── Caption ───────────────╮
|
||||||
|
│ Variable Modified value │
|
||||||
|
│ ([32m⏳ Original default value[0m) │
|
||||||
|
╰──────────────────────────────────────╯
|
||||||
|
Variables:
|
||||||
|
[94m┗━━ [0m📓 a description: a yaml value ◀ loaded from the YAML file "yaml/file.yml"
|
||||||
|
[94m [0m(⏳ [32mmy_value[0m)
|
||||||
7
tests/cli/result_user_datas_layers.txt
Normal file
7
tests/cli/result_user_datas_layers.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
╭────────────── Caption ───────────────╮
|
||||||
|
│ Variable Modified value │
|
||||||
|
│ ([32m⏳ Original default value[0m) │
|
||||||
|
╰──────────────────────────────────────╯
|
||||||
|
Variables:
|
||||||
|
[94m┗━━ [0m📓 a description: a yaml value ◀ loaded from the YAML file "yaml/file.yml"
|
||||||
|
[94m [0m(⏳ [32mmy env value[0m ◀ loaded from environment variable ⏳ [32mmy env value[0m)
|
||||||
2
tests/cli/yaml/file.yml
Normal file
2
tests/cli/yaml/file.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
my_variable: a yaml value
|
||||||
|
|
@ -1 +1 @@
|
||||||
"\u250f\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n\u2503\u001b[1m \u001b[0m\u001b[1mVariable \u001b[0m\u001b[1m \u001b[0m\u2503\u001b[1m \u001b[0m\u001b[1mDescription \u001b[0m\u001b[1m \u001b[0m\u2503\n\u2521\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2529\n\u2502 \u001b[1mmy_variable\u001b[0m \u2502 A description. \u2502\n\u2502 \u001b[1;7m string \u001b[0m \u001b[1;7m mandatory \u001b[0m \u2502 \u001b[1mDefault\u001b[0m: my_value \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n"
|
"\u250f\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n\u2503\u001b[1m \u001b[0m\u001b[1mVariable \u001b[0m\u001b[1m \u001b[0m\u2503\u001b[1m \u001b[0m\u001b[1mDescription \u001b[0m\u001b[1m \u001b[0m\u2503\n\u2521\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2529\n\u2502 \u001b[1mmy_variable\u001b[0m \u2502 A description. \u2502\n\u2502 \u001b[1;7m string \u001b[0m \u001b[1;7m mandatory \u001b[0m \u2502 \u001b[1mDefault\u001b[0m: my_value \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n"
|
||||||
|
|
@ -6,3 +6,4 @@ my_variable:
|
||||||
validators: # validators in jinja without description makes warnings
|
validators: # validators in jinja without description makes warnings
|
||||||
- jinja: |-
|
- jinja: |-
|
||||||
{{ _.my_variable != "my_value" }}
|
{{ _.my_variable != "my_value" }}
|
||||||
|
warnings: true
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ from rougail.cli.__main__ import main
|
||||||
|
|
||||||
|
|
||||||
test_dir = Path(__file__).parent
|
test_dir = Path(__file__).parent
|
||||||
|
os.environ['COLUMNS'] = '80'
|
||||||
|
|
||||||
|
|
||||||
def test_cli():
|
def test_cli():
|
||||||
|
|
@ -19,7 +20,7 @@ def test_cli():
|
||||||
fh.write(ret[1])
|
fh.write(ret[1])
|
||||||
with filename.open() as fh:
|
with filename.open() as fh:
|
||||||
data = fh.read()
|
data = fh.read()
|
||||||
assert ret == (True, data)
|
assert ret == (True, data), str(filename.absolute())
|
||||||
|
|
||||||
|
|
||||||
def test_cli_boolean():
|
def test_cli_boolean():
|
||||||
|
|
@ -31,7 +32,7 @@ def test_cli_boolean():
|
||||||
fh.write(ret[1])
|
fh.write(ret[1])
|
||||||
with filename.open() as fh:
|
with filename.open() as fh:
|
||||||
data = fh.read()
|
data = fh.read()
|
||||||
assert ret == (True, data)
|
assert ret == (True, data), str(filename.absolute())
|
||||||
|
|
||||||
|
|
||||||
def test_cli_boolean_no():
|
def test_cli_boolean_no():
|
||||||
|
|
@ -43,7 +44,7 @@ def test_cli_boolean_no():
|
||||||
fh.write(ret[1])
|
fh.write(ret[1])
|
||||||
with filename.open() as fh:
|
with filename.open() as fh:
|
||||||
data = fh.read()
|
data = fh.read()
|
||||||
assert ret == (True, data)
|
assert ret == (True, data), str(filename.absolute())
|
||||||
|
|
||||||
|
|
||||||
def test_cli_version():
|
def test_cli_version():
|
||||||
|
|
@ -56,7 +57,7 @@ def test_cli_version():
|
||||||
fh.write(dumps(ret))
|
fh.write(dumps(ret))
|
||||||
with filename.open() as fh:
|
with filename.open() as fh:
|
||||||
data = loads(fh.read())
|
data = loads(fh.read())
|
||||||
assert ret == data
|
assert ret == data, str(filename.absolute())
|
||||||
|
|
||||||
|
|
||||||
def test_cli_version_user_data_disabled():
|
def test_cli_version_user_data_disabled():
|
||||||
|
|
@ -69,7 +70,7 @@ def test_cli_version_user_data_disabled():
|
||||||
fh.write(dumps(ret))
|
fh.write(dumps(ret))
|
||||||
with filename.open() as fh:
|
with filename.open() as fh:
|
||||||
data = loads(fh.read())
|
data = loads(fh.read())
|
||||||
assert ret == data
|
assert ret == data, str(filename.absolute())
|
||||||
|
|
||||||
|
|
||||||
def test_cli_version_user_data_disabled_2():
|
def test_cli_version_user_data_disabled_2():
|
||||||
|
|
@ -81,7 +82,49 @@ def test_cli_version_user_data_disabled_2():
|
||||||
fh.write(dumps(ret[1]))
|
fh.write(dumps(ret[1]))
|
||||||
with filename.open() as fh:
|
with filename.open() as fh:
|
||||||
data = loads(fh.read())
|
data = loads(fh.read())
|
||||||
assert ret == (True, data), filename
|
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():
|
def test_cli_rougailcli():
|
||||||
|
|
@ -93,10 +136,11 @@ def test_cli_rougailcli():
|
||||||
fh.write(dumps(ret[1]))
|
fh.write(dumps(ret[1]))
|
||||||
with filename.open() as fh:
|
with filename.open() as fh:
|
||||||
data = loads(fh.read())
|
data = loads(fh.read())
|
||||||
assert ret == (True, data)
|
assert ret == (True, data), str(filename.absolute())
|
||||||
|
|
||||||
|
|
||||||
def test_cli_alt_rougailcli():
|
def test_cli_alt_rougailcli():
|
||||||
|
save = os.environ.copy()
|
||||||
with chdir(test_dir / 'rougailcli_file'):
|
with chdir(test_dir / 'rougailcli_file'):
|
||||||
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'alt_rougailcli.yml'
|
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'alt_rougailcli.yml'
|
||||||
ret = main([], do_not_print=True)
|
ret = main([], do_not_print=True)
|
||||||
|
|
@ -106,10 +150,12 @@ def test_cli_alt_rougailcli():
|
||||||
fh.write(dumps(ret[1]))
|
fh.write(dumps(ret[1]))
|
||||||
with filename.open() as fh:
|
with filename.open() as fh:
|
||||||
data = loads(fh.read())
|
data = loads(fh.read())
|
||||||
assert ret == (True, data)
|
assert ret == (True, data), str(filename.absolute())
|
||||||
|
os.environ = save
|
||||||
|
|
||||||
|
|
||||||
def test_cli_rougailcli_mix():
|
def test_cli_rougailcli_mix():
|
||||||
|
save = os.environ.copy()
|
||||||
with chdir(test_dir / 'rougailcli_file'):
|
with chdir(test_dir / 'rougailcli_file'):
|
||||||
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'mix_rougailcli.yml'
|
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'mix_rougailcli.yml'
|
||||||
ret = main(["-o", "doc", "--doc.output_format", "asciidoc"], do_not_print=True)
|
ret = main(["-o", "doc", "--doc.output_format", "asciidoc"], do_not_print=True)
|
||||||
|
|
@ -119,10 +165,12 @@ def test_cli_rougailcli_mix():
|
||||||
fh.write(dumps(ret[1]))
|
fh.write(dumps(ret[1]))
|
||||||
with filename.open() as fh:
|
with filename.open() as fh:
|
||||||
data = loads(fh.read())
|
data = loads(fh.read())
|
||||||
assert ret == (True, data)
|
assert ret == (True, data), str(filename.absolute())
|
||||||
|
os.environ = save
|
||||||
|
|
||||||
|
|
||||||
def test_cli_rougailcli_warning():
|
def test_cli_rougailcli_warning():
|
||||||
|
save = os.environ.copy()
|
||||||
with chdir(test_dir / 'rougailcli_file'):
|
with chdir(test_dir / 'rougailcli_file'):
|
||||||
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings.yml'
|
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings.yml'
|
||||||
with warnings.catch_warnings(record=True) as rougail_wn:
|
with warnings.catch_warnings(record=True) as rougail_wn:
|
||||||
|
|
@ -136,9 +184,11 @@ def test_cli_rougailcli_warning():
|
||||||
with filename.open() as fh:
|
with filename.open() as fh:
|
||||||
data = loads(fh.read())
|
data = loads(fh.read())
|
||||||
assert ret == data, str(filename.absolute())
|
assert ret == data, str(filename.absolute())
|
||||||
|
os.environ = save
|
||||||
|
|
||||||
|
|
||||||
def test_cli_rougailcli_not_warning():
|
def test_cli_rougailcli_not_warning():
|
||||||
|
save = os.environ.copy()
|
||||||
with chdir(test_dir / 'rougailcli_file'):
|
with chdir(test_dir / 'rougailcli_file'):
|
||||||
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings2.yml'
|
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings2.yml'
|
||||||
with warnings.catch_warnings(record=True) as rougail_wn:
|
with warnings.catch_warnings(record=True) as rougail_wn:
|
||||||
|
|
@ -152,9 +202,11 @@ def test_cli_rougailcli_not_warning():
|
||||||
with filename.open() as fh:
|
with filename.open() as fh:
|
||||||
data = loads(fh.read())
|
data = loads(fh.read())
|
||||||
assert ret == data, str(filename.absolute())
|
assert ret == data, str(filename.absolute())
|
||||||
|
os.environ = save
|
||||||
|
|
||||||
|
|
||||||
def test_cli_rougailcli_warning2():
|
def test_cli_rougailcli_warning2():
|
||||||
|
save = os.environ.copy()
|
||||||
with chdir(test_dir / 'rougailcli_file'):
|
with chdir(test_dir / 'rougailcli_file'):
|
||||||
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings3.yml'
|
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings3.yml'
|
||||||
with warnings.catch_warnings(record=True) as rougail_wn:
|
with warnings.catch_warnings(record=True) as rougail_wn:
|
||||||
|
|
@ -164,13 +216,15 @@ def test_cli_rougailcli_warning2():
|
||||||
filename = Path('warnings3.txt')
|
filename = Path('warnings3.txt')
|
||||||
if not filename.is_file():
|
if not filename.is_file():
|
||||||
with filename.open('w') as fh:
|
with filename.open('w') as fh:
|
||||||
fh.write(dumps([str(w.message) for w in rougail_wn]))
|
fh.write(dumps(ret))
|
||||||
with filename.open() as fh:
|
with filename.open() as fh:
|
||||||
data = loads(fh.read())
|
data = loads(fh.read())
|
||||||
assert ret == data, str(filename.absolute())
|
assert ret == data, str(filename.absolute())
|
||||||
|
os.environ = save
|
||||||
|
|
||||||
|
|
||||||
def test_cli_rougailcli_not_warning2():
|
def test_cli_rougailcli_not_warning2():
|
||||||
|
save = os.environ.copy()
|
||||||
with chdir(test_dir / 'rougailcli_file'):
|
with chdir(test_dir / 'rougailcli_file'):
|
||||||
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings4.yml'
|
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings4.yml'
|
||||||
with warnings.catch_warnings(record=True) as rougail_wn:
|
with warnings.catch_warnings(record=True) as rougail_wn:
|
||||||
|
|
@ -184,3 +238,4 @@ def test_cli_rougailcli_not_warning2():
|
||||||
with filename.open() as fh:
|
with filename.open() as fh:
|
||||||
data = loads(fh.read())
|
data = loads(fh.read())
|
||||||
assert ret == data, str(filename.absolute())
|
assert ret == data, str(filename.absolute())
|
||||||
|
os.environ = save
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue