mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-03 07:41:30 -07:00
templar: ensure that exceptions are handled, fix 'AttributeError' (#48792)
* templar: ensure that exceptions are handled * Fix AttributeError: object has no attribute 'message' 'message' attribute is deprecated since Python 2.6 and not available with Python 3. Simple reproducer: - hosts: localhost vars: not_json: "{{ 'test str' | from_json }}" tasks: - command: "echo {{ not_json }}"
This commit is contained in:
parent
37f66ee15b
commit
62c05033d6
2 changed files with 6 additions and 1 deletions
|
@ -50,6 +50,7 @@ class BaseTemplar(object):
|
|||
some_unsafe_var=wrap_var("unsafe_blip"),
|
||||
some_static_unsafe_var=wrap_var("static_unsafe_blip"),
|
||||
some_unsafe_keyword=wrap_var("{{ foo }}"),
|
||||
str_with_error="{{ 'str' | from_json }}",
|
||||
)
|
||||
self.fake_loader = DictDataLoader({
|
||||
"/path/to/my_file.txt": "foo\n",
|
||||
|
@ -183,6 +184,10 @@ class TestTemplarTemplate(BaseTemplar, unittest.TestCase):
|
|||
self.templar.template,
|
||||
data)
|
||||
|
||||
def test_template_with_error(self):
|
||||
"""Check that AnsibleError is raised, fail if an unhandled exception is raised"""
|
||||
self.assertRaises(AnsibleError, self.templar.template, "{{ str_with_error }}")
|
||||
|
||||
|
||||
class TestTemplarMisc(BaseTemplar, unittest.TestCase):
|
||||
def test_templar_simple(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue