2023-10-12 08:17:30 +02:00
|
|
|
from shutil import rmtree #, copyfile, copytree
|
2021-04-13 19:05:01 +02:00
|
|
|
from os import getcwd, makedirs
|
|
|
|
from os.path import isfile, join, isdir
|
|
|
|
from pytest import fixture, raises
|
|
|
|
from os import listdir
|
|
|
|
from json import load
|
|
|
|
|
|
|
|
from rougail import RougailUpgrade, RougailConfig
|
|
|
|
from rougail.error import DictConsistencyError
|
|
|
|
|
2023-10-12 08:17:30 +02:00
|
|
|
#================================================
|
|
|
|
class Variable:
|
|
|
|
description: str
|
|
|
|
#================================================
|
|
|
|
#================================================
|
2021-04-13 19:05:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
dico_dirs = 'tests/dictionaries_old'
|
2022-10-01 22:27:22 +02:00
|
|
|
dest_dir = 'tmp'
|
2021-04-13 19:05:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
test_ok = set()
|
|
|
|
|
|
|
|
for test in listdir(dico_dirs):
|
|
|
|
if isdir(join(dico_dirs, test)):
|
|
|
|
test_ok.add(test)
|
|
|
|
|
|
|
|
excludes = set([])
|
|
|
|
test_ok -= excludes
|
2023-10-12 08:17:30 +02:00
|
|
|
#test_ok = ['10load_disabled_if_in_fill']
|
2021-04-13 19:05:01 +02:00
|
|
|
|
|
|
|
ORI_DIR = getcwd()
|
|
|
|
|
|
|
|
debug = False
|
|
|
|
#debug = True
|
|
|
|
|
|
|
|
test_ok = list(test_ok)
|
|
|
|
test_ok.sort()
|
|
|
|
if isdir(dest_dir):
|
|
|
|
rmtree(dest_dir)
|
|
|
|
makedirs(dest_dir)
|
2023-10-12 08:17:30 +02:00
|
|
|
#copyfile(join(dico_dirs, '__init__.py'), join(dest_dir, '__init__.py'))
|
2021-04-13 19:05:01 +02:00
|
|
|
#RougailConfig['variable_namespace'] = 'configuration'
|
|
|
|
|
|
|
|
|
|
|
|
@fixture(scope="module", params=test_ok)
|
|
|
|
def test_dir(request):
|
|
|
|
return request.param
|
|
|
|
|
|
|
|
|
2023-10-12 08:17:30 +02:00
|
|
|
def launch_test(test_dir, ext):
|
|
|
|
result_dest_dir = join(dico_dirs, test_dir.rsplit('/', 1)[1], 'result')
|
|
|
|
new_dest_dir = join(dico_dirs, test_dir.rsplit('/', 1)[1], dest_dir)
|
|
|
|
#FIXME
|
|
|
|
if isdir(new_dest_dir):
|
2021-04-13 19:05:01 +02:00
|
|
|
rmtree(new_dest_dir)
|
2023-10-12 08:17:30 +02:00
|
|
|
rougailconfig = RougailConfig.copy()
|
|
|
|
rougailconfig_dest = RougailConfig.copy()
|
|
|
|
rougailconfig_dest['functions_file'] = join(dico_dirs, '../eosfunc/test.py')
|
|
|
|
rougailconfig['dictionaries_dir'] = join(test_dir, 'xml')
|
|
|
|
rougailconfig_dest['dictionaries_dir'] = join(new_dest_dir, 'rougail')
|
|
|
|
rougailconfig_dest['services_dir'] = join(new_dest_dir, 'services')
|
|
|
|
rougailconfig['extra_dictionaries'] = {}
|
|
|
|
rougailconfig_dest['extra_dictionaries'] = {}
|
|
|
|
if isdir(join(test_dir, ext, 'extra_dirs')):
|
|
|
|
extras = listdir(join(test_dir, ext, 'extra_dirs'))
|
2021-04-13 19:05:01 +02:00
|
|
|
extras.sort()
|
|
|
|
for extra in extras:
|
2023-10-12 08:17:30 +02:00
|
|
|
subfolder = join(test_dir, ext, 'extra_dirs', extra)
|
2021-04-13 19:05:01 +02:00
|
|
|
if isdir(subfolder):
|
2023-10-12 08:17:30 +02:00
|
|
|
rougailconfig['extra_dictionaries'][extra] = [subfolder]
|
|
|
|
rougailconfig_dest['extra_dictionaries'][extra] = [join(new_dest_dir, extra)]
|
|
|
|
upgrade = RougailUpgrade(rougailconfig=rougailconfig)
|
|
|
|
upgrade.load_dictionaries(join(new_dest_dir, 'rougail'),
|
|
|
|
extra_dstfolder=new_dest_dir,
|
|
|
|
services_dstfolder=join(new_dest_dir, 'services'),
|
|
|
|
)
|
|
|
|
ori_lists = set()
|
|
|
|
find_files(result_dest_dir,
|
|
|
|
[],
|
|
|
|
ori_lists,
|
|
|
|
)
|
|
|
|
new_lists = set()
|
|
|
|
find_files(new_dest_dir,
|
|
|
|
[],
|
|
|
|
new_lists,
|
|
|
|
)
|
|
|
|
assert ori_lists == new_lists
|
|
|
|
for file in ori_lists:
|
|
|
|
ori_filename = join(result_dest_dir, file)
|
|
|
|
src_filename = join(new_dest_dir, file)
|
|
|
|
with open(ori_filename) as fh:
|
|
|
|
ori_file = fh.read()
|
|
|
|
with open(src_filename) as fh:
|
|
|
|
src_file = fh.read()
|
|
|
|
assert ori_file == src_file, f'file {ori_filename} and {src_filename} are differents'
|
|
|
|
#
|
|
|
|
rmtree(new_dest_dir)
|
|
|
|
|
|
|
|
|
|
|
|
def find_files(dirname: str,
|
|
|
|
root: list,
|
|
|
|
files: set,
|
|
|
|
) -> None:
|
|
|
|
for filename in listdir(dirname):
|
2024-03-28 09:43:33 +01:00
|
|
|
if filename.startswith('.'):
|
|
|
|
continue
|
2023-10-12 08:17:30 +02:00
|
|
|
abs_dirname = join(dirname, filename)
|
|
|
|
root_file = root + [filename]
|
|
|
|
if isdir(join(dirname, filename)):
|
|
|
|
find_files(abs_dirname,
|
|
|
|
root_file,
|
|
|
|
files,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
files.add(join(*root_file))
|
2021-04-13 19:05:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_dictionary(test_dir):
|
|
|
|
assert getcwd() == ORI_DIR
|
|
|
|
test_dir = join(dico_dirs, test_dir)
|
2023-10-12 08:17:30 +02:00
|
|
|
# FIXME for ext in ['xml', 'yml']:
|
|
|
|
# launch_test(test_dir, ext)
|
|
|
|
launch_test(test_dir, 'xml')
|
2021-04-13 19:05:01 +02:00
|
|
|
assert getcwd() == ORI_DIR
|