Coverage for tests / unit / utils / test_enums_and_normalizers.py: 100%

45 statements  

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

1"""Tests for enums and normalizer functions.""" 

2 

3import pytest 

4from assertpy import assert_that 

5 

6from lintro.enums.group_by import GroupBy, normalize_group_by 

7from lintro.enums.hadolint_enums import ( 

8 HadolintFailureThreshold, 

9 HadolintFormat, 

10 normalize_hadolint_format, 

11 normalize_hadolint_threshold, 

12) 

13from lintro.enums.output_format import OutputFormat, normalize_output_format 

14from lintro.enums.tool_name import ToolName, normalize_tool_name 

15from lintro.enums.tool_order import ToolOrder, normalize_tool_order 

16from lintro.enums.yamllint_format import YamllintFormat, normalize_yamllint_format 

17 

18 

19def test_output_format_normalization() -> None: 

20 """Normalize output format strings and enum instances consistently.""" 

21 assert_that(normalize_output_format("grid")).is_equal_to(OutputFormat.GRID) 

22 assert_that(normalize_output_format(OutputFormat.JSON)).is_equal_to( 

23 OutputFormat.JSON, 

24 ) 

25 assert_that(normalize_output_format("unknown")).is_equal_to(OutputFormat.GRID) 

26 

27 

28def test_group_by_normalization() -> None: 

29 """Normalize group-by strings and enum instances consistently.""" 

30 assert_that(normalize_group_by("file")).is_equal_to(GroupBy.FILE) 

31 assert_that(normalize_group_by(GroupBy.AUTO)).is_equal_to(GroupBy.AUTO) 

32 assert_that(normalize_group_by("bad")).is_equal_to(GroupBy.FILE) 

33 

34 

35def test_tool_name_normalization() -> None: 

36 """Normalize tool names from strings and enum instances.""" 

37 assert_that(normalize_tool_name("ruff")).is_equal_to(ToolName.RUFF) 

38 assert_that(normalize_tool_name(ToolName.RUFF)).is_equal_to(ToolName.RUFF) 

39 

40 

41def test_yamllint_format_normalization() -> None: 

42 """Normalize yamllint format values from strings and enums.""" 

43 assert_that(normalize_yamllint_format("parsable")).is_equal_to( 

44 YamllintFormat.PARSABLE, 

45 ) 

46 assert_that(normalize_yamllint_format(YamllintFormat.GITHUB)).is_equal_to( 

47 YamllintFormat.GITHUB, 

48 ) 

49 

50 

51def test_hadolint_normalization() -> None: 

52 """Normalize hadolint format and threshold string values.""" 

53 assert_that(normalize_hadolint_format("json")).is_equal_to(HadolintFormat.JSON) 

54 assert_that(normalize_hadolint_threshold("warning")).is_equal_to( 

55 HadolintFailureThreshold.WARNING, 

56 ) 

57 assert_that(normalize_hadolint_format("bogus")).is_equal_to(HadolintFormat.TTY) 

58 assert_that(normalize_hadolint_threshold("bogus")).is_equal_to( 

59 HadolintFailureThreshold.INFO, 

60 ) 

61 

62 

63def test_tool_order_enum_values() -> None: 

64 """Test ToolOrder enum has expected values.""" 

65 assert_that(ToolOrder.PRIORITY.value).is_equal_to("PRIORITY") 

66 assert_that(ToolOrder.ALPHABETICAL.value).is_equal_to("ALPHABETICAL") 

67 assert_that(ToolOrder.CUSTOM.value).is_equal_to("CUSTOM") 

68 

69 

70def test_tool_order_normalization_from_string() -> None: 

71 """Normalize tool order strings to enum values.""" 

72 assert_that(normalize_tool_order("priority")).is_equal_to(ToolOrder.PRIORITY) 

73 assert_that(normalize_tool_order("ALPHABETICAL")).is_equal_to( 

74 ToolOrder.ALPHABETICAL, 

75 ) 

76 assert_that(normalize_tool_order("Custom")).is_equal_to(ToolOrder.CUSTOM) 

77 

78 

79def test_tool_order_normalization_from_enum() -> None: 

80 """Pass-through enum instances unchanged.""" 

81 assert_that(normalize_tool_order(ToolOrder.PRIORITY)).is_equal_to( 

82 ToolOrder.PRIORITY, 

83 ) 

84 assert_that(normalize_tool_order(ToolOrder.CUSTOM)).is_equal_to(ToolOrder.CUSTOM) 

85 

86 

87def test_tool_order_normalization_invalid_raises() -> None: 

88 """Raise ValueError for invalid tool order strings.""" 

89 with pytest.raises(ValueError, match="Unknown tool order"): 

90 normalize_tool_order("invalid_order") 

91 

92 

93def test_tool_config_info_reexport() -> None: 

94 """Test that tool_config_info re-exports get_tool_config_summary.""" 

95 from lintro.utils import tool_config_info 

96 

97 assert_that(hasattr(tool_config_info, "get_tool_config_summary")).is_true() 

98 assert_that("get_tool_config_summary" in tool_config_info.__all__).is_true()