Coverage for tests / unit / utils / native_parsers / test_yamllint_config.py: 100%
29 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Tests for _load_native_tool_config with yamllint."""
3from __future__ import annotations
5from pathlib import Path
6from unittest.mock import MagicMock, patch
8from assertpy import assert_that
10from lintro.utils.native_parsers import _load_native_tool_config
13def test_load_yamllint_config_from_file(
14 mock_empty_pyproject: MagicMock,
15 temp_cwd: Path,
16) -> None:
17 """Load yamllint config from .yamllint file in current directory.
19 Args:
20 mock_empty_pyproject: Mock for empty pyproject.toml.
21 temp_cwd: Temporary current working directory.
22 """
23 config_file = temp_cwd / ".yamllint"
24 config_file.write_text("rules:\n line-length: 120\n")
25 result = _load_native_tool_config("yamllint")
26 assert_that(result).is_equal_to({"rules": {"line-length": 120}})
29def test_load_yamllint_config_yaml_not_installed(
30 mock_empty_pyproject: MagicMock,
31 temp_cwd: Path,
32) -> None:
33 """Return empty dict when yaml module is not available.
35 Args:
36 mock_empty_pyproject: Mock for empty pyproject.toml.
37 temp_cwd: Temporary current working directory.
38 """
39 config_file = temp_cwd / ".yamllint"
40 config_file.write_text("rules:\n line-length: 120\n")
41 with patch("lintro.utils.native_parsers.yaml", None):
42 result = _load_native_tool_config("yamllint")
43 assert_that(result).is_empty()
46def test_load_yamllint_config_no_config_file(
47 mock_empty_pyproject: MagicMock,
48 temp_cwd: Path,
49) -> None:
50 """Return empty dict when no yamllint config file exists.
52 Args:
53 mock_empty_pyproject: Mock for empty pyproject.toml.
54 temp_cwd: Temporary current working directory.
55 """
56 result = _load_native_tool_config("yamllint")
57 assert_that(result).is_empty()
60def test_load_yamllint_config_invalid_yaml(
61 mock_empty_pyproject: MagicMock,
62 temp_cwd: Path,
63) -> None:
64 """Return empty dict when yamllint config contains invalid YAML.
66 Args:
67 mock_empty_pyproject: Mock for empty pyproject.toml.
68 temp_cwd: Temporary current working directory.
69 """
70 config_file = temp_cwd / ".yamllint"
71 config_file.write_text("invalid: yaml: content: [")
72 result = _load_native_tool_config("yamllint")
73 assert_that(result).is_empty()
76def test_load_yamllint_config_unicode_content(
77 mock_empty_pyproject: MagicMock,
78 temp_cwd: Path,
79) -> None:
80 """Load yamllint config with Unicode characters in values.
82 Args:
83 mock_empty_pyproject: Mock for empty pyproject.toml.
84 temp_cwd: Temporary current working directory.
85 """
86 config_file = temp_cwd / ".yamllint"
87 config_file.write_text("rules:\n comments: 日本語\n")
88 result = _load_native_tool_config("yamllint")
89 assert_that(result["rules"]["comments"]).is_equal_to("日本語")