Coverage for tests / unit / config / test_unified_config.py: 100%
42 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 the unified configuration manager."""
3from __future__ import annotations
5import pytest
6from assertpy import assert_that
8from lintro.utils.unified_config import (
9 DEFAULT_TOOL_PRIORITIES,
10 GLOBAL_SETTINGS,
11 ToolConfigInfo,
12 ToolOrderStrategy,
13 is_tool_injectable,
14)
17@pytest.mark.parametrize(
18 ("strategy", "expected_value"),
19 [
20 (ToolOrderStrategy.PRIORITY, "priority"),
21 (ToolOrderStrategy.CUSTOM, "custom"),
22 (ToolOrderStrategy.ALPHABETICAL, "alphabetical"),
23 ],
24 ids=["priority", "custom", "alphabetical"],
25)
26def test_tool_order_strategy_values(
27 strategy: ToolOrderStrategy,
28 expected_value: str,
29) -> None:
30 """Verify ToolOrderStrategy enum members have expected string values.
32 Args:
33 strategy: The ToolOrderStrategy enum member to test.
34 expected_value: The expected string value.
35 """
36 assert_that(strategy.value).is_equal_to(expected_value)
39def test_default_values() -> None:
40 """Verify default values are set correctly."""
41 info = ToolConfigInfo(tool_name="ruff")
43 assert_that(info.tool_name).is_equal_to("ruff")
44 assert_that(info.native_config).is_equal_to({})
45 assert_that(info.lintro_tool_config).is_equal_to({})
46 assert_that(info.effective_config).is_equal_to({})
47 assert_that(info.warnings).is_equal_to([])
48 assert_that(info.is_injectable).is_true()
51def test_line_length_setting_exists() -> None:
52 """Verify line_length setting is defined."""
53 assert_that(GLOBAL_SETTINGS).contains("line_length")
56def test_line_length_has_tools() -> None:
57 """Verify line_length has tool mappings."""
58 assert_that(GLOBAL_SETTINGS["line_length"]).contains("tools")
59 tools = GLOBAL_SETTINGS["line_length"]["tools"]
61 assert_that(
62 tools,
63 ).contains("ruff")
64 assert_that(
65 tools,
66 ).contains("black")
67 assert_that(tools).contains("markdownlint")
68 assert_that(tools).contains("yamllint")
71def test_line_length_has_injectable_tools() -> None:
72 """Verify injectable tools are defined."""
73 assert_that(GLOBAL_SETTINGS["line_length"]).contains("injectable")
74 injectable = GLOBAL_SETTINGS["line_length"]["injectable"]
76 assert_that(injectable).contains("ruff")
77 assert_that(injectable).contains("black")
78 assert_that(injectable).contains("markdownlint")
79 # yamllint is injectable via Lintro config generation
80 assert_that(injectable).contains("yamllint")
83def test_formatters_have_lower_priority_than_linters() -> None:
84 """Formatters should run before linters (lower priority value)."""
85 assert_that(DEFAULT_TOOL_PRIORITIES["black"]).is_less_than(
86 DEFAULT_TOOL_PRIORITIES["ruff"],
87 )
88 assert_that(DEFAULT_TOOL_PRIORITIES["black"]).is_less_than(
89 DEFAULT_TOOL_PRIORITIES["markdownlint"],
90 )
93def test_pytest_runs_last() -> None:
94 """Pytest should have highest priority value (runs last)."""
95 pytest_priority = DEFAULT_TOOL_PRIORITIES["pytest"]
96 for tool, priority in DEFAULT_TOOL_PRIORITIES.items():
97 if tool != "pytest":
98 assert_that(priority).is_less_than(pytest_priority)
101@pytest.mark.parametrize(
102 "tool_name",
103 ["ruff", "markdownlint", "yamllint", "black"],
104 ids=["ruff", "markdownlint", "yamllint", "black"],
105)
106def test_tool_is_injectable(tool_name: str) -> None:
107 """Verify tools that support config injection.
109 Args:
110 tool_name: Name of the tool to check for injectability.
111 """
112 assert_that(is_tool_injectable(tool_name)).is_true()