mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
updated fail_on_undefined test to new function signatures
This commit is contained in:
parent
5d7dac6938
commit
e9cf67004b
1 changed files with 6 additions and 4 deletions
|
@ -71,22 +71,24 @@ class TestTemplar(unittest.TestCase):
|
|||
self.assertEqual(templar.template("{{bad_dict}}"), "{a='b'")
|
||||
self.assertEqual(templar.template("{{var_list}}"), [1])
|
||||
self.assertEqual(templar.template(1, convert_bare=True), 1)
|
||||
#FIXME: lookup ignores fake file and returns error
|
||||
#self.assertEqual(templar.template("{{lookup('file', '/path/to/my_file.txt')}}"), "foo")
|
||||
|
||||
# force errors
|
||||
self.assertRaises(UndefinedError, templar.template, "{{bad_var}}")
|
||||
self.assertEqual(templar.template("{{lookup('file', '/path/to/my_file.txt')}}"), "foo")
|
||||
self.assertRaises(UndefinedError, templar.template, "{{lookup('file', bad_var)}}")
|
||||
self.assertRaises(AnsibleError, templar.template, "{{lookup('bad_lookup')}}")
|
||||
self.assertRaises(AnsibleError, templar.template, "{{recursive}}")
|
||||
self.assertRaises(AnsibleUndefinedVariable, templar.template, "{{foo-bar}}")
|
||||
|
||||
# test with fail_on_undefined=False
|
||||
templar = Templar(loader=fake_loader, fail_on_undefined=False)
|
||||
self.assertEqual(templar.template("{{bad_var}}"), "{{bad_var}}")
|
||||
self.assertEqual(templar.template("{{bad_var}}", fail_on_undefined=False), "{{bad_var}}")
|
||||
|
||||
# test set_available_variables()
|
||||
templar.set_available_variables(variables=dict(foo="bam"))
|
||||
self.assertEqual(templar.template("{{foo}}"), "bam")
|
||||
# variables must be a dict() for set_available_variables()
|
||||
self.assertRaises(AssertionError, templar.set_available_variables, "foo=bam")
|
||||
self.assertRaises(AssertionError, templar.set_available_variables, "foo=bam")
|
||||
|
||||
def test_template_jinja2_extensions(self):
|
||||
fake_loader = DictDataLoader({})
|
||||
|
|
Loading…
Reference in a new issue