file handle

This commit is contained in:
gwen 2024-10-01 12:03:52 +02:00
parent ff14bd3bcc
commit c51db38022

View file

@ -4,7 +4,7 @@ from pathlib import Path
from os import getcwd, listdir, environ, makedirs from os import getcwd, listdir, environ, makedirs
from os.path import isfile, join, isdir, dirname from os.path import isfile, join, isdir, dirname
from pathlib import Path from pathlib import Path
import json from json import load, dump
from pytest import fixture, raises from pytest import fixture, raises
from ruamel.yaml import YAML from ruamel.yaml import YAML
@ -51,13 +51,13 @@ def _test_dictionaries(test_dir):
def test_dictionaries_warning(test_dir): def test_dictionaries_warning(test_dir):
"tests the '00_6string' folder" "tests the env output"
current_dirname = test_dir.name current_dirname = test_dir.name
rougailconfig = _test_dictionaries(test_dir) rougailconfig = _test_dictionaries(test_dir)
# populate tests if not already exists # populate tests if not already exists
dest_dir = Path('tests') / 'envvars' / test_dir.name dest_dir = Path('tests') / 'envvars' / test_dir.name
populate(dest_dir, rougailconfig) populate(dest_dir, rougailconfig)
# loads the config in the tiramisu's meaning # loads the config in the tiramisu's meaning
config = Rougail(rougailconfig).run() #Config(optiondescription["option_0"]) config = Rougail(rougailconfig).run() #Config(optiondescription["option_0"])
config_dict = dict(config.value.get()) config_dict = dict(config.value.get())
user_datas = {'errors': [], user_datas = {'errors': [],
@ -76,7 +76,7 @@ def test_dictionaries_warning(test_dir):
new_config_dict = dict(new_config.value.get()) new_config_dict = dict(new_config.value.get())
# expected output # expected output
with open(Path('tests') / 'envvars' / current_dirname / 'makedict' / 'all.env') as json_file: with open(Path('tests') / 'envvars' / current_dirname / 'makedict' / 'all.env') as json_file:
expected = json.load(json_file) expected = load(json_file)
# here is the effective test # here is the effective test
for key, value in new_config_dict.items(): for key, value in new_config_dict.items():
assert expected["rougail." + key.name()] == value assert expected["rougail." + key.name()] == value
@ -102,7 +102,7 @@ def populate(dest_dir, rougailconfig):
with makedict_file.open('w') as envfh: with makedict_file.open('w') as envfh:
#envfh.write('\n'.join(values) + '\n') #envfh.write('\n'.join(values) + '\n')
config_dict = dict(option_value(config.value.get())) config_dict = dict(option_value(config.value.get()))
dump(config_dict, fh, indent=4) dump(config_dict, envfh, indent=4)
envfh.write('\n') envfh.write('\n')