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-25 08:52:13 +02:00
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
from pytest import fixture
|
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
|
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-25 08:52:13 +02:00
|
|
|
|
env_test_folder = '00_6string'
|
|
|
|
|
test_ok = [dico_dirs / env_test_folder]
|
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-25 08:52:13 +02:00
|
|
|
|
"rougail config settings"
|
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):
|
2024-09-25 08:52:13 +02:00
|
|
|
|
"tests the '00_6string' folder"
|
2024-09-23 14:34:15 +02:00
|
|
|
|
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())
|
|
|
|
|
user_datas = {'errors': [],
|
|
|
|
|
'warnings': [],
|
|
|
|
|
}
|
|
|
|
|
# loading the env file
|
2024-09-25 08:52:13 +02:00
|
|
|
|
envfile = Path('tests') / 'envvars' / env_test_folder / 'env'
|
2024-09-24 16:42:03 +02:00
|
|
|
|
load_dotenv(envfile)
|
2024-09-25 08:52:13 +02:00
|
|
|
|
# loads the environment variables in the tiramisu config
|
2024-09-24 16:42:03 +02:00
|
|
|
|
environment = RougailUserDataEnvironment(config,
|
|
|
|
|
rougailconfig=rougailconfig,
|
|
|
|
|
user_datas=user_datas,
|
|
|
|
|
)
|
|
|
|
|
environment.run()
|
|
|
|
|
new_config = environment.config
|
|
|
|
|
new_config_dict = dict(new_config.value.get())
|
2024-09-25 08:52:13 +02:00
|
|
|
|
# expected output
|
|
|
|
|
with open(Path('tests') / 'makedict' / env_test_folder / 'output.json') as json_file:
|
|
|
|
|
expected = json.load(json_file)
|
|
|
|
|
# here is the effective test
|
|
|
|
|
for key, value in new_config_dict.items():
|
|
|
|
|
assert expected["rougail."+key.name()] == value
|