From ac8f50fcccc31aec4c6a5263b0277e8a3f391fff Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 12 Dec 2024 12:47:40 +0100 Subject: [PATCH] Adding plugins/test/tests.py and moving filter plugins to plugins/filter. --- playbooks/filter_plugins | 2 +- playbooks/test_plugins | 1 + .../filter}/cfg_389ds_to_dict.py | 0 .../filter}/compare_lc_list.py | 0 plugins/test/tests.py | 37 +++++++++++++++++++ 5 files changed, 39 insertions(+), 1 deletion(-) create mode 120000 playbooks/test_plugins rename {filter_plugins => plugins/filter}/cfg_389ds_to_dict.py (100%) rename {filter_plugins => plugins/filter}/compare_lc_list.py (100%) create mode 100644 plugins/test/tests.py diff --git a/playbooks/filter_plugins b/playbooks/filter_plugins index c954752..72b6fa6 120000 --- a/playbooks/filter_plugins +++ b/playbooks/filter_plugins @@ -1 +1 @@ -../filter_plugins/ \ No newline at end of file +../plugins/filter \ No newline at end of file diff --git a/playbooks/test_plugins b/playbooks/test_plugins new file mode 120000 index 0000000..cddf7f9 --- /dev/null +++ b/playbooks/test_plugins @@ -0,0 +1 @@ +../plugins/test \ No newline at end of file diff --git a/filter_plugins/cfg_389ds_to_dict.py b/plugins/filter/cfg_389ds_to_dict.py similarity index 100% rename from filter_plugins/cfg_389ds_to_dict.py rename to plugins/filter/cfg_389ds_to_dict.py diff --git a/filter_plugins/compare_lc_list.py b/plugins/filter/compare_lc_list.py similarity index 100% rename from filter_plugins/compare_lc_list.py rename to plugins/filter/compare_lc_list.py diff --git a/plugins/test/tests.py b/plugins/test/tests.py new file mode 100644 index 0000000..112ad4b --- /dev/null +++ b/plugins/test/tests.py @@ -0,0 +1,37 @@ +# Copyright (c) 2020 Matthias Dellweg +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + + +import typing as t + +from jinja2.runtime import Undefined + + +def empty_test(value: t.Any) -> bool: + """ + Check whether a value is false or an empty string, list or dict. + """ + if isinstance(value, Undefined): + return True + if isinstance(value, bool): + return not value + if value is None: + return True + if value == "": + return True + if value == []: + return True + if value == {}: + return True + if value == b"": + return True + return False + + +class TestModule: + def tests(self) -> t.Dict[str, t.Callable]: + return { + "empty": empty_test, + } + +# last line -- 2.39.5