From ca6b933453d6f461d5025f4f4196c0d672fa7fbe Mon Sep 17 00:00:00 2001 From: gwen Date: Wed, 25 Sep 2024 08:52:13 +0200 Subject: [PATCH] test works --- tests/envvars/00_10_env_var/env | 8 ------ tests/envvars/00_6string/env | 8 ++++++ tests/makedict/00_6string/output.json | 8 ++++++ tests/test_load.py | 39 +++++++++++---------------- 4 files changed, 31 insertions(+), 32 deletions(-) delete mode 100644 tests/envvars/00_10_env_var/env create mode 100644 tests/envvars/00_6string/env create mode 100644 tests/makedict/00_6string/output.json diff --git a/tests/envvars/00_10_env_var/env b/tests/envvars/00_10_env_var/env deleted file mode 100644 index 5444afb..0000000 --- a/tests/envvars/00_10_env_var/env +++ /dev/null @@ -1,8 +0,0 @@ -ROUGAIL_VARNAME2="tata" -ROUGAIL_VARNAME1="titi" -ROUGAIL_VARNAME23=" 18, 25 " -ROUGAIL_VARINT="5" -ROUGAIL_VARNAME34=" 58, 22 " -ROUGAIL_IDONTEXIST="blah" -ROUGAIL_IDONTEXIST2="hum" -ROUGAIL_myfamily.varname3='spam' diff --git a/tests/envvars/00_6string/env b/tests/envvars/00_6string/env new file mode 100644 index 0000000..ea046c3 --- /dev/null +++ b/tests/envvars/00_6string/env @@ -0,0 +1,8 @@ +ROUGAIL_VAR1="spam" +ROUGAIL_VAR2="egg" +ROUGAIL_VAR3="hugh" +ROUGAIL_VAR4="some" +ROUGAIL_VAR5="part" +ROUGAIL_VAR6="ming" +ROUGAIL_IDONTEXIST="blah" +ROUGAIL_IDONTEXIST2="hum" diff --git a/tests/makedict/00_6string/output.json b/tests/makedict/00_6string/output.json new file mode 100644 index 0000000..4771a46 --- /dev/null +++ b/tests/makedict/00_6string/output.json @@ -0,0 +1,8 @@ +{ + "rougail.var1": "spam", + "rougail.var2": "egg", + "rougail.var3": "hugh", + "rougail.var4": "some", + "rougail.var5": "part", + "rougail.var6": "ming" +} diff --git a/tests/test_load.py b/tests/test_load.py index 9321e05..fed7364 100644 --- a/tests/test_load.py +++ b/tests/test_load.py @@ -2,27 +2,19 @@ from .custom import CustomOption from pathlib import Path import os - -from pytest import fixture # , raises +import json + +from pytest import fixture from ruamel.yaml import YAML from dotenv import load_dotenv from rougail import RougailConfig, Rougail -#from tiramisu import Config from rougail.user_data_environment.data import RougailUserDataEnvironment dico_dirs = Path('../rougail/tests/dictionaries') -#test_ok = set() - -#for test in dico_dirs.iterdir(): -# if (test / 'tiramisu').is_dir() and test.name not in excludes: -# test_ok.add(test) - -#test_ok = list(test_ok) -#test_ok.sort() - -test_ok = [dico_dirs / '00_10_env_var'] +env_test_folder = '00_6string' +test_ok = [dico_dirs / env_test_folder] @fixture(scope="module", params=test_ok) @@ -31,6 +23,7 @@ def test_dir(request): def _test_dictionaries(test_dir): + "rougail config settings" rougailconfig = RougailConfig.copy() rougailconfig['step.user_data'] = ['environment'] rougailconfig['main_namespace'] = None @@ -41,30 +34,28 @@ def _test_dictionaries(test_dir): def test_dictionaries_warning(test_dir): + "tests the '00_6string' folder" rougailconfig = _test_dictionaries(test_dir) # loads the config in the tiramisu's meaning config = Rougail(rougailconfig).run() #Config(optiondescription["option_0"]) 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' + envfile = Path('tests') / 'envvars' / env_test_folder / 'env' load_dotenv(envfile) - + # loads the environment variables in the tiramisu config 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) == """{: ['18', '25'], : [58, 22], : 'titi', : 2, : 'tata', : {: 'egg'}}""" - -#def test_dictionaries_asciidoc(test_dir): -# _test_dictionaries(test_dir, 'asciidoc', True) + # 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