Coverage for tests / unit / utils / unified_config / test_line_length.py: 100%

32 statements  

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

1"""Tests for get_effective_line_length function.""" 

2 

3from __future__ import annotations 

4 

5from unittest.mock import patch 

6 

7from assertpy import assert_that 

8 

9from lintro.utils.unified_config import get_effective_line_length 

10 

11 

12def test_get_effective_line_length_from_tool_config() -> None: 

13 """Verify line_length from tool-specific lintro config has highest priority.""" 

14 with patch( 

15 "lintro.utils.config_priority.load_lintro_tool_config", 

16 return_value={"line_length": 100}, 

17 ): 

18 result = get_effective_line_length("ruff") 

19 assert_that(result).is_equal_to(100) 

20 

21 

22def test_get_effective_line_length_from_tool_config_hyphen_key() -> None: 

23 """Verify line-length (hyphenated) key is also supported in tool config.""" 

24 with patch( 

25 "lintro.utils.config_priority.load_lintro_tool_config", 

26 return_value={"line-length": 120}, 

27 ): 

28 result = get_effective_line_length("ruff") 

29 assert_that(result).is_equal_to(120) 

30 

31 

32def test_get_effective_line_length_from_global_config() -> None: 

33 """Verify global lintro config is used when tool config is empty.""" 

34 with ( 

35 patch("lintro.utils.config_priority.load_lintro_tool_config", return_value={}), 

36 patch( 

37 "lintro.utils.config_priority.load_lintro_global_config", 

38 return_value={"line_length": 80}, 

39 ), 

40 ): 

41 result = get_effective_line_length("ruff") 

42 assert_that(result).is_equal_to(80) 

43 

44 

45def test_get_effective_line_length_from_global_config_hyphen_key() -> None: 

46 """Verify line-length (hyphenated) key is also supported in global config.""" 

47 with ( 

48 patch("lintro.utils.config_priority.load_lintro_tool_config", return_value={}), 

49 patch( 

50 "lintro.utils.config_priority.load_lintro_global_config", 

51 return_value={"line-length": 90}, 

52 ), 

53 ): 

54 result = get_effective_line_length("ruff") 

55 assert_that(result).is_equal_to(90) 

56 

57 

58def test_get_effective_line_length_from_ruff_config() -> None: 

59 """Verify Ruff config in pyproject.toml is used as fallback.""" 

60 with ( 

61 patch("lintro.utils.config_priority.load_lintro_tool_config", return_value={}), 

62 patch( 

63 "lintro.utils.config_priority.load_lintro_global_config", 

64 return_value={}, 

65 ), 

66 patch( 

67 "lintro.utils.config_priority.load_pyproject", 

68 return_value={"tool": {"ruff": {"line-length": 88}}}, 

69 ), 

70 ): 

71 result = get_effective_line_length("black") 

72 assert_that(result).is_equal_to(88) 

73 

74 

75def test_get_effective_line_length_from_ruff_config_underscore_key() -> None: 

76 """Verify line_length (underscore) key is also supported in Ruff config.""" 

77 with ( 

78 patch("lintro.utils.config_priority.load_lintro_tool_config", return_value={}), 

79 patch( 

80 "lintro.utils.config_priority.load_lintro_global_config", 

81 return_value={}, 

82 ), 

83 patch( 

84 "lintro.utils.config_priority.load_pyproject", 

85 return_value={"tool": {"ruff": {"line_length": 95}}}, 

86 ), 

87 ): 

88 result = get_effective_line_length("black") 

89 assert_that(result).is_equal_to(95) 

90 

91 

92def test_get_effective_line_length_returns_none_when_no_config() -> None: 

93 """Verify None is returned when no line length is configured anywhere.""" 

94 with ( 

95 patch( 

96 "lintro.utils.config_priority.load_lintro_tool_config", 

97 return_value={}, 

98 ), 

99 patch( 

100 "lintro.utils.config_priority.load_lintro_global_config", 

101 return_value={}, 

102 ), 

103 patch( 

104 "lintro.utils.config_priority.load_pyproject", 

105 return_value={}, 

106 ), 

107 ): 

108 result = get_effective_line_length("unknown_tool") 

109 assert_that(result).is_none()