test base and systemd templating

This commit is contained in:
egarette@silique.fr 2023-01-07 17:16:31 +01:00
parent 2d8ef64904
commit 3c5d4a4fa6
25 changed files with 34 additions and 9 deletions

View file

View file

View file

@ -1,11 +1,11 @@
from os import listdir, mkdir, readlink
from os.path import join, isdir, isfile, islink
from shutil import rmtree
from pytest import fixture, mark
from pytest import fixture, mark, raises
from lxml.etree import parse
from tiramisu import Config
from rougail import RougailConfig, RougailSystemdTemplate
from rougail import RougailConfig, RougailBaseTemplate, RougailSystemdTemplate
template_dirs = 'tests/dictionaries'
@ -39,7 +39,7 @@ def find_files(dirname: str,
files.add(join(*root_file))
async def template(test_dir, filename, root):
async def template(test_dir, filename, root, engine_name):
test_dir = join(template_dirs, test_dir)
tmp_dir = join(test_dir, '..', 'tmp')
@ -71,6 +71,9 @@ async def template(test_dir, filename, root):
RougailConfig['tmpfile_dest_dir'] = '/test/new/file'
else:
RougailConfig['tmpfile_dest_dir'] = '/usr/local/lib'
if engine_name == 'base':
engine = RougailBaseTemplate(config)
else:
engine = RougailSystemdTemplate(config)
await engine.instance_files()
list_templates = set()
@ -85,6 +88,8 @@ async def template(test_dir, filename, root):
[],
list_results,
)
if engine_name == 'base' and 'tmpfiles.d/0rougail.conf' in list_results:
list_results.remove('tmpfiles.d/0rougail.conf')
assert list_templates == list_results, f'error with {test_dir}:'
for result in list_results:
template_file = join(dest_dir, result)
@ -99,20 +104,40 @@ async def template(test_dir, filename, root):
with open(template_file, 'r') as fh:
generated_file = fh.read()
assert result_file == generated_file, f'{template_file} content : \n{generated_file}\nexpected: \nresult_file\n'
if isdir(dest_dir):
rmtree(dest_dir)
if isdir(tmp_dir):
rmtree(tmp_dir)
@mark.asyncio
async def test_template(test_dir):
await template(test_dir, 'base', '1')
for engine in ['base', 'systemd']:
not_file = join(template_dirs, test_dir, 'no_' + engine)
if isfile(not_file):
with raises(Exception) as err:
await template(test_dir, 'base', '1', engine)
else:
await template(test_dir, 'base', '1', engine)
@mark.asyncio
async def test_template_multi_1(test_dir):
await template(test_dir, 'multi', '1')
for engine in ['base', 'systemd']:
not_file = join(template_dirs, test_dir, 'no_' + engine)
if isfile(not_file):
with raises(Exception) as err:
await template(test_dir, 'multi', '1', engine)
else:
await template(test_dir, 'multi', '1', engine)
@mark.asyncio
async def test_template_multi_2(test_dir):
await template(test_dir, 'multi', '1')
for engine in ['base', 'systemd']:
not_file = join(template_dirs, test_dir, 'no_' + engine)
if isfile(not_file):
with raises(Exception) as err:
await template(test_dir, 'multi', '1', engine)
else:
await template(test_dir, 'multi', '1', engine)