From 51216dcfae42aa29ff48dd9f2c5651e50692e965 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Tue, 25 Sep 2012 15:43:25 +0200 Subject: [PATCH] Add tests for varReplace repr --- test/TestUtils.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/TestUtils.py b/test/TestUtils.py index 432f56f62d..471418f464 100644 --- a/test/TestUtils.py +++ b/test/TestUtils.py @@ -202,6 +202,55 @@ class TestUtils(unittest.TestCase): assert res == 'hello world' + def test_varReplace_repr_basic(self): + vars = { + 'color': '$favorite_color', + 'favorite_color': 'blue', + } + + template = '$color == "blue"' + res = ansible.utils.varReplace(template, vars, do_repr=True) + assert eval(res) + + def test_varReplace_repr_varinvar(self): + vars = { + 'foo': 'foo', + 'bar': 'bar', + 'foobar': '$foo$bar', + 'var': { + 'foo': 'foo', + 'foobar': '$foo$bar', + }, + } + + template = '$foobar == "foobar"' + res = ansible.utils.varReplace(template, vars, do_repr=True) + assert eval(res) + + def test_varReplace_repr_varindex(self): + vars = { + 'foo': 'foo', + 'var': { + 'foo': 'bar', + }, + } + + template = '${var.$foo} == "bar"' + res = ansible.utils.varReplace(template, vars, do_repr=True) + assert eval(res) + + def test_varReplace_repr_varpartindex(self): + vars = { + 'foo': 'foo', + 'var': { + 'foobar': 'foobar', + }, + } + + template = '${var.${foo}bar} == "foobar"' + res = ansible.utils.varReplace(template, vars, do_repr=True) + assert eval(res) + def test_template_varReplace_iterated(self): template = 'hello $who' vars = {