Skip to content

Commit

Permalink
Rename default template processor
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLocehiliosan committed Oct 30, 2019
1 parent b62a4c7 commit 616baae
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions test/test_alt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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))
Expand Down
8 changes: 4 additions & 4 deletions test/test_unit_choose_template_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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 %}}
Expand Down Expand Up @@ -70,11 +70,11 @@
'''
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
Expand All @@ -86,8 +86,8 @@
'''


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)
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions yadm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 616baae

Please sign in to comment.