Coverage for pytest_beehave/models.py: 100%

28 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2026-04-21 04:49 +0000

1"""Shared value objects for pytest-beehave.""" 

2 

3from __future__ import annotations 

4 

5from dataclasses import dataclass 

6from enum import Enum 

7 

8 

9class FeatureStage(Enum): 

10 """The lifecycle stage of a feature folder.""" 

11 

12 BACKLOG = "backlog" 

13 IN_PROGRESS = "in-progress" 

14 COMPLETED = "completed" 

15 

16 

17@dataclass(frozen=True, slots=True) 

18class ExampleId: 

19 """An 8-char hex identifier for a Gherkin Example. 

20 

21 Attributes: 

22 value: The 8-character lowercase hexadecimal string. 

23 """ 

24 

25 value: str 

26 

27 def __str__(self) -> str: 

28 """Return the hex string representation.""" 

29 return self.value 

30 

31 

32@dataclass(frozen=True, slots=True) 

33class FeatureSlug: 

34 """A Python-safe slug derived from a feature folder name. 

35 

36 Attributes: 

37 value: Lowercase, underscore-separated identifier. 

38 """ 

39 

40 value: str 

41 

42 def __str__(self) -> str: 

43 """Return the slug string.""" 

44 return self.value 

45 

46 @classmethod 

47 def from_folder_name(cls, name: str) -> "FeatureSlug": 

48 """Create a FeatureSlug from a kebab-case folder name. 

49 

50 Args: 

51 name: The feature folder name (may contain hyphens). 

52 

53 Returns: 

54 A FeatureSlug with hyphens replaced by underscores. 

55 """ 

56 return cls(name.replace("-", "_").lower()) 

57 

58 

59@dataclass(frozen=True, slots=True) 

60class RuleSlug: 

61 """A file-safe slug derived from a Rule block title. 

62 

63 Attributes: 

64 value: Lowercase, underscore-separated identifier. 

65 """ 

66 

67 value: str 

68 

69 def __str__(self) -> str: 

70 """Return the slug string.""" 

71 return self.value 

72 

73 @classmethod 

74 def from_rule_title(cls, title: str) -> "RuleSlug": 

75 """Create a RuleSlug from a Rule block title. 

76 

77 Args: 

78 title: The Rule: title text. 

79 

80 Returns: 

81 A RuleSlug with spaces and hyphens replaced by underscores, lowercased. 

82 """ 

83 return cls(title.strip().replace("-", "_").replace(" ", "_").lower())