summaryrefslogtreecommitdiffstats
path: root/test/units/template/test_safe_eval.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/units/template/test_safe_eval.py')
-rw-r--r--test/units/template/test_safe_eval.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/units/template/test_safe_eval.py b/test/units/template/test_safe_eval.py
new file mode 100644
index 00000000..89ff8a0e
--- /dev/null
+++ b/test/units/template/test_safe_eval.py
@@ -0,0 +1,44 @@
+# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
+#
+# This file is part of Ansible
+#
+# Ansible is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Ansible is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
+
+# Make coding more python3-ish
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+import sys
+from collections import defaultdict
+
+from units.compat import unittest
+from ansible.template.safe_eval import safe_eval
+
+
+class TestSafeEval(unittest.TestCase):
+
+ 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), {})
+
+ @unittest.skipUnless(sys.version_info[:2] >= (2, 7), "Python 2.6 has no set literals")
+ def test_set_literals(self):
+ self.assertEqual(safe_eval('{0}'), set([0]))