Skip to content

Commit

Permalink
Remove a duplicated function is_nested_task() (#2162)
Browse files Browse the repository at this point in the history
  • Loading branch information
nishipy authored May 19, 2022
1 parent 3435de7 commit 9cc2a95
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:TOX_PARALLEL_NO_SPINNER
# Number of expected test passes, safety measure for accidental skip of
# tests. Update value if you add/remove tests.
PYTEST_REQPASS: 652
PYTEST_REQPASS: 650

steps:
- name: Activate WSL1
Expand Down
10 changes: 1 addition & 9 deletions src/ansiblelint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
from ansiblelint.constants import NESTED_TASK_KEYS, PLAYBOOK_TASK_KEYWORDS, FileType
from ansiblelint.errors import MatchError
from ansiblelint.file_utils import Lintable, discover_lintables
from ansiblelint.skip_utils import is_nested_task
from ansiblelint.text import removeprefix

# ansible-lint doesn't need/want to know about encrypted secrets, so we pass a
Expand Down Expand Up @@ -897,12 +898,3 @@ def nested_items(
yield "list-item", item, parent
for k, v, returned_parent in nested_items(item):
yield k, v, returned_parent


def is_nested_task(task: Dict[str, Any]) -> bool:
"""Check if task includes block/always/rescue."""
for key in NESTED_TASK_KEYS:
if task.get(key):
return True

return False
38 changes: 0 additions & 38 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,41 +409,3 @@ def test_nested_items() -> None:
match=r"Call to deprecated function ansiblelint\.utils\.nested_items.*"
):
assert list(utils.nested_items(data)) == items


@pytest.mark.parametrize(
("task", "expected"),
(
pytest.param(
dict(
name="ensure apache is at the latest version",
yum={"name": "httpd", "state": "latest"},
),
False,
),
pytest.param(
dict(
name="Attempt and graceful roll back",
block=[
{"name": "Force a failure", "ansible.builtin.command": "/bin/false"}
],
rescue=[
{
"name": "Force a failure in middle of recovery!",
"ansible.builtin.command": "/bin/false",
}
],
always=[
{
"name": "Always do this",
"ansible.builtin.debug": {"msg": "This always executes"},
}
],
),
True,
),
),
)
def test_is_nested_task(task: Dict[str, Any], expected: bool) -> None:
"""Test is_nested_task() returns expected bool."""
assert utils.is_nested_task(task) == expected

0 comments on commit 9cc2a95

Please sign in to comment.