Skip to content

Commit

Permalink
jinja 2.10 compat: add missing built-in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescassell committed Nov 2, 2019
1 parent 78e476e commit e003f1e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions 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
45 changes: 45 additions & 0 deletions 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,
}

0 comments on commit e003f1e

Please sign in to comment.