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
« prev ^ index » next coverage.py v7.8.0, created at 2026-04-21 04:49 +0000
1"""Shared value objects for pytest-beehave."""
3from __future__ import annotations
5from dataclasses import dataclass
6from enum import Enum
9class FeatureStage(Enum):
10 """The lifecycle stage of a feature folder."""
12 BACKLOG = "backlog"
13 IN_PROGRESS = "in-progress"
14 COMPLETED = "completed"
17@dataclass(frozen=True, slots=True)
18class ExampleId:
19 """An 8-char hex identifier for a Gherkin Example.
21 Attributes:
22 value: The 8-character lowercase hexadecimal string.
23 """
25 value: str
27 def __str__(self) -> str:
28 """Return the hex string representation."""
29 return self.value
32@dataclass(frozen=True, slots=True)
33class FeatureSlug:
34 """A Python-safe slug derived from a feature folder name.
36 Attributes:
37 value: Lowercase, underscore-separated identifier.
38 """
40 value: str
42 def __str__(self) -> str:
43 """Return the slug string."""
44 return self.value
46 @classmethod
47 def from_folder_name(cls, name: str) -> "FeatureSlug":
48 """Create a FeatureSlug from a kebab-case folder name.
50 Args:
51 name: The feature folder name (may contain hyphens).
53 Returns:
54 A FeatureSlug with hyphens replaced by underscores.
55 """
56 return cls(name.replace("-", "_").lower())
59@dataclass(frozen=True, slots=True)
60class RuleSlug:
61 """A file-safe slug derived from a Rule block title.
63 Attributes:
64 value: Lowercase, underscore-separated identifier.
65 """
67 value: str
69 def __str__(self) -> str:
70 """Return the slug string."""
71 return self.value
73 @classmethod
74 def from_rule_title(cls, title: str) -> "RuleSlug":
75 """Create a RuleSlug from a Rule block title.
77 Args:
78 title: The Rule: title text.
80 Returns:
81 A RuleSlug with spaces and hyphens replaced by underscores, lowercased.
82 """
83 return cls(title.strip().replace("-", "_").replace(" ", "_").lower())