summaryrefslogtreecommitdiffstats
path: root/test/test_task_includes.py
blob: 3b02d00ce55e301f5279d5b5a2ba31246d980c1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Tests related to task inclusions."""
import pytest

from ansiblelint.file_utils import Lintable
from ansiblelint.rules import RulesCollection
from ansiblelint.runner import Runner


@pytest.mark.parametrize(
    ("filename", "file_count", "match_count"),
    (
        pytest.param("examples/playbooks/blockincludes.yml", 4, 3, id="blockincludes"),
        pytest.param(
            "examples/playbooks/blockincludes2.yml",
            4,
            3,
            id="blockincludes2",
        ),
        pytest.param("examples/playbooks/taskincludes.yml", 3, 6, id="taskincludes"),
        pytest.param("examples/playbooks/taskimports.yml", 5, 3, id="taskimports"),
        pytest.param(
            "examples/playbooks/include-in-block.yml",
            3,
            1,
            id="include-in-block",
        ),
        pytest.param(
            "examples/playbooks/include-import-tasks-in-role.yml",
            4,
            2,
            id="role_with_task_inclusions",
        ),
    ),
)
def test_included_tasks(
    default_rules_collection: RulesCollection,
    filename: str,
    file_count: int,
    match_count: int,
) -> None:
    """Check if number of loaded files is correct."""
    lintable = Lintable(filename)
    default_rules_collection.options.enable_list = ["name[prefix]"]
    runner = Runner(lintable, rules=default_rules_collection)
    result = runner.run()
    assert len(runner.lintables) == file_count
    assert len(result) == match_count