pytest_beehave.models

Shared value objects for pytest-beehave.

 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())
class FeatureStage(enum.Enum):
10class FeatureStage(Enum):
11    """The lifecycle stage of a feature folder."""
12
13    BACKLOG = "backlog"
14    IN_PROGRESS = "in-progress"
15    COMPLETED = "completed"

The lifecycle stage of a feature folder.

BACKLOG = <FeatureStage.BACKLOG: 'backlog'>
IN_PROGRESS = <FeatureStage.IN_PROGRESS: 'in-progress'>
COMPLETED = <FeatureStage.COMPLETED: 'completed'>
@dataclass(frozen=True, slots=True)
class ExampleId:
18@dataclass(frozen=True, slots=True)
19class ExampleId:
20    """An 8-char hex identifier for a Gherkin Example.
21
22    Attributes:
23        value: The 8-character lowercase hexadecimal string.
24    """
25
26    value: str
27
28    def __str__(self) -> str:
29        """Return the hex string representation."""
30        return self.value

An 8-char hex identifier for a Gherkin Example.

Attributes: value: The 8-character lowercase hexadecimal string.

ExampleId(value: str)
value: str
@dataclass(frozen=True, slots=True)
class FeatureSlug:
33@dataclass(frozen=True, slots=True)
34class FeatureSlug:
35    """A Python-safe slug derived from a feature folder name.
36
37    Attributes:
38        value: Lowercase, underscore-separated identifier.
39    """
40
41    value: str
42
43    def __str__(self) -> str:
44        """Return the slug string."""
45        return self.value
46
47    @classmethod
48    def from_folder_name(cls, name: str) -> "FeatureSlug":
49        """Create a FeatureSlug from a kebab-case folder name.
50
51        Args:
52            name: The feature folder name (may contain hyphens).
53
54        Returns:
55            A FeatureSlug with hyphens replaced by underscores.
56        """
57        return cls(name.replace("-", "_").lower())

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

Attributes: value: Lowercase, underscore-separated identifier.

FeatureSlug(value: str)
value: str
@classmethod
def from_folder_name(cls, name: str) -> FeatureSlug:
47    @classmethod
48    def from_folder_name(cls, name: str) -> "FeatureSlug":
49        """Create a FeatureSlug from a kebab-case folder name.
50
51        Args:
52            name: The feature folder name (may contain hyphens).
53
54        Returns:
55            A FeatureSlug with hyphens replaced by underscores.
56        """
57        return cls(name.replace("-", "_").lower())

Create a FeatureSlug from a kebab-case folder name.

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

Returns: A FeatureSlug with hyphens replaced by underscores.

@dataclass(frozen=True, slots=True)
class RuleSlug:
60@dataclass(frozen=True, slots=True)
61class RuleSlug:
62    """A file-safe slug derived from a Rule block title.
63
64    Attributes:
65        value: Lowercase, underscore-separated identifier.
66    """
67
68    value: str
69
70    def __str__(self) -> str:
71        """Return the slug string."""
72        return self.value
73
74    @classmethod
75    def from_rule_title(cls, title: str) -> "RuleSlug":
76        """Create a RuleSlug from a Rule block title.
77
78        Args:
79            title: The Rule: title text.
80
81        Returns:
82            A RuleSlug with spaces and hyphens replaced by underscores, lowercased.
83        """
84        return cls(title.strip().replace("-", "_").replace(" ", "_").lower())

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

Attributes: value: Lowercase, underscore-separated identifier.

RuleSlug(value: str)
value: str
@classmethod
def from_rule_title(cls, title: str) -> RuleSlug:
74    @classmethod
75    def from_rule_title(cls, title: str) -> "RuleSlug":
76        """Create a RuleSlug from a Rule block title.
77
78        Args:
79            title: The Rule: title text.
80
81        Returns:
82            A RuleSlug with spaces and hyphens replaced by underscores, lowercased.
83        """
84        return cls(title.strip().replace("-", "_").replace(" ", "_").lower())

Create a RuleSlug from a Rule block title.

Args: title: The Rule: title text.

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