From 6d5467951a5a4bc9a98add128365bb5d315442f5 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Sat, 12 Oct 2019 09:14:45 -0500 Subject: [PATCH] Properly handle missing "." in alternate conditions --- test/test_alt.py | 5 ++++- test/utils.py | 2 +- yadm | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/test_alt.py b/test/test_alt.py index cbac403..68954a0 100644 --- a/test/test_alt.py +++ b/test/test_alt.py @@ -100,7 +100,8 @@ def test_alt_conditions( @pytest.mark.usefixtures('ds1_copy') -@pytest.mark.parametrize('kind', ['builtin', '', 'envtpl', 'j2cli', 'j2']) +@pytest.mark.parametrize( + 'kind', ['builtin', '', None, 'envtpl', 'j2cli', 'j2']) @pytest.mark.parametrize('label', ['t', 'template', 'yadm', ]) def test_alt_templates( runner, paths, kind, label): @@ -108,6 +109,8 @@ def test_alt_templates( yadm_dir = setup_standard_yadm_dir(paths) suffix = f'##{label}.{kind}' + if kind is None: + suffix = f'##{label}' utils.create_alt_files(paths, suffix) run = runner([paths.pgm, '-Y', yadm_dir, 'alt']) assert run.success diff --git a/test/utils.py b/test/utils.py index 32db94a..2291fc5 100644 --- a/test/utils.py +++ b/test/utils.py @@ -59,7 +59,7 @@ def create_alt_files(paths, suffix, # Do not test directory support for jinja alternates test_paths = [new_file1, new_file2] test_names = [ALT_FILE1, ALT_FILE2] - if not re.match(r'##(t|template|yadm)\.', suffix): + if not re.match(r'##(t$|t\.|template|yadm)', suffix): test_paths += [new_dir] test_names += [ALT_DIR] diff --git a/yadm b/yadm index 687264a..c85ae4f 100755 --- a/yadm +++ b/yadm @@ -148,6 +148,7 @@ function score_file() { for field in "${fields[@]}"; do label=${field%%.*} value=${field#*.} + [ "$field" = "$label" ] && value="" # when .value is omitted score=$((score + 1000)) # default condition if [[ "$label" =~ ^(default)$ ]]; then