Clean up test failures (#216)
* Fix arguments-renamed * Handle changed behavior in 2.15pull/210/head
parent
57c5cd4336
commit
462e4e7f71
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
trivial:
|
||||
- Fix various 2.15 sanity and unit tests. (https://github.com/ansible-collections/ansible.utils/pull/216)
|
|
@ -303,7 +303,7 @@ from ansible.errors import AnsibleFilterError
|
|||
from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
|
||||
AnsibleArgSpecValidator,
|
||||
)
|
||||
from ansible_collections.ansible.utils.plugins.module_utils.common.index_of import index_of
|
||||
from ansible_collections.ansible.utils.plugins.plugin_utils.index_of import index_of
|
||||
|
||||
|
||||
try:
|
||||
|
|
|
@ -324,7 +324,7 @@ from ansible.plugins.lookup import LookupBase
|
|||
from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import (
|
||||
AnsibleArgSpecValidator,
|
||||
)
|
||||
from ansible_collections.ansible.utils.plugins.module_utils.common.index_of import index_of
|
||||
from ansible_collections.ansible.utils.plugins.plugin_utils.index_of import index_of
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
|
|
@ -16,6 +16,7 @@ import json
|
|||
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils.six import integer_types, string_types
|
||||
from jinja2.exceptions import TemplateSyntaxError
|
||||
|
||||
|
||||
# Note, this file can only be used on the control node
|
||||
|
@ -99,19 +100,25 @@ def _run_test(entry, test, right, tests):
|
|||
if not isinstance(right, list) and test == "in":
|
||||
right = [right]
|
||||
|
||||
j2_test = tests.get(test)
|
||||
# JinjaPluginIntercept.get() raises an exception instead of returning None
|
||||
# in ansible-core 2.15+
|
||||
try:
|
||||
j2_test = tests.get(test)
|
||||
except TemplateSyntaxError:
|
||||
j2_test = None
|
||||
|
||||
if not j2_test:
|
||||
msg = "{msg} Error was: the test '{test}' was not found.".format(msg=msg, test=test)
|
||||
_raise_error(msg)
|
||||
else:
|
||||
try:
|
||||
if right is None:
|
||||
result = j2_test(entry)
|
||||
else:
|
||||
result = j2_test(entry, right)
|
||||
except Exception as exc:
|
||||
msg = "{msg} Error was: {error}".format(msg=msg, error=to_native(exc))
|
||||
_raise_error(msg)
|
||||
|
||||
try:
|
||||
if right is None:
|
||||
result = j2_test(entry)
|
||||
else:
|
||||
result = j2_test(entry, right)
|
||||
except Exception as exc:
|
||||
msg = "{msg} Error was: {error}".format(msg=msg, error=to_native(exc))
|
||||
_raise_error(msg)
|
||||
|
||||
if invert:
|
||||
result = not result
|
|
@ -1 +0,0 @@
|
|||
plugins/module_utils/common/index_of.py pylint:ansible-bad-module-import # file's use is limited to filter and lookups on control node
|
|
@ -1 +0,0 @@
|
|||
plugins/module_utils/common/index_of.py pylint:ansible-bad-module-import # file's use is limited to filter and lookups on control node
|
|
@ -1,2 +0,0 @@
|
|||
plugins/module_utils/common/index_of.py pylint:ansible-bad-module-import # file's use is limited to filter and lookups on control node
|
||||
tests/unit/mock/loader.py pylint:arguments-renamed
|
|
@ -1,2 +0,0 @@
|
|||
plugins/module_utils/common/index_of.py pylint:ansible-bad-module-import # file's use is limited to filter and lookups on control node
|
||||
tests/unit/mock/loader.py pylint:arguments-renamed
|
|
@ -1,2 +0,0 @@
|
|||
plugins/module_utils/common/index_of.py pylint:ansible-bad-module-import # file's use is limited to filter and lookups on control node
|
||||
tests/unit/mock/loader.py pylint:arguments-renamed
|
|
@ -1 +0,0 @@
|
|||
plugins/module_utils/common/index_of.py pylint:ansible-bad-module-import # file's use is limited to filter and lookups on control node
|
|
@ -47,12 +47,12 @@ class DictDataLoader(DataLoader):
|
|||
|
||||
# TODO: the real _get_file_contents returns a bytestring, so we actually convert the
|
||||
# unicode/text it's created with to utf-8
|
||||
def _get_file_contents(self, path):
|
||||
path = to_text(path)
|
||||
if path in self._file_mapping:
|
||||
return (to_bytes(self._file_mapping[path]), False)
|
||||
def _get_file_contents(self, file_name):
|
||||
file_name = to_text(file_name)
|
||||
if file_name in self._file_mapping:
|
||||
return (to_bytes(self._file_mapping[file_name]), False)
|
||||
else:
|
||||
raise AnsibleParserError("file not found: %s" % path)
|
||||
raise AnsibleParserError("file not found: %s" % file_name)
|
||||
|
||||
def path_exists(self, path):
|
||||
path = to_text(path)
|
||||
|
|
|
@ -14,7 +14,7 @@ import unittest
|
|||
|
||||
from ansible.template import Templar
|
||||
|
||||
from ansible_collections.ansible.utils.plugins.module_utils.common.index_of import index_of
|
||||
from ansible_collections.ansible.utils.plugins.plugin_utils.index_of import index_of
|
||||
|
||||
|
||||
class TestIndexOfFilter(unittest.TestCase):
|
Loading…
Reference in New Issue