Coverage for lintro / enums / tool_order.py: 100%

14 statements  

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

1"""Tool execution order enum definitions. 

2 

3This module defines the supported execution order strategies for tools. 

4""" 

5 

6from __future__ import annotations 

7 

8from enum import auto 

9 

10from lintro.enums.uppercase_str_enum import UppercaseStrEnum 

11 

12 

13class ToolOrder(UppercaseStrEnum): 

14 """Supported tool execution order strategies. 

15 

16 Values are uppercase string identifiers matching enum member names. 

17 """ 

18 

19 PRIORITY = auto() 

20 ALPHABETICAL = auto() 

21 CUSTOM = auto() 

22 

23 

24def normalize_tool_order(value: str | ToolOrder) -> ToolOrder: 

25 """Normalize a raw value to a ToolOrder enum. 

26 

27 Args: 

28 value: str or ToolOrder to normalize. 

29 

30 Returns: 

31 ToolOrder: Normalized enum value. 

32 

33 Raises: 

34 ValueError: If the value is not a valid tool order. 

35 """ 

36 if isinstance(value, ToolOrder): 

37 return value 

38 try: 

39 return ToolOrder[value.upper()] 

40 except KeyError as err: 

41 raise ValueError( 

42 f"Unknown tool order: {value!r}. Supported orders: {list(ToolOrder)}", 

43 ) from err