from lxml import etree from os.path import isfile, join, isdir from pytest import fixture, raises from os import listdir, mkdir from json import dump, load, dumps, loads #from creole.xmlreflector import CreoleObjSpace, CreoleDictConsistencyError #from creole import xmlreflector from creole import objspace, annotator from creole.xml_compare import xml_compare from creole.error import CreoleDictConsistencyError from creole.loader import PopulateTiramisuObjects from creole.config import dtdfilename 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([]) test_ok -= excludes #test_ok = ['70container_all'] test_ok = list(test_ok) test_ok.sort() @fixture(scope="module", params=test_ok) def test_dir(request): return request.param def launch_flattener(test_dir): 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 = PopulateTiramisuObjects() tiramisu_objects.parse_dtd(dtdfilename) tiramisu_objects.make_tiramisu_objects(xmlroot, eosfunc) config = tiramisu_objects.build() config.property.read_write() makedict_dir = join(test_dir, 'makedict') makedict_file = join(makedict_dir, 'base.json') config_dict = config.value.dict() # if not isfile(makedict_file) and config_dict: # if not isdir(makedict_dir): # mkdir(makedict_dir) # with open(makedict_file, 'w') as fh: # dump(config_dict, fh) if not isfile(makedict_file): if config_dict: raise Exception('dict is not empty') else: with open(makedict_file, 'r') as fh: assert load(fh) == loads(dumps(config_dict)) def fake_traduc(txt): return txt def setup_module(module): module.traduc_ori = objspace._ objspace._ = fake_traduc annotator._ = fake_traduc objspace.ContainerAnnotator = getattr(annotator, 'ContainerAnnotator') def teardown_module(module): objspace._ = module.traduc_ori annotator._ = module.traduc_ori def test_dictionary(test_dir): test_dir = join(dico_dirs, test_dir) launch_flattener(test_dir)