add template tests

This commit is contained in:
Emmanuel Garette 2019-12-02 10:33:46 +01:00
parent 498e950610
commit 96e392cfd8
9 changed files with 219 additions and 0 deletions

View File

@ -0,0 +1,43 @@
<?xml version='1.0' encoding='UTF-8'?>
<creole>
<family name="containers">
<family name="container0" doc="test">
<family doc="files" name="files">
<family doc="file0" name="file0">
<variable doc="" multi="False" name="mkdir" type="boolean">
<value>False</value>
</variable>
<variable doc="" multi="False" name="name" type="string">
<value>/etc/mailname</value>
</variable>
<variable doc="" multi="False" name="rm" type="boolean">
<value>False</value>
</variable>
<variable doc="" multi="False" name="source" type="string">
<value>mailname</value>
</variable>
<variable doc="" multi="False" name="activate" type="boolean">
<value>True</value>
</variable>
</family>
</family>
<property>basic</property>
</family>
</family>
<family doc="" name="creole">
<family doc="général" name="general">
<property>normal</property>
<variable doc="No change" multi="False" name="mode_conteneur_actif" type="choice">
<choice type="string">oui</choice>
<choice type="string">non</choice>
<property>force_default_on_freeze</property>
<property>frozen</property>
<property>hidden</property>
<property>mandatory</property>
<property>normal</property>
<value type="string">oui</value>
</variable>
</family>
<separators/>
</family>
</creole>

View File

@ -0,0 +1 @@
oui

View File

@ -0,0 +1 @@
%%mode_conteneur_actif

View File

@ -0,0 +1,57 @@
<?xml version='1.0' encoding='UTF-8'?>
<creole>
<family name="containers">
<family name="container0" doc="test">
<family doc="files" name="files">
<family doc="file0" name="file0">
<variable doc="" multi="False" name="mkdir" type="boolean">
<value>False</value>
</variable>
<variable doc="" multi="False" name="name" type="string">
<value>/tmp/file</value>
</variable>
<variable doc="" multi="False" name="rm" type="boolean">
<value>False</value>
</variable>
<variable doc="" multi="False" name="source" type="string">
<value>file</value>
</variable>
<variable doc="" multi="False" name="activate" type="boolean">
<property expected="oui" inverse="False" source="creole.general.condition" type="calculation">disabled</property>
<value>True</value>
</variable>
</family>
</family>
<property>basic</property>
</family>
</family>
<family doc="" name="creole">
<family doc="general" name="general">
<property>normal</property>
<variable doc="No change" multi="False" name="condition" type="choice">
<choice type="string">oui</choice>
<choice type="string">non</choice>
<property>mandatory</property>
<property>normal</property>
<value type="string">non</value>
</variable>
<variable doc="No change" multi="False" name="mode_conteneur_actif" type="choice">
<choice type="string">oui</choice>
<choice type="string">non</choice>
<property>mandatory</property>
<property>normal</property>
<property expected="oui" inverse="False" source="creole.general.condition" type="calculation">disabled</property>
<value type="string">non</value>
</variable>
<variable doc="No change" multi="False" name="mode_conteneur_actif2" type="choice">
<choice type="string">oui</choice>
<choice type="string">non</choice>
<property>mandatory</property>
<property>normal</property>
<property expected="oui" inverse="False" source="creole.general.condition" type="calculation">disabled</property>
<value type="string">non</value>
</variable>
</family>
<separators/>
</family>
</creole>

View File

@ -0,0 +1 @@
non

View File

@ -0,0 +1 @@
%%condition

View File

@ -0,0 +1,57 @@
<?xml version='1.0' encoding='UTF-8'?>
<creole>
<family name="containers">
<family name="container0" doc="test">
<family doc="files" name="files">
<family doc="file0" name="file0">
<variable doc="" multi="False" name="mkdir" type="boolean">
<value>False</value>
</variable>
<variable doc="" multi="False" name="name" type="string">
<value>/tmp/file</value>
</variable>
<variable doc="" multi="False" name="rm" type="boolean">
<value>False</value>
</variable>
<variable doc="" multi="False" name="source" type="string">
<value>file</value>
</variable>
<variable doc="" multi="False" name="activate" type="boolean">
<property expected="oui" inverse="False" source="creole.general.condition" type="calculation">disabled</property>
<value>True</value>
</variable>
</family>
</family>
<property>basic</property>
</family>
</family>
<family doc="" name="creole">
<family doc="general" name="general">
<property>normal</property>
<variable doc="No change" multi="False" name="condition" type="choice">
<choice type="string">oui</choice>
<choice type="string">non</choice>
<property>mandatory</property>
<property>normal</property>
<value type="string">oui</value>
</variable>
<variable doc="No change" multi="False" name="mode_conteneur_actif" type="choice">
<choice type="string">oui</choice>
<choice type="string">non</choice>
<property>mandatory</property>
<property>normal</property>
<property expected="oui" inverse="False" source="creole.general.condition" type="calculation">disabled</property>
<value type="string">non</value>
</variable>
<variable doc="No change" multi="False" name="mode_conteneur_actif2" type="choice">
<choice type="string">oui</choice>
<choice type="string">non</choice>
<property>mandatory</property>
<property>normal</property>
<property expected="oui" inverse="False" source="creole.general.condition" type="calculation">disabled</property>
<value type="string">non</value>
</variable>
</family>
<separators/>
</family>
</creole>

View File

@ -0,0 +1 @@
%%condition

57
tests/test_template.py Normal file
View File

@ -0,0 +1,57 @@
from os import listdir, mkdir
from os.path import join, isdir, isfile
from shutil import rmtree
from pytest import fixture
from lxml.etree import parse
from tiramisu import Config
from rougail import template, load
from rougail.config import dtdfilename
template_dirs = 'tests/templates'
test_ok = listdir(template_dirs)
@fixture(scope="module", params=test_ok)
def test_dir(request):
return request.param
def test_dictionary(test_dir):
test_dir = join(template_dirs, test_dir)
tmp_dir = join(test_dir, 'tmp')
funcs_file = join(template_dirs, '../eosfunc/test.py')
template.distrib_dir = join(test_dir, 'tmpl')
template.templatedir = tmp_dir
if isdir(tmp_dir):
rmtree(tmp_dir)
mkdir(tmp_dir)
dest_dir = join(test_dir, 'dest')
template.dest_dir = dest_dir
if isdir(dest_dir):
rmtree(dest_dir)
mkdir(dest_dir)
with open(join(test_dir, '00-base.xml')) as fileio:
xmlroot = parse(fileio).getroot()
optiondescription = load(xmlroot,
dtdfilename,
funcs_file)
config = Config(optiondescription)
config.property.read_only()
template.generate(config,
funcs_file)
list_templates = set(listdir(dest_dir))
list_results = set(listdir(join(test_dir, 'result')))
assert list_templates == list_results
for result in listdir(join(test_dir, 'result')):
template_file = join(dest_dir, result)
if not isfile(template_file):
raise Exception(f'{template_file} is not generated')
with open(join(test_dir, 'result', result), 'r') as fh:
result_file = fh.read()
with open(template_file, 'r') as fh:
generated_file = fh.read()
assert result_file == generated_file