From e003f1e75361de32627979f26959197ce66792c3 Mon Sep 17 00:00:00 2001 From: James Cassell Date: Sat, 2 Nov 2019 03:39:26 -0400 Subject: [PATCH] jinja 2.10 compat: add missing built-in tests --- .../fragments/compat-jinja-2.10-test.yml | 3 ++ lib/ansible/plugins/test/compat_jinja_2_10.py | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 changelogs/fragments/compat-jinja-2.10-test.yml create mode 100644 lib/ansible/plugins/test/compat_jinja_2_10.py diff --git a/changelogs/fragments/compat-jinja-2.10-test.yml b/changelogs/fragments/compat-jinja-2.10-test.yml new file mode 100644 index 00000000000000..53b463b4c0ce5d --- /dev/null +++ b/changelogs/fragments/compat-jinja-2.10-test.yml @@ -0,0 +1,3 @@ +--- +bugfixes: +- fixed ansible template failures on older jinja due to missing built-in tests diff --git a/lib/ansible/plugins/test/compat_jinja_2_10.py b/lib/ansible/plugins/test/compat_jinja_2_10.py new file mode 100644 index 00000000000000..e417ba211c6516 --- /dev/null +++ b/lib/ansible/plugins/test/compat_jinja_2_10.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2017, the Jinja Team +# BSD 3-Clause "New" or "Revised" License (see https://opensource.org/licenses/BSD-3-Clause) + +# XXX: These tests exist for compatibility with Jinja < 2.10. Once every +# platform has at least 2.10 version of jinja, this file can go away. + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import operator + +def test_in(value, seq): + """Check if value is in seq. + Copied from Jinja 2.10 https://github.com/pallets/jinja/pull/665 + + .. versionadded:: 2.10 + """ + return value in seq + +class TestModule: + """copied from jinja 2.10 for consistent test behavior independent of the + system jinja version + """ + + def tests(self): + return { + 'in': test_in, + '==': operator.eq, + 'eq': operator.eq, + 'equalto': operator.eq, + '!=': operator.ne, + 'ne': operator.ne, + '>': operator.gt, + 'gt': operator.gt, + 'greaterthan': operator.gt, + 'ge': operator.ge, + '>=': operator.ge, + '<': operator.lt, + 'lt': operator.lt, + 'lessthan': operator.lt, + '<=': operator.le, + 'le': operator.le, + }