Coverage for tests / unit / utils / config / test_manager_core.py: 100%
61 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"""Unit tests for UnifiedConfigManager initialization, refresh, and getter methods."""
3from __future__ import annotations
5from unittest.mock import patch
7from assertpy import assert_that
9from lintro.utils.unified_config import (
10 ToolConfigInfo,
11 UnifiedConfigManager,
12)
14# =============================================================================
15# Tests for UnifiedConfigManager initialization
16# =============================================================================
19def test_manager_initialization_loads_global_config() -> None:
20 """Verify manager loads global config during initialization.
22 The manager should call load_lintro_global_config and store the result.
23 """
24 with (
25 patch(
26 "lintro.utils.unified_config_manager.load_lintro_global_config",
27 return_value={"line_length": 100},
28 ),
29 patch(
30 "lintro.utils.unified_config_manager.get_tool_config_summary",
31 return_value={},
32 ),
33 patch(
34 "lintro.utils.unified_config_manager.validate_config_consistency",
35 return_value=[],
36 ),
37 ):
38 manager = UnifiedConfigManager()
40 assert_that(manager.global_config).is_equal_to({"line_length": 100})
43def test_manager_initialization_loads_tool_configs() -> None:
44 """Verify manager loads tool configs during initialization.
46 The manager should call get_tool_config_summary and store the result.
47 """
48 tool_configs = {"ruff": ToolConfigInfo(tool_name="ruff")}
49 with (
50 patch(
51 "lintro.utils.unified_config_manager.load_lintro_global_config",
52 return_value={},
53 ),
54 patch(
55 "lintro.utils.unified_config_manager.get_tool_config_summary",
56 return_value=tool_configs,
57 ),
58 patch(
59 "lintro.utils.unified_config_manager.validate_config_consistency",
60 return_value=[],
61 ),
62 ):
63 manager = UnifiedConfigManager()
65 assert_that(manager.tool_configs).contains_key("ruff")
68def test_manager_initialization_loads_warnings() -> None:
69 """Verify manager loads config warnings during initialization.
71 The manager should call validate_config_consistency and store warnings.
72 """
73 warnings = ["Warning: config mismatch"]
74 with (
75 patch(
76 "lintro.utils.unified_config_manager.load_lintro_global_config",
77 return_value={},
78 ),
79 patch(
80 "lintro.utils.unified_config_manager.get_tool_config_summary",
81 return_value={},
82 ),
83 patch(
84 "lintro.utils.unified_config_manager.validate_config_consistency",
85 return_value=warnings,
86 ),
87 ):
88 manager = UnifiedConfigManager()
90 assert_that(manager.warnings).is_length(1)
91 assert_that(manager.warnings[0]).contains("Warning")
94# =============================================================================
95# Tests for refresh method
96# =============================================================================
99def test_manager_refresh_reloads_all_config(manager: UnifiedConfigManager) -> None:
100 """Verify refresh method reloads all configuration.
102 After refresh, the manager should have updated config from all sources.
105 Args:
106 manager: Configuration manager instance.
107 """
108 with (
109 patch(
110 "lintro.utils.unified_config_manager.load_lintro_global_config",
111 return_value={"line_length": 120},
112 ),
113 patch(
114 "lintro.utils.unified_config_manager.get_tool_config_summary",
115 return_value={"black": ToolConfigInfo(tool_name="black")},
116 ),
117 patch(
118 "lintro.utils.unified_config_manager.validate_config_consistency",
119 return_value=["New warning"],
120 ),
121 ):
122 manager.refresh()
124 assert_that(manager.global_config).is_equal_to({"line_length": 120})
125 assert_that(manager.tool_configs).contains_key("black")
126 assert_that(manager.warnings).is_length(1)
129def test_manager_refresh_does_not_raise(manager: UnifiedConfigManager) -> None:
130 """Verify refresh completes without raising exceptions.
132 Even with default mocks, refresh should complete successfully.
135 Args:
136 manager: Configuration manager instance.
137 """
138 with (
139 patch(
140 "lintro.utils.unified_config_manager.load_lintro_global_config",
141 return_value={},
142 ),
143 patch(
144 "lintro.utils.unified_config_manager.get_tool_config_summary",
145 return_value={},
146 ),
147 patch(
148 "lintro.utils.unified_config_manager.validate_config_consistency",
149 return_value=[],
150 ),
151 ):
152 # Should not raise
153 manager.refresh()
156# =============================================================================
157# Tests for get_effective_line_length method
158# =============================================================================
161def test_manager_get_effective_line_length_delegates_to_module_function(
162 manager: UnifiedConfigManager,
163) -> None:
164 """Verify get_effective_line_length delegates to the module function.
166 The manager method should call the standalone get_effective_line_length
167 function and return its result.
170 Args:
171 manager: Configuration manager instance.
172 """
173 with patch(
174 "lintro.utils.unified_config_manager.get_effective_line_length",
175 return_value=120,
176 ):
177 result = manager.get_effective_line_length("ruff")
179 assert_that(result).is_equal_to(120)
182def test_manager_get_effective_line_length_returns_none_when_not_configured(
183 manager: UnifiedConfigManager,
184) -> None:
185 """Verify None is returned when no line length is configured.
187 When the underlying function returns None, the manager should too.
190 Args:
191 manager: Configuration manager instance.
192 """
193 with patch(
194 "lintro.utils.unified_config_manager.get_effective_line_length",
195 return_value=None,
196 ):
197 result = manager.get_effective_line_length("unknown")
199 assert_that(result).is_none()
202# =============================================================================
203# Tests for get_tool_config method
204# =============================================================================
207def test_manager_get_tool_config_returns_existing_config(
208 mock_manager_dependencies: None,
209) -> None:
210 """Verify get_tool_config returns existing tool config if present.
212 When a tool is already in tool_configs, it should be returned directly.
214 Args:
215 mock_manager_dependencies: Mock manager dependencies.
216 """
217 tool_info = ToolConfigInfo(tool_name="ruff", is_injectable=True)
218 with (
219 patch(
220 "lintro.utils.unified_config_manager.load_lintro_global_config",
221 return_value={},
222 ),
223 patch(
224 "lintro.utils.unified_config_manager.get_tool_config_summary",
225 return_value={"ruff": tool_info},
226 ),
227 patch(
228 "lintro.utils.unified_config_manager.validate_config_consistency",
229 return_value=[],
230 ),
231 ):
232 manager = UnifiedConfigManager()
233 result = manager.get_tool_config("ruff")
235 assert_that(result.tool_name).is_equal_to("ruff")
238def test_manager_get_tool_config_creates_config_for_missing_tool(
239 manager: UnifiedConfigManager,
240) -> None:
241 """Verify get_tool_config creates config for unknown tools.
243 When requesting config for a tool not in tool_configs, a new
244 ToolConfigInfo should be created with loaded native config.
247 Args:
248 manager: Configuration manager instance.
249 """
250 with (
251 patch(
252 "lintro.utils.unified_config_manager._load_native_tool_config",
253 return_value={"option": "value"},
254 ),
255 patch(
256 "lintro.utils.unified_config_manager.load_lintro_tool_config",
257 return_value={},
258 ),
259 ):
260 result = manager.get_tool_config("custom_tool")
262 assert_that(result).is_instance_of(ToolConfigInfo)
263 assert_that(result.tool_name).is_equal_to("custom_tool")
264 assert_that(result.native_config).is_equal_to({"option": "value"})
267def test_manager_get_tool_config_caches_created_config(
268 manager: UnifiedConfigManager,
269) -> None:
270 """Verify newly created tool configs are cached.
272 After get_tool_config creates a config, it should be stored in tool_configs.
275 Args:
276 manager: Configuration manager instance.
277 """
278 with (
279 patch(
280 "lintro.utils.unified_config_manager._load_native_tool_config",
281 return_value={},
282 ),
283 patch(
284 "lintro.utils.unified_config_manager.load_lintro_tool_config",
285 return_value={},
286 ),
287 ):
288 manager.get_tool_config("new_tool")
290 assert_that(manager.tool_configs).contains_key("new_tool")
293# =============================================================================
294# Tests for get_ordered_tools method
295# =============================================================================
298def test_manager_get_ordered_tools_delegates_to_module_function(
299 manager: UnifiedConfigManager,
300) -> None:
301 """Verify get_ordered_tools delegates to the module function.
303 The manager method should call the standalone get_ordered_tools
304 function and return its result.
307 Args:
308 manager: Configuration manager instance.
309 """
310 with patch(
311 "lintro.utils.unified_config_manager.get_ordered_tools",
312 return_value=["a", "b"],
313 ):
314 result = manager.get_ordered_tools(["b", "a"])
316 assert_that(result).is_equal_to(["a", "b"])
319def test_manager_get_ordered_tools_maintains_order(
320 manager: UnifiedConfigManager,
321) -> None:
322 """Verify get_ordered_tools returns tools in priority order by default.
324 Without custom ordering, tools should be sorted by their default priorities.
327 Args:
328 manager: Configuration manager instance.
329 """
330 with patch(
331 "lintro.utils.unified_config_manager.get_ordered_tools",
332 return_value=["prettier", "black", "ruff"],
333 ):
334 result = manager.get_ordered_tools(["ruff", "black", "prettier"])
336 assert_that(result[0]).is_equal_to("prettier")
337 assert_that(result).is_length(3)