From ea55dddc6a826ecd6619c68fb3c68cb4beac3ecf Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Thu, 4 Apr 2024 12:23:18 -0700 Subject: [PATCH] Remove deprecated 'loader' argument (#82968) * remove deprecated 'loader' argument from listify_lookup_plugin_terms API Fixes: #82949 Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/listify.yml | 3 ++ lib/ansible/utils/listify.py | 6 +--- test/sanity/ignore.txt | 1 - test/units/utils/test_listify.py | 51 ++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/listify.yml create mode 100644 test/units/utils/test_listify.py diff --git a/changelogs/fragments/listify.yml b/changelogs/fragments/listify.yml new file mode 100644 index 00000000000..c77458bcc5d --- /dev/null +++ b/changelogs/fragments/listify.yml @@ -0,0 +1,3 @@ +--- +removed_features: + - utils/listify - remove deprecated 'loader' argument from listify_lookup_plugin_terms API (https://github.com/ansible/ansible/issues/82949). diff --git a/lib/ansible/utils/listify.py b/lib/ansible/utils/listify.py index 362a50ba1f1..45d18033f6b 100644 --- a/lib/ansible/utils/listify.py +++ b/lib/ansible/utils/listify.py @@ -27,11 +27,7 @@ display = Display() __all__ = ['listify_lookup_plugin_terms'] -def listify_lookup_plugin_terms(terms, templar, loader=None, fail_on_undefined=True, convert_bare=False): - - if loader is not None: - display.deprecated('"listify_lookup_plugin_terms" does not use "dataloader" anymore, the ability to pass it in will be removed in future versions.', - version='2.18') +def listify_lookup_plugin_terms(terms, templar, fail_on_undefined=True, convert_bare=False): if isinstance(terms, string_types): terms = templar.template(terms.strip(), convert_bare=convert_bare, fail_on_undefined=fail_on_undefined) diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index b5e0f43f8ea..7a74a97b4e3 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -202,5 +202,4 @@ lib/ansible/playbook/play_context.py pylint:ansible-deprecated-version # 2.18 d lib/ansible/plugins/action/__init__.py pylint:ansible-deprecated-version # 2.18 deprecation lib/ansible/plugins/loader.py pylint:ansible-deprecated-version # 2.18 deprecation lib/ansible/template/__init__.py pylint:ansible-deprecated-version # 2.18 deprecation -lib/ansible/utils/listify.py pylint:ansible-deprecated-version # 2.18 deprecation lib/ansible/vars/manager.py pylint:ansible-deprecated-version # 2.18 deprecation diff --git a/test/units/utils/test_listify.py b/test/units/utils/test_listify.py new file mode 100644 index 00000000000..0d827ced62f --- /dev/null +++ b/test/units/utils/test_listify.py @@ -0,0 +1,51 @@ +# Copyright: Contributors to the Ansible project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import annotations + +import pytest + +from ansible.template import Templar +from ansible.utils.listify import listify_lookup_plugin_terms + +from units.mock.loader import DictDataLoader + + +@pytest.mark.parametrize( + ("test_input", "expected"), + [ + pytest.param( + [], + [], + id="empty-list", + ), + pytest.param( + "foo", + ["foo"], + id="string-types", + ), + pytest.param( + ["foo"], + ["foo"], + id="list-types", + ), + ], +) +def test_listify_lookup_plugin_terms(test_input, expected): + fake_loader = DictDataLoader({}) + templar = Templar(loader=fake_loader) + + terms = listify_lookup_plugin_terms( + test_input, templar=templar, fail_on_undefined=False + ) + assert terms == expected + + +def test_negative_listify_lookup_plugin_terms(): + fake_loader = DictDataLoader({}) + templar = Templar(loader=fake_loader) + + with pytest.raises(TypeError, match=".*got an unexpected keyword argument 'loader'"): + listify_lookup_plugin_terms( + "foo", templar=templar, loader=fake_loader, fail_on_undefined=False + )