Clean up test failures (#216)

* Fix arguments-renamed

* Handle changed behavior in 2.15
pull/210/head
Kate Case 2022-10-13 11:01:42 -04:00 committed by GitHub
parent 57c5cd4336
commit 462e4e7f71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 28 additions and 27 deletions

View File

@ -0,0 +1,3 @@
---
trivial:
- Fix various 2.15 sanity and unit tests. (https://github.com/ansible-collections/ansible.utils/pull/216)

View File

@ -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:

View File

@ -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):

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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):