Coverage for lintro / enums / bandit_levels.py: 100%
26 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"""Bandit severity and confidence level enum definitions.
3This module defines supported severity and confidence levels for Bandit issues.
4"""
6from __future__ import annotations
8from enum import auto
10from lintro.enums.uppercase_str_enum import UppercaseStrEnum
13class BanditSeverityLevel(UppercaseStrEnum):
14 """Supported severity levels for Bandit issues.
16 Values are upper-case string identifiers to align with Bandit tool outputs.
17 """
19 LOW = auto()
20 MEDIUM = auto()
21 HIGH = auto()
24class BanditConfidenceLevel(UppercaseStrEnum):
25 """Supported confidence levels for Bandit issues.
27 Values are upper-case string identifiers to align with Bandit tool outputs.
28 """
30 LOW = auto()
31 MEDIUM = auto()
32 HIGH = auto()
35def normalize_bandit_severity_level(
36 value: str | BanditSeverityLevel,
37) -> BanditSeverityLevel:
38 """Normalize a raw value to a BanditSeverityLevel enum.
40 Args:
41 value: str or BanditSeverityLevel to normalize.
43 Returns:
44 BanditSeverityLevel: Normalized enum value.
46 Raises:
47 ValueError: If value is not a valid severity level.
48 """
49 if isinstance(value, BanditSeverityLevel):
50 return value
51 try:
52 return BanditSeverityLevel[value.upper()]
53 except KeyError as err:
54 supported = f"Supported levels: {list(BanditSeverityLevel)}"
55 raise ValueError(
56 f"Unknown bandit severity level: {value!r}. {supported}",
57 ) from err
60def normalize_bandit_confidence_level(
61 value: str | BanditConfidenceLevel,
62) -> BanditConfidenceLevel:
63 """Normalize a raw value to a BanditConfidenceLevel enum.
65 Args:
66 value: str or BanditConfidenceLevel to normalize.
68 Returns:
69 BanditConfidenceLevel: Normalized enum value.
71 Raises:
72 ValueError: If value is not a valid confidence level.
73 """
74 if isinstance(value, BanditConfidenceLevel):
75 return value
76 try:
77 return BanditConfidenceLevel[value.upper()]
78 except KeyError as err:
79 raise ValueError(
80 f"Unknown bandit confidence level: {value!r}. "
81 f"Supported levels: {list(BanditConfidenceLevel)}",
82 ) from err