1
0
Fork 0
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:
Brian Coca 2015-06-11 12:47:29 -04:00
parent 5d7dac6938
commit e9cf67004b

View file

@ -71,16 +71,18 @@ 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"))