diff --git a/tests/templates/00base/00-base.xml b/tests/templates/00base/00-base.xml new file mode 100644 index 00000000..cf395684 --- /dev/null +++ b/tests/templates/00base/00-base.xml @@ -0,0 +1,43 @@ + + + + + + + + False + + + /etc/mailname + + + False + + + mailname + + + True + + + + basic + + + + + normal + + oui + non + force_default_on_freeze + frozen + hidden + mandatory + normal + oui + + + + + diff --git a/tests/templates/00base/result/mailname b/tests/templates/00base/result/mailname new file mode 100644 index 00000000..bd51bf63 --- /dev/null +++ b/tests/templates/00base/result/mailname @@ -0,0 +1 @@ +oui diff --git a/tests/templates/00base/tmpl/mailname b/tests/templates/00base/tmpl/mailname new file mode 100644 index 00000000..a29cfeaf --- /dev/null +++ b/tests/templates/00base/tmpl/mailname @@ -0,0 +1 @@ +%%mode_conteneur_actif diff --git a/tests/templates/11disabled_if_in_filelist/00-base.xml b/tests/templates/11disabled_if_in_filelist/00-base.xml new file mode 100644 index 00000000..131a2077 --- /dev/null +++ b/tests/templates/11disabled_if_in_filelist/00-base.xml @@ -0,0 +1,57 @@ + + + + + + + + False + + + /tmp/file + + + False + + + file + + + disabled + True + + + + basic + + + + + normal + + oui + non + mandatory + normal + non + + + oui + non + mandatory + normal + disabled + non + + + oui + non + mandatory + normal + disabled + non + + + + + diff --git a/tests/templates/11disabled_if_in_filelist/result/file b/tests/templates/11disabled_if_in_filelist/result/file new file mode 100644 index 00000000..d907505b --- /dev/null +++ b/tests/templates/11disabled_if_in_filelist/result/file @@ -0,0 +1 @@ +non diff --git a/tests/templates/11disabled_if_in_filelist/tmpl/file b/tests/templates/11disabled_if_in_filelist/tmpl/file new file mode 100644 index 00000000..5113d9aa --- /dev/null +++ b/tests/templates/11disabled_if_in_filelist/tmpl/file @@ -0,0 +1 @@ +%%condition diff --git a/tests/templates/11disabled_if_in_filelist_disabled/00-base.xml b/tests/templates/11disabled_if_in_filelist_disabled/00-base.xml new file mode 100644 index 00000000..fcbec226 --- /dev/null +++ b/tests/templates/11disabled_if_in_filelist_disabled/00-base.xml @@ -0,0 +1,57 @@ + + + + + + + + False + + + /tmp/file + + + False + + + file + + + disabled + True + + + + basic + + + + + normal + + oui + non + mandatory + normal + oui + + + oui + non + mandatory + normal + disabled + non + + + oui + non + mandatory + normal + disabled + non + + + + + diff --git a/tests/templates/11disabled_if_in_filelist_disabled/tmpl/file b/tests/templates/11disabled_if_in_filelist_disabled/tmpl/file new file mode 100644 index 00000000..5113d9aa --- /dev/null +++ b/tests/templates/11disabled_if_in_filelist_disabled/tmpl/file @@ -0,0 +1 @@ +%%condition diff --git a/tests/test_template.py b/tests/test_template.py new file mode 100644 index 00000000..2b5c844d --- /dev/null +++ b/tests/test_template.py @@ -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