diff --git a/Makefile b/Makefile index 1281b5a..2950d47 100644 --- a/Makefile +++ b/Makefile @@ -20,8 +20,7 @@ test: pytest verify install: @type poetry >/dev/null || pip3 install poetry @type yq || sudo apt-get install -y yq - @poetry install - @echo + @poetry install --no-root format: install poetry run black . diff --git a/plugins/filter/custom_filter.py b/plugins/filter/custom_filter.py index 921d726..607fbf2 100644 --- a/plugins/filter/custom_filter.py +++ b/plugins/filter/custom_filter.py @@ -44,20 +44,21 @@ # pylint: enable=line-too-long import copy -import itertools -import sys import functools +import itertools import re +import sys + import netaddr import yaml - from markupsafe import soft_str if sys.version_info[0] < 3: - from collections import Sequence, defaultdict # pylint: disable=deprecated-class + from collections import Sequence # pylint: disable=deprecated-class + from collections import defaultdict else: - from collections.abc import Sequence from collections import defaultdict + from collections.abc import Sequence def is_hash(d): @@ -677,7 +678,11 @@ def is_any_true(xs): bool: True if any element in the iterable is true, False otherwise. """ - return functools.reduce(lambda x, y: x or y, map(lambda x: bool(x), xs), False) # pylint: disable=unnecessary-lambda + return functools.reduce( + lambda x, y: x or y, + map(lambda x: bool(x), xs), # pylint: disable=unnecessary-lambda + False, + ) def is_all_true(xs): @@ -694,7 +699,11 @@ def is_all_true(xs): This function uses a lambda function in conjunction with functools.reduce for evaluation. """ - return functools.reduce(lambda x, y: x and y, map(lambda x: bool(x), xs), True) # pylint: disable=unnecessary-lambda + return functools.reduce( + lambda x, y: x and y, + map(lambda x: bool(x), xs), # pylint: disable=unnecessary-lambda + True, + ) def search_regex(r, s): @@ -712,7 +721,7 @@ def search_regex(r, s): return bool(re.match(r, s)) -class FilterModule(): +class FilterModule: """ A class encapsulating a collection of jinja2 filters. diff --git a/plugins/test/custom_test.py b/plugins/test/custom_test.py index 1406254..09aa6d9 100644 --- a/plugins/test/custom_test.py +++ b/plugins/test/custom_test.py @@ -69,7 +69,7 @@ def test_property(record=None, regex=".*", prop=""): return None -class TestModule(): +class TestModule: """ A class encapsulating test functions related to network and property validations. diff --git a/tests/test_filter.py b/tests/test_filter.py index 5d5aed6..4db83b3 100644 --- a/tests/test_filter.py +++ b/tests/test_filter.py @@ -1,40 +1,41 @@ -import sys import os +import sys + import pytest sys.path.append(os.path.join(os.path.dirname(sys.path[0]), "plugins", "filter")) print(sys.path) -from custom_filter import ( # noqa: E402 - reverse_record, - filename, - with_ext, +from custom_filter import dict_to_list # noqa: E402 +from custom_filter import ( alias_keys, - merge_dicts, - merge_dicts_reverse, - select_attributes, drop_attributes, - map_format, - merge_item, + filename, + ip_range, + is_all_true, + is_any_true, + is_hash, key_item, - dict_to_list, list_to_dict, - is_hash, - to_dict, - to_kv, - to_safe_yaml, - map_values, map_attributes, - sorted_get, - ip_range, map_flatten, + map_format, + map_group, map_join, + map_values, + merge_dicts, + merge_dicts_reverse, + merge_item, merge_join, - map_group, - is_any_true, - is_all_true, + reverse_record, search_regex, + select_attributes, + sorted_get, + to_dict, + to_kv, + to_safe_yaml, + with_ext, ) @@ -194,7 +195,7 @@ def test_list_to_dict(): ] assert list_to_dict(e, ["a", "b"], False) == { "first": {"a": {"b": "first"}}, - "second": {"a": {"b": "second"}} + "second": {"a": {"b": "second"}}, } with pytest.raises(KeyError): list_to_dict(e, ["a", "c"], False) @@ -433,37 +434,37 @@ def test_map_group(): def test_is_any_true(): - assert is_any_true(["a"]) == True - assert is_any_true([""]) == False - assert is_any_true(["", "a"]) == True - assert is_any_true(["a", ""]) == True - assert is_any_true(["a", "b"]) == True - assert is_any_true([1]) == True - assert is_any_true([0]) == False - assert is_any_true([0, 1]) == True - assert is_any_true([1, 0]) == True - assert is_any_true([1, 2]) == True + assert is_any_true(["a"]) is True + assert is_any_true([""]) is False + assert is_any_true(["", "a"]) is True + assert is_any_true(["a", ""]) is True + assert is_any_true(["a", "b"]) is True + assert is_any_true([1]) is True + assert is_any_true([0]) is False + assert is_any_true([0, 1]) is True + assert is_any_true([1, 0]) is True + assert is_any_true([1, 2]) is True def test_is_all_true(): - assert is_all_true(["a"]) == True - assert is_all_true([""]) == False - assert is_all_true(["", "a"]) == False - assert is_all_true(["a", ""]) == False - assert is_all_true(["a", "b"]) == True - assert is_all_true([1]) == True - assert is_all_true([0]) == False - assert is_all_true([0, 1]) == False - assert is_all_true([1, 0]) == False - assert is_all_true([1, 2]) == True + assert is_all_true(["a"]) is True + assert is_all_true([""]) is False + assert is_all_true(["", "a"]) is False + assert is_all_true(["a", ""]) is False + assert is_all_true(["a", "b"]) is True + assert is_all_true([1]) is True + assert is_all_true([0]) is False + assert is_all_true([0, 1]) is False + assert is_all_true([1, 0]) is False + assert is_all_true([1, 2]) is True def test_search_regex(): - assert search_regex("^$", "") == True - assert search_regex("^[a-z]$", "") == False - assert search_regex("^[a-z]$", "a") == True - assert search_regex("^m", "match") == True - assert search_regex("^h", "match") == False - assert search_regex("^a.*", "abcd") == True - assert search_regex("^.*bc.*", "abcd") == True - assert search_regex("^.*bc.*", "abCd") == False + assert search_regex("^$", "") is True + assert search_regex("^[a-z]$", "") is False + assert search_regex("^[a-z]$", "a") is True + assert search_regex("^m", "match") is True + assert search_regex("^h", "match") is False + assert search_regex("^a.*", "abcd") is True + assert search_regex("^.*bc.*", "abcd") is True + assert search_regex("^.*bc.*", "abCd") is False