Skip to content

Commit

Permalink
Apply python autoformat recommendations (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyphreak authored Oct 23, 2024
1 parent ad0c0b2 commit bb6accc
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 63 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
4 changes: 2 additions & 2 deletions galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
namespace: nephelaiio
name: plugins
version: 0.0.5
version: 0.0.6
readme: README.md
authors:
- Ted Cook <[email protected]>
description: Collection packaging of nephelaiio.plugins
license:
- MIT
tags: ['postgresql']
tags: ["postgresql"]
dependencies: {}
repository: https://github.com/nephelaiio/ansible-collection-plugins
documentation: https://github.com/nephelaiio/ansible-collection-plugins
Expand Down
25 changes: 17 additions & 8 deletions plugins/filter/custom_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion plugins/test/custom_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
101 changes: 51 additions & 50 deletions tests/test_filter.py
Original file line number Diff line number Diff line change
@@ -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,
)


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit bb6accc

Please sign in to comment.