Skip to content

Commit

Permalink
chore(v3): add str and repr to enums
Browse files Browse the repository at this point in the history
This helps makes enums more manageable during logging and debugging.

The `D200` Ruff lint is ignored, ensuring that single-line docstrings
use the same formatting as the remaining docstrings.

Signed-off-by: JP-Ellis <josh@jpellis.me>
  • Loading branch information
JP-Ellis committed Oct 10, 2023
1 parent 58e6502 commit d4121df
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
86 changes: 85 additions & 1 deletion pact/v3/ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,18 @@ class ExpressionValueType(Enum):
DECIMAL = lib.ExpressionValueType_Decimal
BOOLEAN = lib.ExpressionValueType_Boolean

def __str__(self) -> str:
"""
Informal string representation of the Expression Value Type.
"""
return self.name

def __repr__(self) -> str:
"""
Information-rich string representation of the Expression Value Type.
"""
return f"ExpressionValueType.{self.name}"


class GeneratorCategory(Enum):
"""
Expand All @@ -280,6 +292,18 @@ class GeneratorCategory(Enum):
STATUS = lib.GeneratorCategory_STATUS
METADATA = lib.GeneratorCategory_METADATA

def __str__(self) -> str:
"""
Informal string representation of the Generator Category.
"""
return self.name

def __repr__(self) -> str:
"""
Information-rich string representation of the Generator Category.
"""
return f"GeneratorCategory.{self.name}"


class InteractionPart(Enum):
"""
Expand All @@ -291,6 +315,18 @@ class InteractionPart(Enum):
REQUEST = lib.InteractionPart_Request
RESPONSE = lib.InteractionPart_Response

def __str__(self) -> str:
"""
Informal string representation of the Interaction Part.
"""
return self.name

def __repr__(self) -> str:
"""
Information-rich string representation of the Interaction Part.
"""
return f"InteractionPath.{self.name}"


class LevelFilter(Enum):
"""Level Filter."""
Expand All @@ -302,6 +338,18 @@ class LevelFilter(Enum):
DEBUG = lib.LevelFilter_Debug
TRACE = lib.LevelFilter_Trace

def __str__(self) -> str:
"""
Informal string representation of the Level Filter.
"""
return self.name

def __repr__(self) -> str:
"""
Information-rich string representation of the Level Filter.
"""
return f"LevelFilter.{self.name}"


class MatchingRuleCategory(Enum):
"""
Expand All @@ -319,6 +367,18 @@ class MatchingRuleCategory(Enum):
CONTENST = lib.MatchingRuleCategory_CONTENTS
METADATA = lib.MatchingRuleCategory_METADATA

def __str__(self) -> str:
"""
Informal string representation of the Matching Rule Category.
"""
return self.name

def __repr__(self) -> str:
"""
Information-rich string representation of the Matching Rule Category.
"""
return f"MatchingRuleCategory.{self.name}"


class PactSpecification(Enum):
"""
Expand All @@ -334,6 +394,18 @@ class PactSpecification(Enum):
V3 = lib.PactSpecification_V3
V4 = lib.PactSpecification_V4

def __str__(self) -> str:
"""
Informal string representation of the Pact Specification.
"""
return self.name

def __repr__(self) -> str:
"""
Information-rich string representation of the Pact Specification.
"""
return f"Pact Specification.{self.name}"


class StringResult(Enum):
"""
Expand All @@ -343,7 +415,19 @@ class StringResult(Enum):
"""

FAILED = lib.StringResult_Failed
Ok = lib.StringResult_Ok
OK = lib.StringResult_Ok

def __str__(self) -> str:
"""
Informal string representation of the String Result.
"""
return self.name

def __repr__(self) -> str:
"""
Information-rich string representation of the String Result.
"""
return f"StringResult.{self.name}"


def version() -> str:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ target-version = "py38"
select = ["ALL"]

ignore = [
"D200", # Require single line docstrings to be on one line.
"D203", # Require blank line before class docstring
"D212", # Multi-line docstring summary must start at the first line
"ANN101", # `self` must be typed
Expand Down

0 comments on commit d4121df

Please sign in to comment.