Coverage for tests / unit / config / test_execution_config.py: 100%

62 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-04-03 18:53 +0000

1"""Tests for lintro.config.execution_config module.""" 

2 

3from __future__ import annotations 

4 

5import os 

6from unittest.mock import patch 

7 

8import pytest 

9from assertpy import assert_that 

10 

11from lintro.config.execution_config import ExecutionConfig, _get_default_max_workers 

12 

13 

14def test_execution_config_default_enabled_tools() -> None: 

15 """ExecutionConfig has empty enabled_tools by default.""" 

16 config = ExecutionConfig() 

17 assert_that(config.enabled_tools).is_empty() 

18 

19 

20def test_execution_config_default_tool_order() -> None: 

21 """ExecutionConfig uses priority tool order by default.""" 

22 config = ExecutionConfig() 

23 assert_that(config.tool_order).is_equal_to("priority") 

24 

25 

26def test_execution_config_default_fail_fast() -> None: 

27 """ExecutionConfig has fail_fast disabled by default.""" 

28 config = ExecutionConfig() 

29 assert_that(config.fail_fast).is_false() 

30 

31 

32def test_execution_config_default_parallel() -> None: 

33 """ExecutionConfig has parallel enabled by default.""" 

34 config = ExecutionConfig() 

35 assert_that(config.parallel).is_true() 

36 

37 

38def test_execution_config_max_workers_uses_cpu_count() -> None: 

39 """ExecutionConfig max_workers defaults to CPU count.""" 

40 config = ExecutionConfig() 

41 expected = max(1, min(os.cpu_count() or 4, 32)) 

42 assert_that(config.max_workers).is_equal_to(expected) 

43 

44 

45def test_execution_config_set_enabled_tools() -> None: 

46 """ExecutionConfig accepts enabled_tools list.""" 

47 config = ExecutionConfig(enabled_tools=["ruff", "black"]) 

48 assert_that(config.enabled_tools).contains("ruff", "black") 

49 

50 

51def test_execution_config_tool_order_alphabetical() -> None: 

52 """ExecutionConfig accepts alphabetical tool order.""" 

53 config = ExecutionConfig(tool_order="alphabetical") 

54 assert_that(config.tool_order).is_equal_to("alphabetical") 

55 

56 

57def test_execution_config_tool_order_custom_list() -> None: 

58 """ExecutionConfig accepts custom tool order list.""" 

59 config = ExecutionConfig(tool_order=["black", "ruff", "mypy"]) 

60 assert_that(config.tool_order).is_equal_to(["black", "ruff", "mypy"]) 

61 

62 

63def test_execution_config_set_fail_fast() -> None: 

64 """ExecutionConfig accepts fail_fast=True.""" 

65 config = ExecutionConfig(fail_fast=True) 

66 assert_that(config.fail_fast).is_true() 

67 

68 

69def test_execution_config_set_parallel_false() -> None: 

70 """ExecutionConfig accepts parallel=False.""" 

71 config = ExecutionConfig(parallel=False) 

72 assert_that(config.parallel).is_false() 

73 

74 

75def test_execution_config_set_max_workers() -> None: 

76 """ExecutionConfig accepts custom max_workers.""" 

77 config = ExecutionConfig(max_workers=8) 

78 assert_that(config.max_workers).is_equal_to(8) 

79 

80 

81def test_execution_config_max_workers_minimum() -> None: 

82 """ExecutionConfig enforces minimum max_workers of 1.""" 

83 with pytest.raises(ValueError, match="greater than or equal to 1"): 

84 ExecutionConfig(max_workers=0) 

85 

86 

87def test_execution_config_max_workers_maximum() -> None: 

88 """ExecutionConfig enforces maximum max_workers of 32.""" 

89 with pytest.raises(ValueError, match="less than or equal to 32"): 

90 ExecutionConfig(max_workers=100) 

91 

92 

93def test_get_default_max_workers_returns_cpu_count() -> None: 

94 """_get_default_max_workers returns CPU count clamped to 1-32.""" 

95 result = _get_default_max_workers() 

96 expected = max(1, min(os.cpu_count() or 4, 32)) 

97 assert_that(result).is_equal_to(expected) 

98 

99 

100def test_get_default_max_workers_handles_none_cpu_count() -> None: 

101 """_get_default_max_workers handles None cpu_count.""" 

102 with patch.object(os, "cpu_count", return_value=None): 

103 result = _get_default_max_workers() 

104 assert_that(result).is_equal_to(4) 

105 

106 

107def test_get_default_max_workers_clamps_high_count() -> None: 

108 """_get_default_max_workers clamps high CPU counts to 32.""" 

109 with patch.object(os, "cpu_count", return_value=64): 

110 result = _get_default_max_workers() 

111 assert_that(result).is_equal_to(32) 

112 

113 

114def test_get_default_max_workers_fallback_on_zero() -> None: 

115 """_get_default_max_workers falls back to 4 when cpu_count returns 0.""" 

116 # 0 is falsy in Python, so `os.cpu_count() or 4` returns 4 

117 with patch.object(os, "cpu_count", return_value=0): 

118 result = _get_default_max_workers() 

119 assert_that(result).is_equal_to(4)