rougail-user-data-environment/tests/test_load.py

71 lines
2.4 KiB
Python
Raw Normal View History

2024-09-23 14:34:15 +02:00
from .custom import CustomOption
2024-09-18 11:43:22 +02:00
from pathlib import Path
2024-09-24 16:42:03 +02:00
import os
2024-09-23 14:34:15 +02:00
from pytest import fixture # , raises
2024-09-18 11:43:22 +02:00
from ruamel.yaml import YAML
2024-09-24 16:42:03 +02:00
from dotenv import load_dotenv
2024-09-18 11:43:22 +02:00
2024-09-23 14:34:15 +02:00
from rougail import RougailConfig, Rougail
#from tiramisu import Config
2024-09-24 16:42:03 +02:00
from rougail.user_data_environment.data import RougailUserDataEnvironment
2024-09-18 11:43:22 +02:00
dico_dirs = Path('../rougail/tests/dictionaries')
2024-09-23 14:34:15 +02:00
#test_ok = set()
2024-09-18 11:43:22 +02:00
2024-09-23 14:34:15 +02:00
#for test in dico_dirs.iterdir():
# if (test / 'tiramisu').is_dir() and test.name not in excludes:
# test_ok.add(test)
2024-09-18 11:43:22 +02:00
2024-09-23 14:34:15 +02:00
#test_ok = list(test_ok)
#test_ok.sort()
2024-09-18 11:43:22 +02:00
2024-09-24 16:42:03 +02:00
test_ok = [dico_dirs / '00_10_env_var']
2024-09-18 11:43:22 +02:00
@fixture(scope="module", params=test_ok)
def test_dir(request):
return request.param
2024-09-23 14:34:15 +02:00
def _test_dictionaries(test_dir):
2024-09-18 11:43:22 +02:00
rougailconfig = RougailConfig.copy()
2024-09-24 16:42:03 +02:00
rougailconfig['step.user_data'] = ['environment']
rougailconfig['main_namespace'] = None
2024-09-18 11:43:22 +02:00
dirs = [str(test_dir / 'dictionaries' / 'rougail')]
rougailconfig['custom_types']['custom'] = CustomOption
2024-09-23 14:34:15 +02:00
rougailconfig['main_dictionaries'] = dirs
return rougailconfig
def test_dictionaries_warning(test_dir):
rougailconfig = _test_dictionaries(test_dir)
# loads the config in the tiramisu's meaning
config = Rougail(rougailconfig).run() #Config(optiondescription["option_0"])
2024-09-24 16:42:03 +02:00
config_dict = dict(config.value.get())
#print(config_dict)
user_datas = {'errors': [],
'warnings': [],
}
# loading the env file
envfile = Path('tests') / 'envvars' / '00_10_env_var' / 'env'
load_dotenv(envfile)
environment = RougailUserDataEnvironment(config,
rougailconfig=rougailconfig,
user_datas=user_datas,
)
environment.run()
new_config = environment.config
#print(user_datas)
#print(os.getenv("ROUGAIL_VARNAME23"))
new_config_dict = dict(new_config.value.get())
# print(new_config_dict)
assert str(new_config_dict) == """{<TiramisuOption path="varname23">: ['18', '25'], <TiramisuOption path="varname34">: [58, 22], <TiramisuOption path="varname1">: 'titi', <TiramisuOption path="varint">: 2, <TiramisuOption path="varname2">: 'tata', <TiramisuOption path="myfamily">: {<TiramisuOption path="myfamily.varname3">: 'egg'}}"""
2024-09-23 14:34:15 +02:00
#def test_dictionaries_asciidoc(test_dir):
# _test_dictionaries(test_dir, 'asciidoc', True)