summaryrefslogtreecommitdiffstats
path: root/test/test_load_failure.py
blob: 72112d6a97b6affc3d7083b3adb4af62df38eebe (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
"""Tests for LoadFailureRule."""

import pytest

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


@pytest.mark.parametrize(
    "path",
    (
        pytest.param("examples/broken/encoding.j2", id="jinja2"),
        pytest.param("examples/broken/encoding.yml", id="yaml"),
    ),
)
def test_load_failure_encoding(
    path: str,
    default_rules_collection: RulesCollection,
) -> None:
    """Check that we fail when file encoding is wrong."""
    runner = Runner(path, rules=default_rules_collection)
    matches = runner.run()
    assert len(matches) == 1, matches
    assert matches[0].rule.id == "load-failure"
    assert "'utf-8' codec can't decode byte" in matches[0].message
    assert matches[0].tag == "load-failure[unicodedecodeerror]"