from lxml import etree from os.path import isfile, join, isdir from pytest import fixture, mark from os import listdir, mkdir from json import dump, load, dumps, loads from tiramisu import Config from rougail import load as rougail_load from rougail.xml_compare import xml_compare from rougail.error import DictConsistencyError dico_dirs = 'tests/flattener_dicos' test_ok = set() for test in listdir(dico_dirs): if isdir(join(dico_dirs, test)): if isdir(join(dico_dirs, test, 'result')): test_ok.add(test) excludes = set([]) #excludes = set(['70container_services']) test_ok -= excludes #test_ok = ['10leadership_append'] test_ok = list(test_ok) test_ok.sort() @fixture(scope="module", params=test_ok) def test_dir(request): return request.param async def launch_flattener(test_dir): debug = False # debug = True eosfunc = join(dico_dirs, '../eosfunc/test.py') cache_file = test_dir + '/result/00-base.xml' fileio = open(cache_file) xmlroot = etree.parse(fileio).getroot() tiramisu_objects = rougail_load(xmlroot, eosfunc, ) tiramisu_objects += '\n' #print(tiramisu_objects) tiramisu_dir = join(test_dir, 'tiramisu') tiramisu_file = join(tiramisu_dir, 'base.py') #config = await Config(tiramisu_objects) #await config.property.read_only() #await config.property.pop('mandatory') #config_dict = await config.value.dict() if not isdir(tiramisu_dir): mkdir(tiramisu_dir) if not isfile(tiramisu_file) or debug: with open(tiramisu_file, 'w') as fh: fh.write(tiramisu_objects) with open(tiramisu_file, 'r') as fh: tiramisu_objects_ori = fh.read() assert tiramisu_objects == tiramisu_objects_ori #if config_dict: # if not isdir(tiramisu_dir): # mkdir(tiramisu_dir) # #with open(tiramisu_file, 'w') as fh: # # dump(config_dict, fh) # # fh.write('\n') #if not isfile(tiramisu_file): # if config_dict: # raise Exception('dict is not empty') #else: # assert load(fh) == loads(dumps(config_dict)) @mark.asyncio async def test_dictionary(test_dir): test_dir = join(dico_dirs, test_dir) await launch_flattener(test_dir)