From 45aac6a7391581e63c3d0fd16c31f1193909a3cb Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 2 Sep 2015 14:11:52 -0400 Subject: [PATCH] Adding unit tests for safe_eval --- test/units/template/test_safe_eval.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/units/template/test_safe_eval.py b/test/units/template/test_safe_eval.py index 785fc459921..610d4714439 100644 --- a/test/units/template/test_safe_eval.py +++ b/test/units/template/test_safe_eval.py @@ -19,3 +19,29 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +from collections import defaultdict + +from ansible.compat.tests import unittest +from ansible.compat.tests.mock import patch, MagicMock + +from ansible.template.safe_eval import safe_eval + +class TestSafeEval(unittest.TestCase): + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_safe_eval_usage(self): + # test safe eval calls with different possible types for the + # locals dictionary, to ensure we don't run into problems like + # ansible/ansible/issues/12206 again + for locals_vars in (dict(), defaultdict(dict)): + self.assertEqual(safe_eval('True', locals=locals_vars), True) + self.assertEqual(safe_eval('False', locals=locals_vars), False) + self.assertEqual(safe_eval('0', locals=locals_vars), 0) + self.assertEqual(safe_eval('[]', locals=locals_vars), []) + self.assertEqual(safe_eval('{}', locals=locals_vars), {}) +