1
0
Fork 0
mirror of synced 2024-05-27 20:41:09 -04:00

Rename default template processor

This commit is contained in:
Tim Byrne 2019-10-30 17:29:17 -05:00
parent b62a4c77a6
commit 616baaeac6
No known key found for this signature in database
GPG key ID: 14DB4FC2465A4B12
4 changed files with 30 additions and 30 deletions

View file

@ -101,7 +101,7 @@ def test_alt_conditions(
@pytest.mark.usefixtures('ds1_copy')
@pytest.mark.parametrize(
'kind', ['builtin', '', None, 'envtpl', 'j2cli', 'j2'])
'kind', ['default', '', None, 'envtpl', 'j2cli', 'j2'])
@pytest.mark.parametrize('label', ['t', 'template', 'yadm', ])
def test_alt_templates(
runner, paths, kind, label):
@ -223,7 +223,7 @@ def test_template_overwrite_symlink(runner, yadm_y, paths, tst_sys):
link = paths.work.join('test_link')
link.mksymlinkto(target, absolute=1)
template = paths.work.join('test_link##template.builtin')
template = paths.work.join('test_link##template.default')
template.write('test-data')
run = runner(yadm_y('add', target, template))

View file

@ -2,12 +2,12 @@
import pytest
@pytest.mark.parametrize('label', ['', 'builtin', 'other'])
@pytest.mark.parametrize('label', ['', 'default', 'other'])
@pytest.mark.parametrize('awk', [True, False], ids=['awk', 'no-awk'])
def test_kind_builtin(runner, yadm, awk, label):
"""Test kind: builtin"""
def test_kind_default(runner, yadm, awk, label):
"""Test kind: default"""
expected = 'template_builtin'
expected = 'template_default'
awk_avail = 'true'
if not awk:

View file

@ -1,18 +1,18 @@
"""Unit tests: template_builtin"""
"""Unit tests: template_default"""
# these values are also testing the handling of bizarre characters
LOCAL_CLASS = "builtin_Test+@-!^Class"
LOCAL_SYSTEM = "builtin_Test+@-!^System"
LOCAL_HOST = "builtin_Test+@-!^Host"
LOCAL_USER = "builtin_Test+@-!^User"
LOCAL_DISTRO = "builtin_Test+@-!^Distro"
LOCAL_CLASS = "default_Test+@-!^Class"
LOCAL_SYSTEM = "default_Test+@-!^System"
LOCAL_HOST = "default_Test+@-!^Host"
LOCAL_USER = "default_Test+@-!^User"
LOCAL_DISTRO = "default_Test+@-!^Distro"
TEMPLATE = f'''
start of template
builtin class = >{{{{yadm.class}}}}<
builtin os = >{{{{yadm.os}}}}<
builtin host = >{{{{yadm.hostname}}}}<
builtin user = >{{{{yadm.user}}}}<
builtin distro = >{{{{yadm.distro}}}}<
default class = >{{{{yadm.class}}}}<
default os = >{{{{yadm.os}}}}<
default host = >{{{{yadm.hostname}}}}<
default user = >{{{{yadm.user}}}}<
default distro = >{{{{yadm.distro}}}}<
{{% if yadm.class == "else1" %}}
wrong else 1
{{% else %}}
@ -70,11 +70,11 @@ end of template
'''
EXPECTED = f'''
start of template
builtin class = >{LOCAL_CLASS}<
builtin os = >{LOCAL_SYSTEM}<
builtin host = >{LOCAL_HOST}<
builtin user = >{LOCAL_USER}<
builtin distro = >{LOCAL_DISTRO}<
default class = >{LOCAL_CLASS}<
default os = >{LOCAL_SYSTEM}<
default host = >{LOCAL_HOST}<
default user = >{LOCAL_USER}<
default distro = >{LOCAL_DISTRO}<
Included section from else
Included section for class = {LOCAL_CLASS} ({LOCAL_CLASS} repeated)
Multiple lines
@ -86,8 +86,8 @@ end of template
'''
def test_template_builtin(runner, yadm, tmpdir):
"""Test template_builtin"""
def test_template_default(runner, yadm, tmpdir):
"""Test template_default"""
input_file = tmpdir.join('input')
input_file.write(TEMPLATE, ensure=True)
@ -100,7 +100,7 @@ def test_template_builtin(runner, yadm, tmpdir):
local_host="{LOCAL_HOST}"
local_user="{LOCAL_USER}"
local_distro="{LOCAL_DISTRO}"
template_builtin "{input_file}" "{output_file}"
template_default "{input_file}" "{output_file}"
"""
run = runner(command=['bash'], inp=script)
assert run.success
@ -117,7 +117,7 @@ def test_source(runner, yadm, tmpdir):
script = f"""
YADM_TEST=1 source {yadm}
template_builtin "{input_file}" "{output_file}"
template_default "{input_file}" "{output_file}"
"""
run = runner(command=['bash'], inp=script)
assert run.success

8
yadm
View file

@ -275,8 +275,8 @@ function record_template() {
function choose_template_cmd() {
kind="$1"
if [ "$kind" = "builtin" ] || [ "$kind" = "" ] && awk_available; then
echo "template_builtin"
if [ "$kind" = "default" ] || [ "$kind" = "" ] && awk_available; then
echo "template_default"
elif [ "$kind" = "j2cli" ] || [ "$kind" = "j2" ] && j2cli_available; then
echo "template_j2cli"
elif [ "$kind" = "envtpl" ] || [ "$kind" = "j2" ] && envtpl_available; then
@ -289,14 +289,14 @@ function choose_template_cmd() {
# ****** Template Processors ******
function template_builtin() {
function template_default() {
input="$1"
output="$2"
# the explicit "space + tab" character class used below is used because not
# all versions of awk seem to support the POSIX character classes [[:blank:]]
awk_pgm=$(cat << "EOF"
# built-in template processor
# built-in default template processor
BEGIN {
blank = "[ ]"
c["class"] = class